-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (69 loc) · 2.46 KB
/
Dockerfile
File metadata and controls
70 lines (69 loc) · 2.46 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
67
68
69
70
# syntax=docker/dockerfile:1
FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json pnpm-lock.yaml* yarn.lock* .npmrc* ./
RUN npm i -g pnpm@9 && pnpm i --frozen-lockfile || npm ci || yarn install --frozen-lockfile
COPY . .
RUN pnpm build || npm run build || yarn build
FROM nginx:1.27-alpine
RUN apk add --no-cache curl
COPY --from=build /app/dist /usr/share/nginx/html
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# 單頁應用 SPA fallback + API proxy
RUN printf 'server {\n\
listen 80;\n\
root /usr/share/nginx/html;\n\
\n\
# Disable caching for runtime config (dynamically generated at container startup)\n\
location = /runtime-config.js {\n\
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";\n\
add_header Pragma "no-cache";\n\
add_header Expires "0";\n\
try_files $uri =404;\n\
}\n\
\n\
# Proxy API requests to backend\n\
location /api/ {\n\
proxy_pass http://kai-backend:9900;\n\
proxy_http_version 1.1;\n\
proxy_set_header Upgrade $http_upgrade;\n\
proxy_set_header Connection "upgrade";\n\
proxy_set_header Host $host;\n\
proxy_set_header X-Real-IP $remote_addr;\n\
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
proxy_set_header X-Forwarded-Proto $scheme;\n\
}\n\
\n\
# Proxy Flexy sandbox requests to backend\n\
location /flexy/ {\n\
proxy_pass http://kai-backend:9900;\n\
proxy_http_version 1.1;\n\
proxy_set_header Upgrade $http_upgrade;\n\
proxy_set_header Connection "upgrade";\n\
proxy_set_header Host $host;\n\
proxy_set_header X-Real-IP $remote_addr;\n\
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
proxy_set_header X-Forwarded-Proto $scheme;\n\
}\n\
\n\
# Proxy code-server requests to backend\n\
location /code-server/ {\n\
proxy_pass http://kai-backend:9900;\n\
proxy_http_version 1.1;\n\
proxy_set_header Upgrade $http_upgrade;\n\
proxy_set_header Connection "upgrade";\n\
proxy_set_header Host $host;\n\
proxy_set_header X-Real-IP $remote_addr;\n\
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
proxy_set_header X-Forwarded-Proto $scheme;\n\
}\n\
\n\
# SPA fallback for console routes\n\
location / {\n\
try_files $uri $uri/ /index.html;\n\
}\n\
}\n' > /etc/nginx/conf.d/default.conf
EXPOSE 80
HEALTHCHECK --interval=5s --timeout=3s --retries=20 CMD curl -f http://localhost/ || exit 1
ENTRYPOINT ["/entrypoint.sh"]