fix: 前端自动化部署优化

This commit is contained in:
wood911010 committed 2025-08-09 22:40:48 +08:00
1 parent 6bcd8f4d09
commit 246d49a038
5 files changed
+26 -5

No files matched your search

+3 -2
View File
@@ -22,8 +22,9 @@ FROM nginx:alpine
# Copy built assets # Copy built assets
COPY --from=builder /app/dist /usr/share/nginx/html COPY --from=builder /app/dist /usr/share/nginx/html
# Copy custom nginx configuration # Copy nginx configuration template and entrypoint to render from env
COPY nginx.conf /etc/nginx/conf.d/default.conf COPY nginx.conf /etc/nginx/conf.d/default.conf.template
COPY frontend/entrypoint/10-envsubst.sh /docker-entrypoint.d/10-envsubst.sh
# Create log directory # Create log directory
RUN mkdir -p /var/log/nginx RUN mkdir -p /var/log/nginx
+2
View File
@@ -87,6 +87,8 @@ services:
restart: unless-stopped restart: unless-stopped
environment: environment:
- TZ=Asia/Shanghai - TZ=Asia/Shanghai
# Set API upstream for automated deployments (e.g., external gateway or backend host)
- API_UPSTREAM=${API_UPSTREAM:-http://backend:18888}
ports: ports:
- "${FRONTEND_PORT:-80}:80" - "${FRONTEND_PORT:-80}:80"
depends_on: depends_on:
+1
View File
@@ -68,6 +68,7 @@ services:
restart: unless-stopped restart: unless-stopped
environment: environment:
- TZ=Asia/Shanghai - TZ=Asia/Shanghai
- API_UPSTREAM=http://backend:18888
ports: ports:
- "18080:80" - "18080:80"
depends_on: depends_on:
+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
set -eu
# Default upstream if not provided (docker compose dev network)
: "${API_UPSTREAM:=http://backend:18888}"
TEMPLATE="/etc/nginx/conf.d/default.conf.template"
TARGET="/etc/nginx/conf.d/default.conf"
if [ -f "$TEMPLATE" ]; then
echo "[entrypoint] Rendering nginx config with API_UPSTREAM=$API_UPSTREAM"
envsubst '\$API_UPSTREAM' < "$TEMPLATE" > "$TARGET"
fi
exit 0
+2 -3
View File
@@ -39,10 +39,9 @@ server {
access_log off; access_log off;
} }
# API proxy to backend (container network) # API proxy to backend (configurable via $API_UPSTREAM)
location /api/ { location /api/ {
# Keep original request path; backend service name resolves inside Docker network proxy_pass $API_UPSTREAM;
proxy_pass http://backend:18888;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;