From 48863be438f060bdc1272eb8b40454a0fd5fa9f6 Mon Sep 17 00:00:00 2001 From: zhouyonggao <1971162852@qq.com> Date: Fri, 28 Nov 2025 16:44:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20=E4=BF=AE=E6=94=B9=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E7=8E=AF=E5=A2=83=E4=B8=BAtest=E5=B9=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=8C=82=E8=BD=BD?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加对config.$ENV_NAME.yaml配置文件的挂载支持,当文件存在时自动挂载到容器中 同时将默认部署环境从prod改为test,并优化错误提示信息 --- scripts/deploy_docker.sh | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/scripts/deploy_docker.sh b/scripts/deploy_docker.sh index bea209d..666af7b 100644 --- a/scripts/deploy_docker.sh +++ b/scripts/deploy_docker.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -ENV_NAME="${1:-prod}" +ENV_NAME="${1:-test}" IMAGE="marketing-system-data-tool" TAG="$ENV_NAME" PORT="${PORT:-8077}" @@ -11,7 +11,7 @@ if [ ! -f "$ENV_FILE" ] && [ -f "server/.env.$ENV_NAME" ]; then ENV_FILE="server/.env.$ENV_NAME" fi if [ ! -f "$ENV_FILE" ]; then - echo "$ENV_FILE not found" >&2 + echo "示例:server/.env.example" >&2 exit 1 fi docker build -t "$IMAGE:$TAG" -f Dockerfile . @@ -24,13 +24,27 @@ fi if docker ps -a --format '{{.Names}}' | grep -q "^${CID_NAME}$"; then docker rm "$CID_NAME" >/dev/null 2>&1 || true fi -docker run -d \ - --name "$CID_NAME" \ - --restart unless-stopped \ - --env APP_ENV="$ENV_NAME" \ - --env-file "$ENV_FILE" \ - -p "$PORT:8077" \ - -v "$ROOT_DIR/storage/export:/app/storage/export" \ - -v "$ROOT_DIR/log:/app/log" \ - "$IMAGE:$TAG" +CONFIG_PATH="$ROOT_DIR/server/config.$ENV_NAME.yaml" +if [ -f "$CONFIG_PATH" ]; then + docker run -d \ + --name "$CID_NAME" \ + --restart unless-stopped \ + --env APP_ENV="$ENV_NAME" \ + --env-file "$ENV_FILE" \ + -p "$PORT:8077" \ + -v "$ROOT_DIR/storage/export:/app/storage/export" \ + -v "$ROOT_DIR/log:/app/log" \ + -v "$CONFIG_PATH:/app/server/config.$ENV_NAME.yaml:ro" \ + "$IMAGE:$TAG" +else + docker run -d \ + --name "$CID_NAME" \ + --restart unless-stopped \ + --env APP_ENV="$ENV_NAME" \ + --env-file "$ENV_FILE" \ + -p "$PORT:8077" \ + -v "$ROOT_DIR/storage/export:/app/storage/export" \ + -v "$ROOT_DIR/log:/app/log" \ + "$IMAGE:$TAG" +fi echo "container: $CID_NAME image: $IMAGE:$TAG port: $PORT"