From 1d8760e9b567f32061405c13f2cfd07bc0dcb667 Mon Sep 17 00:00:00 2001 From: zhouyonggao <1971162852@qq.com> Date: Fri, 28 Nov 2025 16:36:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor(deployment):=20=E7=A7=BB=E9=99=A4docke?= =?UTF-8?q?r-compose=E9=85=8D=E7=BD=AE=E5=B9=B6=E9=87=8D=E6=9E=84=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除不再使用的docker-compose.yml和deploy_image.sh文件 重构deploy.sh脚本以直接运行Go二进制程序 简化部署流程,不再依赖Docker容器 --- docker-compose.yml | 22 ---------- scripts/deploy.sh | 48 ++++++++++----------- scripts/deploy_image.sh | 69 ------------------------------- server/bin/marketing-data-server | Bin 12885442 -> 12885442 bytes 4 files changed, 21 insertions(+), 118 deletions(-) delete mode 100644 docker-compose.yml delete mode 100644 scripts/deploy_image.sh diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index a93bf75..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,22 +0,0 @@ -services: - msdt: - build: . - platform: ${PLATFORM:-linux/amd64} - container_name: msdt - environment: - - APP_ENV=${APP_ENV:-prod} - - MARKETING_DB_HOST=${MARKETING_DB_HOST} - - MARKETING_DB_PORT=${MARKETING_DB_PORT} - - MARKETING_DB_USER=${MARKETING_DB_USER} - - MARKETING_DB_PASSWORD=${MARKETING_DB_PASSWORD} - - MARKETING_DB_NAME=${MARKETING_DB_NAME} - - YMT_DB_HOST=${YMT_DB_HOST} - - YMT_DB_PORT=${YMT_DB_PORT} - - YMT_DB_USER=${YMT_DB_USER} - - YMT_DB_PASSWORD=${YMT_DB_PASSWORD} - - YMT_DB_NAME=${YMT_DB_NAME} - - YMT_KEY_DECRYPT_KEY_B64=${YMT_KEY_DECRYPT_KEY_B64} - ports: - - "8077:8077" - volumes: - - ./server/storage:/app/storage diff --git a/scripts/deploy.sh b/scripts/deploy.sh index d1fb5ba..3993deb 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -1,28 +1,22 @@ -#!/usr/bin/env sh -set -e -ENV=${1:-prod} -MODE=${2:-no-build} -ENVFILE="" -if [ -f ".env.$ENV" ]; then ENVFILE="--env-file .env.$ENV"; fi -PLATFORM=${PLATFORM:-} -if [ -z "$PLATFORM" ]; then - ARCH=$(uname -m) - case "$ARCH" in - x86_64) PLATFORM="linux/amd64" ;; - aarch64) PLATFORM="linux/arm64" ;; - *) PLATFORM="linux/amd64" ;; - esac +#!/usr/bin/env bash +set -euo pipefail +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +ENV_NAME="${1:-prod}" +export APP_ENV="$ENV_NAME" +cd "$ROOT_DIR" +if [ -f ".env.$ENV_NAME" ]; then + true +elif [ -f "server/.env.$ENV_NAME" ]; then + true +else + echo ".env.$ENV_NAME not found" >&2 + exit 1 fi -export PLATFORM -case "$MODE" in - no-build) - APP_ENV=$ENV docker compose $ENVFILE up -d ;; - rebuild) - APP_ENV=$ENV docker compose $ENVFILE build --no-cache - APP_ENV=$ENV docker compose $ENVFILE up -d ;; - pull) - APP_ENV=$ENV docker compose $ENVFILE build --pull - APP_ENV=$ENV docker compose $ENVFILE up -d ;; - build|*) - APP_ENV=$ENV docker compose $ENVFILE up -d --build ;; -esac +mkdir -p log +cd "$ROOT_DIR/server" +go build -o "bin/marketing-data-server" "./cmd/server" +cd "$ROOT_DIR" +TARGET="$ROOT_DIR/server/bin/marketing-data-server" +nohup env APP_ENV="$ENV_NAME" "$TARGET" > "$ROOT_DIR/log/server.out" 2>&1 & +echo $! > "$ROOT_DIR/server/bin/server.pid" +echo "started: $TARGET pid $(cat "$ROOT_DIR/server/bin/server.pid")" diff --git a/scripts/deploy_image.sh b/scripts/deploy_image.sh deleted file mode 100644 index a5b4388..0000000 --- a/scripts/deploy_image.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -ENV=${1:-test} -IMAGE=${2:-marketingsystemdatatool_msdt:latest} -CMD=${3:-up} -PLATFORM=${PLATFORM:-} -if [ -z "$PLATFORM" ]; then - ARCH=$(uname -m) - case "$ARCH" in - x86_64) PLATFORM="linux/amd64" ;; - aarch64) PLATFORM="linux/arm64" ;; - *) PLATFORM="linux/amd64" ;; - esac -fi - -ROOT_DIR=$(cd "$(dirname "$0")/.." && pwd) - -if [ -f "$ROOT_DIR/.env.$ENV" ]; then - set -a - . "$ROOT_DIR/.env.$ENV" - set +a -fi - -case "$CMD" in - up) - docker rm -f msdt >/dev/null 2>&1 || true - PLATFORM_FLAG="" - if [ -n "$PLATFORM" ]; then PLATFORM_FLAG="--platform $PLATFORM"; fi - IMG_ARCH="" - if docker image inspect "$IMAGE" >/dev/null 2>&1; then - IMG_ARCH=$(docker image inspect "$IMAGE" --format '{{.Architecture}}' 2>/dev/null || echo "") - fi - if [ -n "$IMG_ARCH" ]; then - HOST_ARCH=$(uname -m) - case "$HOST_ARCH" in x86_64) HOST_ARCH="amd64" ;; aarch64) HOST_ARCH="arm64" ;; *) HOST_ARCH="amd64" ;; esac - if [ "$IMG_ARCH" != "$HOST_ARCH" ]; then - docker pull --platform "$PLATFORM" "$IMAGE" >/dev/null 2>&1 || true - PLATFORM_FLAG="--platform $PLATFORM" - fi - else - docker pull --platform "$PLATFORM" "$IMAGE" >/dev/null 2>&1 || true - fi - docker run -d --name msdt $PLATFORM_FLAG \ - -p 8077:8077 \ - -e APP_ENV="$ENV" \ - -e MARKETING_DB_HOST="${MARKETING_DB_HOST:-}" \ - -e MARKETING_DB_PORT="${MARKETING_DB_PORT:-}" \ - -e MARKETING_DB_USER="${MARKETING_DB_USER:-}" \ - -e MARKETING_DB_PASSWORD="${MARKETING_DB_PASSWORD:-}" \ - -e MARKETING_DB_NAME="${MARKETING_DB_NAME:-}" \ - -e YMT_DB_HOST="${YMT_DB_HOST:-}" \ - -e YMT_DB_PORT="${YMT_DB_PORT:-}" \ - -e YMT_DB_USER="${YMT_DB_USER:-}" \ - -e YMT_DB_PASSWORD="${YMT_DB_PASSWORD:-}" \ - -e YMT_DB_NAME="${YMT_DB_NAME:-}" \ - -v "$ROOT_DIR/server/storage:/app/storage" \ - "$IMAGE" ;; - down) - docker rm -f msdt >/dev/null 2>&1 || true ;; - restart) - docker restart msdt ;; - logs) - docker logs -f msdt ;; - *) - echo "usage: deploy_image.sh [up|down|restart|logs]" >&2 - echo "env overrides: set PLATFORM=linux/amd64 or PLATFORM=linux/arm64 if needed" >&2 - exit 1 ;; -esac diff --git a/server/bin/marketing-data-server b/server/bin/marketing-data-server index 9597e13de81e0df2f36a07da5fc027a4a61fa1a4..215f071376c9ca5334ea7ec54ef96e7f22e23daf 100755 GIT binary patch delta 1272 zcmb`@{Zo?#0KoAEi7`!>sbrEalcE=4JlotrNqm3_qR30Iv9!tdY_edy2(w5I)wxl6CJ>o_{@;^Ok+hdjFOxXU|x`Sw5b!{^8EFW>Oh<56Ms zjca4G=iQo-Zl&(7 zXZh^8CZCw=O7%FB9cAXmI=i!|&Rt^h7UfiJb!BfzPRVqc9c6Y$ezq+?U@K|J6H5!4 zJ+ZBxSPdc&iF+{zQJ9PS5DhKnVLtB10>t3IUWbKv0E@5~OAv<#u@nzs8RGFUmSY9< zcmyl)C{`f>kKu77;t4#7r|>jZBMHecAO!-9Fu{y9u)vB`q+u=AAsx?PJuP zL4TDLz1vft6sVE>KEGE=Z`c)V*L8}PcGqlBryS@I$2F~nE)ki?LN;vJh#cf%6Y{Vb zTab^fC_o{KP>g3$f>PMwKpC8P4%@ID&%=csD2E#!Nbtgkov45xFQ5`t2%s7@s6`!i zp&kv2p(}W2SwuKS*>OtTGWY)rd#W8>nXKbj^T>zrfq`EcAwi~gKBWX}C|A}V9%JG*cxZo+xzine=w z-fdgd;So*D=}~3s%!uBn|1D(cL~&cA;TX|Bx=mE1gdl;l4Iy xW#s5kyngRYhgF_lyQEh)n|}At1;Wwmf7MUvw)I9>ABm~(A*ZAVM3!_wla)_W~w4Lf(4jk)IP9i>erZNdB!S4XhiQt#3?w;piI zdfl=FBw`6}$5JFA8FyeAQm`DUSb;mS694sg;cl$LJy?xK+oq}4QXAlNXei_P;>k2gb0 zFpDpu0U?&YP@ER~bu4^o=Bp%=?~FA+XKJ)D{&nD|gI5ZR|5BI9Oa58cqf0(|W%bO$ z)QVb#ZNp{l)&2$9*_-pXMsB38pR>tFV{76)a;x1kJ=|3^UWCq;k`GatD-*-#pOQv_od>uk+IBk2^W=vzxSWcGTPE73Y8nLAByy}e{*8DDympA uH=7|Be^~zGv3lL4U8T5Y7|DsZ{-*vjEM8tz9{y!M+qu{sO_a~gcKr+SK=;G|