Files
2026-05-29 09:19:30 +08:00

94 lines
2.6 KiB
Docker

# =============================================================
# 寄卖商城 H5 静态站运行时镜像
# 静态文件通过 bind-mount 挂入 /usr/share/nginx/html
# =============================================================
FROM nginx:1.25-alpine
ENV TZ=Asia/Shanghai
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk add --no-cache tzdata \
&& cp /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone \
&& rm -f /etc/apk/cache/*.apk
RUN cat > /etc/nginx/conf.d/default.conf <<'NGX'
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
client_max_body_size 50m;
location ~* \.(?:js|css|png|jpg|jpeg|gif|svg|woff2?|ttf|map|pdf)$ {
expires 30d;
add_header Cache-Control "public, max-age=2592000";
try_files $uri =404;
}
location /api/ {
proxy_pass http://integral-houtai:8785/api/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 120s;
client_max_body_size 50m;
}
location /upload/ {
proxy_pass http://integral-houtai:8785/upload/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 120s;
client_max_body_size 50m;
}
location / {
try_files $uri $uri/ /index.html;
}
}
NGX
RUN cat > /docker-entrypoint.d/90-integral-configs.sh <<'SH' \
&& chmod +x /docker-entrypoint.d/90-integral-configs.sh
#!/bin/sh
set -eu
CONFIG_FILE=/usr/share/nginx/html/static/configs.js
[ -f "$CONFIG_FILE" ] || exit 0
escape_sed() {
printf '%s' "$1" | sed 's/[\/&]/\\&/g'
}
replace_js_string() {
key="$1"
value="$2"
[ -n "$value" ] || return 0
sed -i -E "s#(${key}:[[:space:]]*)'[^']*'#\1'$(escape_sed "$value")'#" "$CONFIG_FILE"
}
replace_js_number() {
key="$1"
value="$2"
[ -n "$value" ] || return 0
sed -i -E "s#(${key}:[[:space:]]*)[0-9]+#\1${value}#" "$CONFIG_FILE"
}
replace_js_string TITLE "${INTEGRAL_TITLE:-}"
replace_js_string BASE_URL "${INTEGRAL_API_PUBLIC_URL:-}/api"
replace_js_string IMG_URL "${INTEGRAL_IMG_PUBLIC_URL:-}"
replace_js_string H5_URL "${INTEGRAL_H5_PUBLIC_URL:-}"
replace_js_number sn_id "${INTEGRAL_SN_ID:-}"
replace_js_string appStr "${INTEGRAL_APP_STR:-}"
SH
EXPOSE 80