20261111 #21
13
Dockerfile
13
Dockerfile
@ -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"]
|
||||
|
||||
@ -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"]
|
||||
|
||||
192
nginx-k3s.conf
192
nginx-k3s.conf
@ -1,4 +1,4 @@
|
||||
# k3s 方案 A:仅静态 SPA。API 由浏览器按域名直连(prod: api.ideship.com / test: api.test.ideship.com)。
|
||||
# k3s 方案 A:仅静态 SPA。API 由浏览器按域名直连;TLS 由 Traefik 终结。
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
@ -9,14 +9,14 @@ server {
|
||||
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 $uri @spa;
|
||||
}
|
||||
|
||||
location = /9610.html {
|
||||
try_files /9610.html =404;
|
||||
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 {
|
||||
@ -28,7 +28,6 @@ server {
|
||||
location = /site/index.html {
|
||||
return 301 /;
|
||||
}
|
||||
|
||||
location ^~ /site/ {
|
||||
try_files $uri =404;
|
||||
expires 7d;
|
||||
@ -37,190 +36,33 @@ server {
|
||||
}
|
||||
|
||||
location = /favicon.ico {
|
||||
try_files /favicon.png =404;
|
||||
try_files /favicon.png /favicon.ico =404;
|
||||
expires 7d;
|
||||
add_header Cache-Control "public";
|
||||
access_log off;
|
||||
}
|
||||
|
||||
location = /favicon.png {
|
||||
try_files /favicon.png =404;
|
||||
expires 7d;
|
||||
add_header Cache-Control "public";
|
||||
access_log off;
|
||||
}
|
||||
|
||||
location = /login {
|
||||
try_files $uri @spa;
|
||||
}
|
||||
location = /login/ {
|
||||
try_files $uri @spa;
|
||||
}
|
||||
|
||||
rewrite ^/admin/?$ /index.html last;
|
||||
|
||||
location = /admin {
|
||||
try_files $uri @spa;
|
||||
}
|
||||
location = /admin/ {
|
||||
try_files $uri @spa;
|
||||
}
|
||||
|
||||
location ~ ^/api/(upstreamInterface|upstreamInterfaceConfig|upstreamInterfaceConfigEdit|downstreamInterface(|/newPort)|appList(|/createApplication)|requestLog|callStatistics|apiDebugger|apiTest|openApi)(/|$) {
|
||||
try_files $uri @spa;
|
||||
}
|
||||
|
||||
location ^~ /xhs/startService { try_files $uri @spa; }
|
||||
location ^~ /xhs/creation { try_files $uri @spa; }
|
||||
location ^~ /xhs/publishHistory { try_files $uri @spa; }
|
||||
location ^~ /xhs/skills { try_files $uri @spa; }
|
||||
location ^~ /xhs/humanSettings { try_files $uri @spa; }
|
||||
location ^~ /xhs/agentPair { try_files $uri @spa; }
|
||||
location = /xhs/analysis { try_files $uri @spa; }
|
||||
location = /xhs/analysis/ { try_files $uri @spa; }
|
||||
|
||||
location ^~ /wechat/register { try_files $uri @spa; }
|
||||
location ^~ /wechat/bind { try_files $uri @spa; }
|
||||
location ^~ /h5 { try_files $uri @spa; }
|
||||
location ^~ /track/query { try_files $uri @spa; }
|
||||
location ^~ /operation/inboundScan { try_files $uri @spa; }
|
||||
location ^~ /operation/outboundScan { try_files $uri @spa; }
|
||||
location ^~ /operation/printLabel { try_files $uri @spa; }
|
||||
location ^~ /operation/parcelArrival { try_files $uri @spa; }
|
||||
location ^~ /operation/fulfillPack { try_files $uri @spa; }
|
||||
|
||||
# 订单前端路由(^~ 须比下方 /order/ API 正则代理更优先)
|
||||
location ^~ /order/priceCheck { try_files $uri @spa; }
|
||||
location ^~ /order/placeOrder { try_files $uri @spa; }
|
||||
location ^~ /order/myOrders { try_files $uri @spa; }
|
||||
location ^~ /order/fulfillOrders { try_files $uri @spa; }
|
||||
location ^~ /order/waybillManage { try_files $uri @spa; }
|
||||
location ^~ /order/pickupOrder { try_files $uri @spa; }
|
||||
location ^~ /order/customs9610Order { try_files $uri @spa; }
|
||||
location ^~ /order/batchJobs { try_files $uri @spa; }
|
||||
location ^~ /order/templateMapping { try_files $uri @spa; }
|
||||
location ^~ /order/platformStore { try_files $uri @spa; }
|
||||
location ^~ /order/platformStoreOrder { try_files $uri @spa; }
|
||||
|
||||
# 知识库前端路由(^~ 须比下方 /kb/ API 代理更优先)
|
||||
location ^~ /kb/category { try_files $uri @spa; }
|
||||
location ^~ /kb/article { try_files $uri @spa; }
|
||||
|
||||
location = /warehouse/parcel { try_files $uri @spa; }
|
||||
location = /warehouse/inventory { try_files $uri @spa; }
|
||||
location = /warehouse/sku { try_files $uri @spa; }
|
||||
location = /warehouse/binLocation { try_files $uri @spa; }
|
||||
location ^~ /warehouse/inboundNotice { try_files $uri @spa; }
|
||||
location ^~ /Plugin/ { try_files $uri @spa; }
|
||||
|
||||
location ^~ /channel/salesProducts { try_files $uri @spa; }
|
||||
location ^~ /channel/serviceChannels { try_files $uri @spa; }
|
||||
location ^~ /channel/priceArea { try_files $uri @spa; }
|
||||
location ^~ /channel/blacklist { try_files $uri @spa; }
|
||||
location ^~ /channel/remoteZones { try_files $uri @spa; }
|
||||
location ^~ /channel/weightRules { try_files $uri @spa; }
|
||||
location ^~ /channel/weightRounding { try_files $uri @spa; }
|
||||
location ^~ /channel/autoTrigger { try_files $uri @spa; }
|
||||
location ^~ /channel/issueTemplate { try_files $uri @spa; }
|
||||
location ^~ /channel/labelDesign { try_files $uri @spa; }
|
||||
|
||||
# 官网线路目录。这条不是前端路由;落到下方 SPA 会返回 index.html,浏览器看不到 JSON。
|
||||
# 仅这一条转到对应环境的 Admin API(test → api.test.ideship.com,其余 → api.ideship.com)。
|
||||
location = /channel/sales-product/portal/catalog {
|
||||
set $oms_api_upstream api.ideship.com;
|
||||
if ($host ~* "(^test\.ideship\.com$|\.test\.ideship\.com$)") {
|
||||
set $oms_api_upstream api.test.ideship.com;
|
||||
}
|
||||
resolver 1.1.1.1 8.8.8.8 ipv6=off valid=300s;
|
||||
resolver_timeout 5s;
|
||||
proxy_http_version 1.1;
|
||||
proxy_ssl_server_name on;
|
||||
proxy_set_header Host $oms_api_upstream;
|
||||
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_pass https://$oms_api_upstream/admin/channel/sales-product/portal/catalog$is_args$args;
|
||||
proxy_connect_timeout 10s;
|
||||
proxy_read_timeout 30s;
|
||||
}
|
||||
|
||||
# 营销前端路由(^~ 须比下方 /marketing/ API 正则代理更优先)
|
||||
location ^~ /marketing/memberLevel { try_files $uri @spa; }
|
||||
location ^~ /marketing/pointsRule { try_files $uri @spa; }
|
||||
location ^~ /marketing/pointsFlow { try_files $uri @spa; }
|
||||
location ^~ /marketing/couponTemplate { try_files $uri @spa; }
|
||||
location ^~ /marketing/couponGrant { try_files $uri @spa; }
|
||||
location ^~ /marketing/commissionRule { try_files $uri @spa; }
|
||||
location ^~ /marketing/commissionDetail { try_files $uri @spa; }
|
||||
location ^~ /marketing/commissionWithdraw { try_files $uri @spa; }
|
||||
location ^~ /marketing/referralTree { try_files $uri @spa; }
|
||||
|
||||
# 面单/截图同源代理:/__cos__/<host>/<path> → http://<host>/<path>
|
||||
# cos.* 自定义域 https 证书常仍是 *.myqcloud.com;上游继续走 http。
|
||||
# COS 签名 q-sign-time 含 ";":前端须编成 %3B,否则查询串被按 ";" 拆参 → Request has expired。
|
||||
location ~ ^/__cos__/([^/]+)(/.*)$ {
|
||||
set $cos_host $1;
|
||||
set $cos_uri $2;
|
||||
resolver 1.1.1.1 8.8.8.8 ipv6=off valid=300s;
|
||||
resolver_timeout 5s;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $cos_host;
|
||||
proxy_set_header Authorization "";
|
||||
proxy_set_header Cookie "";
|
||||
proxy_set_header X-Real-IP "";
|
||||
proxy_pass http://$cos_host$cos_uri$is_args$args;
|
||||
proxy_connect_timeout 10s;
|
||||
proxy_read_timeout 120s;
|
||||
proxy_buffering off;
|
||||
}
|
||||
|
||||
# 系统管理前端路由(^~ 须比下方 /system/ API 正则代理更优先)
|
||||
location = /system/dict { try_files $uri @spa; }
|
||||
location = /system/warehouseAddress { try_files $uri @spa; }
|
||||
location = /system/announcement { try_files $uri @spa; }
|
||||
location = /system/country { try_files $uri @spa; }
|
||||
location ^~ /system/users { try_files $uri @spa; }
|
||||
location ^~ /system/roles { try_files $uri @spa; }
|
||||
location ^~ /system/menus { try_files $uri @spa; }
|
||||
location ^~ /system/organizations { try_files $uri @spa; }
|
||||
location ^~ /system/batchEmail { try_files $uri @spa; }
|
||||
location ^~ /system/otherConfig { try_files $uri @spa; }
|
||||
location ^~ /system/aiAssistant { try_files $uri @spa; }
|
||||
location ^~ /system/aiSkills { try_files $uri @spa; }
|
||||
location ^~ /system/mcpTools { try_files $uri @spa; }
|
||||
location ^~ /system/dataPerm/ { try_files $uri @spa; }
|
||||
|
||||
# SPA 回退:try_files $uri @spa 统一带 no-cache,避免部署后浏览器缓存旧 index.html
|
||||
location @spa {
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
|
||||
add_header Pragma "no-cache" always;
|
||||
add_header Expires "0" always;
|
||||
try_files /index.html =404;
|
||||
}
|
||||
|
||||
location = /index.html {
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
|
||||
add_header Pragma "no-cache" always;
|
||||
add_header Expires "0" always;
|
||||
try_files /index.html =404;
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
add_header Expires "0";
|
||||
}
|
||||
|
||||
# 微信 JS 安全域名校验:原样返回 txt,禁止 SPA 回落 index.html
|
||||
# 微信域名校验文件
|
||||
location ~* ^/MP_verify_[A-Za-z0-9]+\.txt$ {
|
||||
default_type text/plain;
|
||||
charset off;
|
||||
add_header Cache-Control "no-store";
|
||||
try_files $uri =404;
|
||||
add_header Cache-Control "no-cache";
|
||||
}
|
||||
|
||||
location ~* \.(?:js|css)$ {
|
||||
location ~* \.(?:js|css|woff2?|ttf|eot|svg|png|jpe?g|gif|webp|ico|map)$ {
|
||||
try_files $uri =404;
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
expires 7d;
|
||||
add_header Cache-Control "public";
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# SPA 路由回退
|
||||
location / {
|
||||
try_files $uri @spa;
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user