Files
frontend_v2/Dockerfile
toom1996 549d025afe update
2026-10-19 00:33:53 +08:00

41 lines
1.2 KiB
Docker
Raw Permalink 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 取数地址:走宿主回环的代理 18091(deploy.sh 传 build-arg,配合 build.network=host)。
# 由代理转发到「当前活跃的后端槽」,所以构建期不受正在更新哪个槽影响。
ARG BASE_API_SSG=http://127.0.0.1:18091
ENV BASE_API_SSG=$BASE_API_SSG
# SSG 内部接口可选令牌(无 PUBLIC_ 前缀,绝不会进入前端 bundle)
ARG SSG_TOKEN=""
ENV SSG_TOKEN=$SSG_TOKEN
# 运行期浏览器调用地址:空 = 同源相对 /api(由 proxy 反代到后端)
ENV BASE_API=""
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# ---- 运行阶段:只跑 Astro node server,nginx 已独立成 proxy 容器 ----
FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production \
HOST=0.0.0.0 \
PORT=3000
COPY package*.json ./
RUN npm ci --omit=dev && npm cache clean --force
COPY --from=build /app/dist ./dist
EXPOSE 3000
# 只探端口存活:SSR 取数临时失败不应该把容器判死(否则蓝绿切换会误判)
HEALTHCHECK --interval=15s --timeout=3s --start-period=15s --retries=3 \
CMD nc -z 127.0.0.1 3000 || exit 1
CMD ["node", "./dist/server/entry.mjs"]