From 7f658ffc2a8e5e9ed5aa16ff0c77c56d7af0fe3e Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 3 Mar 2024 17:14:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9E=E4=BE=8B=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/edge-instance-installer/.gitignore | 2 + cmd/edge-instance-installer/build.sh | 45 +++++++++++++++++++ .../main.go | 26 +++++++++-- cmd/standalone-instance-installer/.gitignore | 2 - cmd/standalone-instance-installer/build.sh | 17 ------- internal/instances/instance.go | 2 +- 6 files changed, 70 insertions(+), 24 deletions(-) create mode 100644 cmd/edge-instance-installer/.gitignore create mode 100755 cmd/edge-instance-installer/build.sh rename cmd/{standalone-instance-installer => edge-instance-installer}/main.go (72%) delete mode 100644 cmd/standalone-instance-installer/.gitignore delete mode 100755 cmd/standalone-instance-installer/build.sh diff --git a/cmd/edge-instance-installer/.gitignore b/cmd/edge-instance-installer/.gitignore new file mode 100644 index 00000000..ebb37973 --- /dev/null +++ b/cmd/edge-instance-installer/.gitignore @@ -0,0 +1,2 @@ +edge-instance-installer* +prepare.sh \ No newline at end of file diff --git a/cmd/edge-instance-installer/build.sh b/cmd/edge-instance-installer/build.sh new file mode 100755 index 00000000..5e68414a --- /dev/null +++ b/cmd/edge-instance-installer/build.sh @@ -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" \ No newline at end of file diff --git a/cmd/standalone-instance-installer/main.go b/cmd/edge-instance-installer/main.go similarity index 72% rename from cmd/standalone-instance-installer/main.go rename to cmd/edge-instance-installer/main.go index 57bbea9f..572a8fa3 100644 --- a/cmd/standalone-instance-installer/main.go +++ b/cmd/edge-instance-installer/main.go @@ -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 diff --git a/cmd/standalone-instance-installer/.gitignore b/cmd/standalone-instance-installer/.gitignore deleted file mode 100644 index 07c48484..00000000 --- a/cmd/standalone-instance-installer/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -standalone-instance-installer* -prepare.sh \ No newline at end of file diff --git a/cmd/standalone-instance-installer/build.sh b/cmd/standalone-instance-installer/build.sh deleted file mode 100755 index 837eac5a..00000000 --- a/cmd/standalone-instance-installer/build.sh +++ /dev/null @@ -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 \ No newline at end of file diff --git a/internal/instances/instance.go b/internal/instances/instance.go index a96ea74a..433e39ee 100644 --- a/internal/instances/instance.go +++ b/internal/instances/instance.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 + " ...") } // 检查数据库名