-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile.vote.template
More file actions
66 lines (52 loc) · 1.81 KB
/
Copy pathDockerfile.vote.template
File metadata and controls
66 lines (52 loc) · 1.81 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# ============================================================
# THVote Vote App Dockerfile 模板
#
# 构建时由 CI workflow 内联生成(使用 heredoc)
# 多阶段构建:从源代码构建
#
# 使用方式(在 workflow 中):
# docker build -t $TAG --build-arg BACKEND_URL=http://backend:8000 -f - . << 'EOF'
# $(cat Dockerfile.vote.template)
# EOF
# ============================================================
# ---- Build Stage ----
FROM node:20-alpine AS build
# 安装 pnpm
RUN corepack enable && corepack prepare pnpm@10.33.0 --activate
WORKDIR /app
# 设置 pnpm store
ENV PNPM_HOME=/pnpm
ENV PATH=$PNPM_HOME:$PATH
# 复制源代码
COPY . .
# 安装依赖
RUN pnpm install --frozen-lockfile
# 设置 GraphQL schema 获取地址(构建时通过 --build-arg 传入)
ARG BACKEND_URL=http://localhost:8000
# 预下载 schema(如果本地存在则跳过)
# codegen 在 CI 中由 workflow 执行,此处仅保留占位
# RUN echo "GraphQL schema 从 ${BACKEND_URL} 获取"
# 构建应用
RUN pnpm --filter @touhou-vote/vote run build -- --mode test
# ---- Production Stage ----
FROM nginx:alpine
# 监听 8082(与 test 环境配置一致)
RUN echo 'server { \
listen 8082; \
location / { \
root /usr/share/nginx/html; \
try_files $uri /index.html; \
} \
location /v11-be/ { \
proxy_pass http://thvote-backend:8000/; \
proxy_http_version 1.1; \
proxy_set_header Host $host; \
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; \
} \
}' > /etc/nginx/conf.d/default.conf
EXPOSE 8082
# 从 build stage 复制构建产物
COPY --from=build /app/packages/vote/dist /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]