diff --git a/scripts/deploy_docker.sh b/scripts/deploy_docker.sh index e3b1cd1..92a0006 100644 --- a/scripts/deploy_docker.sh +++ b/scripts/deploy_docker.sh @@ -6,29 +6,12 @@ IMAGE="marketing-system-data-tool" TAG="$ENV_NAME" PORT="${PORT:-8077}" cd "$ROOT_DIR" -ENV_FILE_OVERRIDE="${2:-}" -ENV_FILE="" -if [ -n "$ENV_FILE_OVERRIDE" ]; then - if [ -f "$ENV_FILE_OVERRIDE" ]; then - ENV_FILE="$ENV_FILE_OVERRIDE" - else - echo "警告:指定的 env 文件不存在:$ENV_FILE_OVERRIDE,忽略 --env-file" >&2 - fi -else - 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 [ -z "$ENV_FILE" ]; then - echo "未使用 env 文件,配置仅通过 server/config.$ENV_NAME.yaml 加载" >&2 -fi if docker image inspect "$IMAGE:$TAG" >/dev/null 2>&1; then - echo "使用已有镜像: $IMAGE:$TAG" + echo "使用已有镜像作为缓存: $IMAGE:$TAG" + DOCKER_BUILDKIT=1 docker build --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from "$IMAGE:$TAG" -t "$IMAGE:$TAG" -f Dockerfile . else echo "镜像不存在,开始构建: $IMAGE:$TAG" - docker build -t "$IMAGE:$TAG" -f Dockerfile . + DOCKER_BUILDKIT=1 docker build --build-arg BUILDKIT_INLINE_CACHE=1 -t "$IMAGE:$TAG" -f Dockerfile . fi mkdir -p log storage/export CID_NAME="marketing-data-$ENV_NAME" @@ -44,26 +27,13 @@ if [ ! -f "$CONFIG_PATH" ]; then echo "配置文件缺失:$CONFIG_PATH" >&2 exit 1 fi -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 +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" echo "container: $CID_NAME image: $IMAGE:$TAG port: $PORT"