mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:43:03 +08:00 
			
		
		
		
	优化实例安装脚本
This commit is contained in:
		
							
								
								
									
										2
									
								
								cmd/edge-instance-installer/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								cmd/edge-instance-installer/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
edge-instance-installer*
 | 
			
		||||
prepare.sh
 | 
			
		||||
							
								
								
									
										45
									
								
								cmd/edge-instance-installer/build.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										45
									
								
								cmd/edge-instance-installer/build.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,45 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
function build() {
 | 
			
		||||
	ROOT=$(dirname "$0")
 | 
			
		||||
 | 
			
		||||
	OS="${1}"
 | 
			
		||||
	ARCH="${2}"
 | 
			
		||||
	TAG="${3}"
 | 
			
		||||
 | 
			
		||||
	if [ -z "$OS" ]; then
 | 
			
		||||
		echo "usage: build.sh OS ARCH"
 | 
			
		||||
		exit
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	if [ -z "$ARCH" ]; then
 | 
			
		||||
		echo "usage: build.sh OS ARCH"
 | 
			
		||||
		exit
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	VERSION=$(lookup_version "${ROOT}/../../internal/const/const.go")
 | 
			
		||||
	TARGET_NAME="edge-instance-installer-${OS}-${ARCH}-v${VERSION}"
 | 
			
		||||
 | 
			
		||||
	env GOOS=linux GOARCH="${ARCH}" go build -tags="${TAG}" -trimpath -ldflags="-s -w" -o "${TARGET_NAME}" main.go
 | 
			
		||||
 | 
			
		||||
	if [ -f "${TARGET_NAME}" ]; then
 | 
			
		||||
		cp "${TARGET_NAME}" "${ROOT}/../../../EdgeAdmin/docker/instance/edge-instance/assets"
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	echo "[done]"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function lookup_version() {
 | 
			
		||||
	FILE=$1
 | 
			
		||||
	VERSION_DATA=$(cat "$FILE")
 | 
			
		||||
	re="Version[ ]+=[ ]+\"([0-9.]+)\""
 | 
			
		||||
	if [[ $VERSION_DATA =~ $re ]]; then
 | 
			
		||||
		VERSION=${BASH_REMATCH[1]}
 | 
			
		||||
		echo "$VERSION"
 | 
			
		||||
	else
 | 
			
		||||
		echo "could not match version"
 | 
			
		||||
		exit
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
build "$1" "$2" "$3"
 | 
			
		||||
@@ -7,21 +7,39 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/instances"
 | 
			
		||||
	_ "github.com/iwind/TeaGo/bootstrap"
 | 
			
		||||
	"github.com/iwind/TeaGo/lists"
 | 
			
		||||
	"log"
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	var verbose = lists.ContainsString(os.Args, "-v")
 | 
			
		||||
 | 
			
		||||
	var dbHost = "127.0.0.1"
 | 
			
		||||
	var dbPassword = "123456"
 | 
			
		||||
	var dbName = "edges"
 | 
			
		||||
 | 
			
		||||
	envDBHost, _ := os.LookupEnv("DB_HOST")
 | 
			
		||||
	envDBHost, _ := os.LookupEnv("EDGE_DB_HOST")
 | 
			
		||||
	if len(envDBHost) > 0 {
 | 
			
		||||
		dbHost = envDBHost
 | 
			
		||||
		if verbose {
 | 
			
		||||
			log.Println("env EDGE_DB_HOST=" + envDBHost)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	envDBPassword, _ := os.LookupEnv("DB_PASSWORD")
 | 
			
		||||
	envDBPassword, _ := os.LookupEnv("EDGE_DB_PASSWORD")
 | 
			
		||||
	if len(envDBPassword) > 0 {
 | 
			
		||||
		dbPassword = envDBPassword
 | 
			
		||||
		if verbose {
 | 
			
		||||
			log.Println("env EDGE_DB_PASSWORD=" + envDBPassword)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	envDBName, _ := os.LookupEnv("EDGE_DB_NAME")
 | 
			
		||||
	if len(envDBName) > 0 {
 | 
			
		||||
		dbName = envDBName
 | 
			
		||||
		if verbose {
 | 
			
		||||
			log.Println("env EDGE_DB_NAME=" + envDBName)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var isTesting = lists.ContainsString(os.Args, "-test") || lists.ContainsString(os.Args, "--test")
 | 
			
		||||
@@ -31,7 +49,7 @@ func main() {
 | 
			
		||||
 | 
			
		||||
	var instance = instances.NewInstance(instances.Options{
 | 
			
		||||
		IsTesting: isTesting,
 | 
			
		||||
		Verbose:   lists.ContainsString(os.Args, "-v"),
 | 
			
		||||
		Verbose:   verbose,
 | 
			
		||||
		Cacheable: false,
 | 
			
		||||
		WorkDir:   "",
 | 
			
		||||
		SrcDir:    "/usr/local/goedge/src",
 | 
			
		||||
@@ -46,7 +64,7 @@ func main() {
 | 
			
		||||
			Port:     3306,
 | 
			
		||||
			Username: "root",
 | 
			
		||||
			Password: dbPassword,
 | 
			
		||||
			Name:     "edges",
 | 
			
		||||
			Name:     dbName,
 | 
			
		||||
		},
 | 
			
		||||
		AdminNode: struct {
 | 
			
		||||
			Port int
 | 
			
		||||
							
								
								
									
										2
									
								
								cmd/standalone-instance-installer/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								cmd/standalone-instance-installer/.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,2 +0,0 @@
 | 
			
		||||
standalone-instance-installer*
 | 
			
		||||
prepare.sh
 | 
			
		||||
@@ -1,17 +0,0 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
OS="${1}"
 | 
			
		||||
ARCH="${2}"
 | 
			
		||||
TAG="${3}"
 | 
			
		||||
 | 
			
		||||
if [ -z "$OS" ]; then
 | 
			
		||||
	echo "usage: build.sh OS ARCH"
 | 
			
		||||
	exit
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if [ -z "$ARCH" ]; then
 | 
			
		||||
	echo "usage: build.sh OS ARCH"
 | 
			
		||||
	exit
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
env GOOS=linux GOARCH="${ARCH}" go build -tags="${TAG}" -trimpath -ldflags="-s -w" -o "standalone-instance-installer-${OS}-${ARCH}" main.go
 | 
			
		||||
@@ -64,7 +64,7 @@ func (this *Instance) SetupAll() error {
 | 
			
		||||
 | 
			
		||||
func (this *Instance) SetupDB() error {
 | 
			
		||||
	if this.options.Verbose {
 | 
			
		||||
		log.Println("setup db ...")
 | 
			
		||||
		log.Println("setup db " + this.options.DB.Host + ":" + types.String(this.options.DB.Port) + "/" + this.options.DB.Name + " ...")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 检查数据库名
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user