From 455859dab6bf4e1ed22214be18f9c20db18ad301 Mon Sep 17 00:00:00 2001 From: zhouyonggao <1971162852@qq.com> Date: Fri, 28 Nov 2025 16:47:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20=E6=94=B9=E8=BF=9B=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=96=87=E4=BB=B6=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0=E7=BC=BA=E5=A4=B1=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加对环境文件存在性的检查,当文件不存在时显示警告而非直接退出 当未指定环境文件时,允许仅通过配置文件加载配置 --- scripts/deploy_docker.sh | 51 ++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/scripts/deploy_docker.sh b/scripts/deploy_docker.sh index c97c82c..3c998f9 100644 --- a/scripts/deploy_docker.sh +++ b/scripts/deploy_docker.sh @@ -7,19 +7,22 @@ TAG="$ENV_NAME" PORT="${PORT:-8077}" cd "$ROOT_DIR" ENV_FILE_OVERRIDE="${2:-}" +ENV_FILE="" if [ -n "$ENV_FILE_OVERRIDE" ]; then - ENV_FILE="$ENV_FILE_OVERRIDE" + if [ -f "$ENV_FILE_OVERRIDE" ]; then + ENV_FILE="$ENV_FILE_OVERRIDE" + else + echo "警告:指定的 env 文件不存在:$ENV_FILE_OVERRIDE,忽略 --env-file" >&2 + fi else - ENV_FILE=".env.$ENV_NAME" - if [ ! -f "$ENV_FILE" ] && [ -f "server/.env.$ENV_NAME" ]; then + if [ -f ".env.$ENV_NAME" ]; then + ENV_FILE=".env.$ENV_NAME" + elif [ -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 +if [ -z "$ENV_FILE" ]; then + echo "未使用 env 文件,配置仅通过 server/config.$ENV_NAME.yaml 加载" >&2 fi docker build -t "$IMAGE:$TAG" -f Dockerfile . mkdir -p log storage/export @@ -36,14 +39,26 @@ 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" +if [ -n "$ENV_FILE" ]; 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" \ + -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" +fi echo "container: $CID_NAME image: $IMAGE:$TAG port: $PORT"