From 93d95254b7d753dcff84940fa68965e0ef235135 Mon Sep 17 00:00:00 2001 From: Rzy <465386466@qq.com> Date: Tue, 16 Jul 2024 18:39:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=83=A8=E7=BD=B2=E5=91=BD?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/rpc/queue/queue.go | 2 +- cmd/rpc/transfer.go | 3 ++- sh/build.sh | 6 ++---- sh/build_produce.sh | 15 +++++---------- sh/build_test.sh | 17 +++++------------ sh/config.sh | 7 +++++++ sh/depoly.sh | 23 +++++++++++++---------- sh/env | 1 + until/env.go | 7 +++++++ 9 files changed, 43 insertions(+), 38 deletions(-) create mode 100644 sh/env diff --git a/cmd/rpc/queue/queue.go b/cmd/rpc/queue/queue.go index 42db7db..c15b1db 100644 --- a/cmd/rpc/queue/queue.go +++ b/cmd/rpc/queue/queue.go @@ -12,7 +12,7 @@ import ( "trasfer_middleware/until/sysLog" ) -var configFile = flag.String("f", "../../../config/transfer_local.yaml", "the config file") +var configFile = flag.String("f", "../../../config/transfer_produce.yaml", "the config file") func main() { flag.Parse() diff --git a/cmd/rpc/transfer.go b/cmd/rpc/transfer.go index 64baa0f..116348b 100644 --- a/cmd/rpc/transfer.go +++ b/cmd/rpc/transfer.go @@ -16,9 +16,10 @@ import ( "trasfer_middleware/cmd/rpc/internal/server" "trasfer_middleware/cmd/rpc/internal/svc" "trasfer_middleware/cmd/rpc/pb/transfer" + "trasfer_middleware/until" ) -var configFile = flag.String("f", "../../config/transfer_local.yaml", "the config file") +var configFile = flag.String("f", until.GetConfig(), "the config file") func main() { flag.Parse() diff --git a/sh/build.sh b/sh/build.sh index aff0cf4..058ccd0 100644 --- a/sh/build.sh +++ b/sh/build.sh @@ -1,9 +1,7 @@ #!/bin/bash -source ./config.sh - docker build -t "${IMAGE}:${VERSION}" . --no-cache -docker tag "${IMAGE}:${TAGS_NAME}" ${ADDRESS}:${TAGS_NAME} +docker tag "${IMAGE}:${VERSION}" ${ADDRESS}:${VERSION} -docker push ${ADDRESS}:${TAGS_NAME} \ No newline at end of file +docker push ${ADDRESS}:${VERSION} \ No newline at end of file diff --git a/sh/build_produce.sh b/sh/build_produce.sh index 929170a..7cedbd8 100644 --- a/sh/build_produce.sh +++ b/sh/build_produce.sh @@ -1,14 +1,9 @@ #!/bin/bash -IMAGE="transfer_middleware" -RPC_CONTAINER="transfer_middleware" -RPC_PORT="10001" -V_REFLECT="" -TAGS_NAME="v1" -ADDRESS="registry.cn-chengdu.aliyuncs.com/go_ls/transfer_middleware" +. $(pwd)/sh/config.sh +Environment="produce" +ADDRESS="${PRODUCE_ADDRESS}" +echo "produce"> $(pwd)/sh/env -docker build -t "${IMAGE}:${TAGS_NAME}" . --no-cache +. $(pwd)/sh/build.sh -docker tag "${IMAGE}:${TAGS_NAME}" ${ADDRESS}:${TAGS_NAME} - -docker push ${ADDRESS}:${TAGS_NAME} \ No newline at end of file diff --git a/sh/build_test.sh b/sh/build_test.sh index 929170a..ab72d0a 100644 --- a/sh/build_test.sh +++ b/sh/build_test.sh @@ -1,14 +1,7 @@ #!/bin/bash -IMAGE="transfer_middleware" -RPC_CONTAINER="transfer_middleware" -RPC_PORT="10001" -V_REFLECT="" -TAGS_NAME="v1" -ADDRESS="registry.cn-chengdu.aliyuncs.com/go_ls/transfer_middleware" - -docker build -t "${IMAGE}:${TAGS_NAME}" . --no-cache - -docker tag "${IMAGE}:${TAGS_NAME}" ${ADDRESS}:${TAGS_NAME} - -docker push ${ADDRESS}:${TAGS_NAME} \ No newline at end of file +. $(pwd)/sh/config.sh +Environment="test" +ADDRESS="${TEST_ADDRESS}" +echo "test"> $(pwd)/sh/env +sh $(pwd)/sh/build.sh diff --git a/sh/config.sh b/sh/config.sh index e69de29..6acd568 100644 --- a/sh/config.sh +++ b/sh/config.sh @@ -0,0 +1,7 @@ +IMAGE="transfer_middleware" +CONTAINER="transfer_middleware" +PORT="10001" +TEST_ADDRESS="registry.cn-chengdu.aliyuncs.com/go_ls/transfer_middleware" +PRODUCE_ADDRESS="registry.cn-chengdu.aliyuncs.com/go_ls/transfer_middleware_produce" +COMMIT_CONTENT="UPDATE" +VERSION="v1" diff --git a/sh/depoly.sh b/sh/depoly.sh index f5c9aa2..63c0c41 100755 --- a/sh/depoly.sh +++ b/sh/depoly.sh @@ -1,14 +1,17 @@ #!/bin/bash -IMAGE="transfer_middleware:v1" -RPC_CONTAINER="transfer_middleware" -RPC_PORT="10001" -V_REFLECT="" +. $(pwd)/sh/config.sh +ENV=$(cat "$(pwd)/sh/env") +# 使用if-elif-else结构判断环境 +if [ "$ENV"=="produce" ]; then + ADDRESS="${PRODUCE_ADDRESS}" +elif [ "$ENV"=="test" ]; then + ADDRESS="${TEST_ADDRESS}" +else + ADDRESS="${PRODUCE_ADDRESS}" +fi -docker build -t "${IMAGE}" . --no-cache -docker stop "${RPC_CONTAINER}" - -docker rm "${RPC_CONTAINER}" - -#docker run -it -p "${RPC_PORT}:${RPC_PORT}" --name "$RPC_CONTAINER" "${IMAGE}" \ No newline at end of file +docker pull ${ADDRESS}:${VERSION} +docker rm -f "${CONTAINER}" +docker run -it -p "${PORT}:${PORT}" --name "${CONTAINER}" "${IMAGE}:${VERSION}" \ No newline at end of file diff --git a/sh/env b/sh/env new file mode 100644 index 0000000..c9e473a --- /dev/null +++ b/sh/env @@ -0,0 +1 @@ +produce diff --git a/until/env.go b/until/env.go index 12923ba..2a6526b 100644 --- a/until/env.go +++ b/until/env.go @@ -1 +1,8 @@ package until + +import "os" + +func GetConfig() string { + + return os.Getenv("GO_ENV") +}