Merge branch 'test' of https://git.ideship.com/ideship/front into test
All checks were successful
Build and Deploy Front / deploy (push) Successful in 3m58s

This commit is contained in:
zzh 2026-11-11 17:35:10 +08:00
commit 3d40f08e49
6 changed files with 86 additions and 43 deletions

View File

@ -9,7 +9,8 @@
.idea
node_modules
dist
# 勿排除 dist:宿主机构建 Dockerfile / Dockerfile.k3s.runtime 需要 COPY dist/
# Kaniko 多阶段会在镜像内重新 pnpm build,带上旧 dist 无妨
coverage
*.log
npm-debug.log*

View File

@ -1,8 +1,6 @@
# 复制到 itfx-front 仓库 .gitea/workflows/deploy.yml
# push master → prod;push test → test
# 构建始终用 prod kubeconfig(Kaniko);仅 deploy 切集群
# 前端镜像:test 分支须传 FRONT_BUILD_SCRIPT=build:test,否则会打进正式 API 域名
# 构建变慢时:确认宿主机 ci-publish-front.sh 已给 Kaniko --cache=true(lock 不变时应跳过 pnpm install)
# 构建:runner 宿主 pnpm + docker(ci-publish-front.sh);仅 deploy 切集群
name: Build and Deploy Front
on:

View File

@ -1,9 +1,6 @@
# 本地/简易 Docker:仅静态 SPA。HTTPS 由外层网关(如 Traefik)终结。
# 构建前先执行:pnpm build
FROM docker.m.daocloud.io/library/node:20-alpine
WORKDIR /app
RUN npm config set registry https://registry.npmmirror.com \
&& npm install -g serve@14.2.4
COPY dist/ ./dist/
# 本地/简易:先 pnpm build,再 docker build
# HTTPS 由外层网关(Traefik)终结
FROM docker.m.daocloud.io/library/nginx:1.27-alpine
COPY dist/ /usr/share/nginx/html/
COPY nginx-k3s.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["serve", "-s", "dist", "-l", "80"]

View File

@ -1,43 +1,17 @@
# 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
# ---------- 前端构建 ----------
# k3s / Kaniko 备用:多阶段构建。生产 CI 优先宿主 pnpm + Dockerfile.k3s.runtime
# TLS 由 Traefik(websecure) + cert-manager 终结;API 浏览器直连。
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
FROM docker.m.daocloud.io/library/nginx:1.27-alpine
COPY --from=build /app/dist /usr/share/nginx/html/
COPY nginx-k3s.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["serve", "-s", "dist", "-l", "80"]

5
Dockerfile.k3s.runtime Normal file
View File

@ -0,0 +1,5 @@
# 宿主机构建 dist 后只打 nginx 静态层(CI:ci-publish-front.sh)
FROM docker.m.daocloud.io/library/nginx:1.27-alpine
COPY dist/ /usr/share/nginx/html/
COPY nginx-k3s.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

68
nginx-k3s.conf Normal file
View File

@ -0,0 +1,68 @@
# k3s 方案 A:仅静态 SPA。API 由浏览器按域名直连;TLS 由 Traefik 终结。
server {
listen 80;
server_name _;
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml image/svg+xml;
root /usr/share/nginx/html;
index index.html;
# 官网静态(若存在);否则回退 SPA
location = / {
try_files /site/index.html /index.html =404;
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
location = /site {
return 301 /;
}
location = /site/ {
return 301 /;
}
location = /site/index.html {
return 301 /;
}
location ^~ /site/ {
try_files $uri =404;
expires 7d;
add_header Cache-Control "public";
access_log off;
}
location = /favicon.ico {
try_files /favicon.png /favicon.ico =404;
expires 7d;
add_header Cache-Control "public";
access_log off;
}
location = /index.html {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
# 微信域名校验文件
location ~* ^/MP_verify_[A-Za-z0-9]+\.txt$ {
try_files $uri =404;
add_header Cache-Control "no-cache";
}
location ~* \.(?:js|css|woff2?|ttf|eot|svg|png|jpe?g|gif|webp|ico|map)$ {
try_files $uri =404;
expires 7d;
add_header Cache-Control "public";
access_log off;
}
# SPA 路由回退
location / {
try_files $uri $uri/ /index.html;
}
}