-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
37 lines (28 loc) · 983 Bytes
/
Copy pathDockerfile
File metadata and controls
37 lines (28 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# syntax=docker/dockerfile:1
# ---------- 构建阶段:使用 Node 构建 Vite 前端静态产物 ----------
FROM node:20-alpine AS builder
WORKDIR /app
# 先复制依赖清单以利用 Docker 层缓存
COPY package.json package-lock.json ./
RUN npm ci
# 复制源码与构建配置
COPY tsconfig.json tsconfig.node.json ./
COPY web ./web
# 构建静态产物,输出至 /app/dist(见 web/vite.config.ts 的 build.outDir)
RUN npm run build:web
# ---------- 运行阶段:使用 nginx 托管静态文件 ----------
FROM nginx:1.27-alpine AS runner
# 自定义 nginx 配置,支持 SPA 路由回退到 index.html
RUN printf 'server {\n\
listen 80;\n\
server_name _;\n\
root /usr/share/nginx/html;\n\
index index.html;\n\
location / {\n\
try_files $uri $uri/ /index.html;\n\
}\n\
}\n' > /etc/nginx/conf.d/default.conf
# 拷贝构建产物
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]