fix: 前端自动化部署优化
This commit is contained in:
1 parent
6bcd8f4d09
commit
246d49a038
5 files changed
+26
-5
No files matched your search
+3
-2
@@ -22,8 +22,9 @@ FROM nginx:alpine
|
||||
# Copy built assets
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
|
||||
# Copy custom nginx configuration
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
# Copy nginx configuration template and entrypoint to render from env
|
||||
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
|
||||
RUN mkdir -p /var/log/nginx
|
||||
|
||||
@@ -87,6 +87,8 @@ services:
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
# Set API upstream for automated deployments (e.g., external gateway or backend host)
|
||||
- API_UPSTREAM=${API_UPSTREAM:-http://backend:18888}
|
||||
ports:
|
||||
- "${FRONTEND_PORT:-80}:80"
|
||||
depends_on:
|
||||
|
||||
@@ -68,6 +68,7 @@ services:
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- API_UPSTREAM=http://backend:18888
|
||||
ports:
|
||||
- "18080:80"
|
||||
depends_on:
|
||||
|
||||
@@ -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
@@ -39,10 +39,9 @@ server {
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# API proxy to backend (container network)
|
||||
# API proxy to backend (configurable via $API_UPSTREAM)
|
||||
location /api/ {
|
||||
# Keep original request path; backend service name resolves inside Docker network
|
||||
proxy_pass http://backend:18888;
|
||||
proxy_pass $API_UPSTREAM;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
Reference in new issue
Block a user