Files
frontend_v2/Dockerfile
toom1996 b274ccdfec
Some checks failed
deploy / deploy (push) Has been cancelled
update
2026-08-23 00:58:33 +08:00

32 lines
1.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.

# ---- 前端构建阶段 ----
FROM node:22-alpine AS build
WORKDIR /app
# 构建期 SSG 拉数据用的「后端 SSG 内部地址」。
# 在 docker-compose 里通过 build.args.BASE_API_SSG 传入(= http://localhost:8091,
# 配合 build.network: host,让前端构建容器能访问已启动的 backend 容器的 SSG 内部端口)。
# 该端口只绑宿主回环(127.0.0.1:8091),nginx 绝不反代,因此 SSG 全量数据不会外泄。
# BASE_API_SSG 与运行期 BASE_API(8090)完全分离,二者指向不同端口。
ARG BASE_API_SSG=http://localhost:8091
ENV BASE_API_SSG=$BASE_API_SSG
# SSG 内部端口的可选访问令牌(防御纵深)。仅构建期 node fetch 使用,且不带 PUBLIC_ 前缀,
# 故绝不会进入前端 bundle。置空时后端不校验(依赖回环绑定即可)。
ARG SSG_TOKEN=""
ENV SSG_TOKEN=$SSG_TOKEN
# 运行期浏览器调用地址:置空 = 同源相对路径 /api(由下方 nginx 反代到 backend:8090)
ENV BASE_API=""
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# ---- 静态托管阶段 ----
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]