Files
integral-shop/deploy/docker/single-shop/h5.Dockerfile
danaisuiyuan fb76270882 feat(deploy): 完整 Docker 部署方案 — 寄卖商城 + 积分商城
新增两步独立 Docker 部署方案(czleilei240 环境):

步骤一 寄卖商城(integral-resell)
- step1-integral/docker-compose.yml:redis(Alpine自建) + houtai(webman PHP8) + h5(Nginx)
- houtai.Dockerfile:PHP 8.0 + 阿里云镜像源 + webman.bin entrypoint
- h5.Dockerfile:Nginx + configs.js 环境变量动态重写
- redis.Dockerfile:Alpine + apk 构建,绕过 DockerHub 镜像源问题
- 宿主机 bind-mount:/www/wwwroot/leileiadmin.czchunfang.com(FTP可直接更新程序)

步骤二 积分商城(single-shop-22)
- step2-single-shop/docker-compose.yml:redis + admin-api + front-api + admin-web + h5
- Java Dockerfiles:OpenJDK 17 + --add-opens Spring Boot 2.2.6 兼容

公共配置
- nginx/:四个域名宝塔 Nginx 反代配置(HTTP→HTTPS 301、SSL 终止)
- scripts/:sync-to-server.sh / deploy-step1.sh / remote-up.sh
- DOCKER_DEPLOY.md:完整部署文档

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-17 17:24:08 +08:00

97 lines
3.2 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# =============================================================
# 寄卖商城 用户端 H5 uni-app
# build context = single-shop-22/single_uniapp22miao
# 多阶段: Node 构建 H5 -> Nginx 运行
# 通过 ARG H5_API_DOMAIN 注入 API 域名(留空走同域 /api/
#
# 直接复用源码已构建产物: 用 --target=fast 构建
# =============================================================
# syntax=docker/dockerfile:1.6
# ---------- 构建阶段 ----------
FROM node:16-alpine AS builder
ARG H5_API_DOMAIN=""
ENV NODE_OPTIONS=--openssl-legacy-provider \
NPM_CONFIG_REGISTRY=https://registry.npmmirror.com
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm install --legacy-peer-deps
COPY . .
# 重写 config/app.js 中的 domain
# 留空时使用同域: let domain = ''
RUN sed -i -E "s|^let[[:space:]]+domain[[:space:]]*=.*|let domain = '${H5_API_DOMAIN}'|" config/app.js \
&& sed -i -E "s|HTTP_H5_URL:[[:space:]]*'[^']*'|HTTP_H5_URL: '${H5_API_DOMAIN}'|" config/app.js \
&& cat config/app.js
RUN npm run build:h5
# uni-app 默认产物路径
# unpackage/dist/build/h5 Vue CLI Plugin uni 旧版: unpackage/dist/build/web
# ---------- 运行阶段 ----------
FROM nginx:1.25-alpine AS runtime
ENV TZ=Asia/Shanghai
RUN apk add --no-cache tzdata \
&& cp /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone
COPY --from=builder /app/unpackage/dist/build/ /tmp/h5build/
# 兼容两种输出目录名 h5/ 或 web/
RUN if [ -d /tmp/h5build/h5 ]; then cp -r /tmp/h5build/h5/. /usr/share/nginx/html/; \
elif [ -d /tmp/h5build/web ]; then cp -r /tmp/h5build/web/. /usr/share/nginx/html/; \
else echo "未找到 h5 / web 产物"; exit 1; fi \
&& rm -rf /tmp/h5build
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;
add_header X-Frame-Options SAMEORIGIN always;
location ~* \.(?:js|css|png|jpg|jpeg|gif|svg|woff2?|ttf|map)$ {
expires 30d;
add_header Cache-Control "public, max-age=2592000, immutable";
try_files $uri =404;
}
location /api/ {
proxy_pass http://single-front-api:30031/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 / {
try_files $uri $uri/ /index.html;
}
}
NGX
EXPOSE 80
# ---------- 备选: 直接复用源码已构建的 unpackage/dist/build/h5 ----------
# 构建: docker compose build --target fast single-h5
FROM nginx:1.25-alpine AS fast
ENV TZ=Asia/Shanghai
RUN apk add --no-cache tzdata \
&& cp /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone
COPY unpackage/dist/build/ /tmp/h5build/
RUN if [ -d /tmp/h5build/h5 ]; then cp -r /tmp/h5build/h5/. /usr/share/nginx/html/; \
elif [ -d /tmp/h5build/web ]; then cp -r /tmp/h5build/web/. /usr/share/nginx/html/; \
else echo "未找到 h5 / web 产物"; exit 1; fi \
&& rm -rf /tmp/h5build
COPY --from=runtime /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80