From 2c5f83f64e5c32518e4d6813573c822fecf94f70 Mon Sep 17 00:00:00 2001 From: wonder Date: Sun, 24 May 2026 21:39:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(deploy):=20=E6=94=AF=E6=8C=81=E9=80=9A?= =?UTF-8?q?=E8=BF=87=20.env=20=E6=96=87=E4=BB=B6=E6=B3=A8=E5=85=A5?= =?UTF-8?q?=E5=90=8E=E7=AB=AF=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - docker-compose.yml 添加 env_file 加载 backend/.env - deploy.sh 自动检测并从 .env.example 复制模板 - .dockerignore 排除 .env 防止密钥泄露到镜像 --- .dockerignore | 1 + deploy.sh | 17 ++++++++++++++++- docker-compose.yml | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index 6054892..b97b965 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,4 +2,5 @@ node_modules frontend/node_modules frontend/dist backend/bin +backend/.env .git diff --git a/deploy.sh b/deploy.sh index cfd59fc..32683da 100755 --- a/deploy.sh +++ b/deploy.sh @@ -31,7 +31,22 @@ else cd "$INSTALL_DIR" fi -# 3. 构建并启动 +# 3. 环境变量检查 +ENV_FILE="$INSTALL_DIR/backend/.env" +ENV_EXAMPLE="$INSTALL_DIR/backend/.env.example" +if [ ! -f "$ENV_FILE" ]; then + if [ -f "$ENV_EXAMPLE" ]; then + echo "==> 未找到 backend/.env,已从 .env.example 复制模板" + cp "$ENV_EXAMPLE" "$ENV_FILE" + echo " 请编辑 $ENV_FILE 填入实际配置后重新运行本脚本" + exit 0 + else + echo "错误: backend/.env 和 .env.example 均不存在,请手动创建" + exit 1 + fi +fi + +# 4. 构建并启动 echo "==> 构建并启动 Docker 容器..." if docker compose version &>/dev/null; then COMPOSE_CMD="docker compose" diff --git a/docker-compose.yml b/docker-compose.yml index 83e764d..aa15cf3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,9 +3,10 @@ services: build: context: ./backend dockerfile: Dockerfile + env_file: + - ./backend/.env environment: - GEN2D_MODE=release - - GEN2D_PORT=8080 volumes: - backend-data:/data expose: