front/Dockerfile.k3s
zzh 2dd3e656a3
All checks were successful
Build and Deploy Front / deploy (push) Successful in 6m58s
feat: H5 访客可逛四 Tab,登录门禁与微信注册引导优化
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-26 10:22:58 +08:00

44 lines
1.9 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.

# k3s / Kaniko:静态 SPA(方案 A)。TLS 由 Traefik(websecure) + cert-manager 终结。
# API 由浏览器按站点域名直连:
# test.ideship.com → api.test.ideship.com;其余 → api.ideship.com
# FRONT_BUILD_SCRIPT:
# prod 默认 build(.env.production → api.ideship.com)
# test 传 build:test(.env.ideship-test → api.test.ideship.com)
# 即使误用 production 构建,运行时也会按 hostname 纠正到测试 API。
#
# 构建耗时提示(宿主机 ci-publish-front.sh):
# 务必给 Kaniko 开 --cache=true(及 cache-repo / cache-ttl),
# 否则每次都会全量 pnpm install + vite build(本地 vite alone 约 3~4 分钟)。
# ---------- 运行时 serve:与源码无关,Kaniko 有 cache 时几乎秒过 ----------
FROM docker.m.daocloud.io/library/node:20-alpine AS serve-runtime
RUN npm config set registry https://registry.npmmirror.com \
&& npm install -g serve@14.2.4
# ---------- 前端构建 ----------
FROM docker.m.daocloud.io/library/node:20-alpine AS build
WORKDIR /app
ARG FRONT_BUILD_SCRIPT=build
# corepack 启用内置 pnpm,避免每次 npm install -g
RUN corepack enable \
&& corepack prepare pnpm@9.15.9 --activate \
&& pnpm config set registry https://registry.npmmirror.com
COPY package.json pnpm-lock.yaml ./
# --ignore-scripts:跳过 gifsicle/optipng 等原生编译(需 autoreconf;vite 未启用 imagemin)
# 先只装依赖,lock 不变时可命中 Kaniko 层缓存(最大收益)
RUN pnpm install --frozen-lockfile --ignore-scripts
COPY . .
RUN pnpm run ${FRONT_BUILD_SCRIPT}
# ---------- 最终镜像:只拷 serve + dist ----------
FROM docker.m.daocloud.io/library/node:20-alpine
WORKDIR /app
COPY --from=serve-runtime /usr/local/lib/node_modules/serve /usr/local/lib/node_modules/serve
COPY --from=serve-runtime /usr/local/bin/serve /usr/local/bin/serve
COPY --from=build /app/dist ./dist
EXPOSE 80
CMD ["serve", "-s", "dist", "-l", "80"]