From 0f603041d93514eb064649e6a83684cbd9b8f6ec Mon Sep 17 00:00:00 2001 From: zhouyonggao <1971162852@qq.com> Date: Fri, 28 Nov 2025 16:46:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20=E6=94=B9=E8=BF=9Bdocker?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E8=84=9A=E6=9C=AC=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=92=8C=E9=85=8D=E7=BD=AE=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加环境文件路径覆盖参数,并增强错误提示 统一docker运行命令逻辑,强制检查配置文件存在性 --- scripts/deploy_docker.sh | 49 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/scripts/deploy_docker.sh b/scripts/deploy_docker.sh index 666af7b..c97c82c 100644 --- a/scripts/deploy_docker.sh +++ b/scripts/deploy_docker.sh @@ -1,16 +1,23 @@ #!/usr/bin/env bash set -euo pipefail -ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" ENV_NAME="${1:-test}" IMAGE="marketing-system-data-tool" TAG="$ENV_NAME" PORT="${PORT:-8077}" cd "$ROOT_DIR" -ENV_FILE=".env.$ENV_NAME" -if [ ! -f "$ENV_FILE" ] && [ -f "server/.env.$ENV_NAME" ]; then - ENV_FILE="server/.env.$ENV_NAME" +ENV_FILE_OVERRIDE="${2:-}" +if [ -n "$ENV_FILE_OVERRIDE" ]; then + ENV_FILE="$ENV_FILE_OVERRIDE" +else + ENV_FILE=".env.$ENV_NAME" + if [ ! -f "$ENV_FILE" ] && [ -f "server/.env.$ENV_NAME" ]; then + ENV_FILE="server/.env.$ENV_NAME" + fi fi if [ ! -f "$ENV_FILE" ]; then + echo "$ENV_FILE not found" >&2 + echo "请创建 .env.$ENV_NAME 或指定第二个参数为 env 文件路径" >&2 echo "示例:server/.env.example" >&2 exit 1 fi @@ -25,26 +32,18 @@ if docker ps -a --format '{{.Names}}' | grep -q "^${CID_NAME}$"; then docker rm "$CID_NAME" >/dev/null 2>&1 || true fi 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" +if [ ! -f "$CONFIG_PATH" ]; then + echo "配置文件缺失:$CONFIG_PATH" >&2 + exit 1 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" \ + -v "$CONFIG_PATH:/app/server/config.$ENV_NAME.yaml:ro" \ + "$IMAGE:$TAG" echo "container: $CID_NAME image: $IMAGE:$TAG port: $PORT"