-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.frontend
More file actions
87 lines (72 loc) · 2.53 KB
/
Dockerfile.frontend
File metadata and controls
87 lines (72 loc) · 2.53 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# ==================================================
# Stage 1: Build Frontend
# ==================================================
FROM node:20-bullseye AS builder
# Install pnpm
RUN npm install -g pnpm@10.27.0
WORKDIR /app
# Copy workspace files
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY packages/frontend/package.json ./packages/frontend/
COPY packages/shared/package.json ./packages/shared/
# Install dependencies
RUN pnpm install --frozen-lockfile
# Copy source code
COPY packages/frontend ./packages/frontend
COPY packages/shared ./packages/shared
# Build shared package first (frontend depends on it)
RUN pnpm --filter @codeinsight/shared build
# Build argument for API URL
ARG VITE_API_URL=http://localhost:3002
# Set environment variable for Vite build
ENV VITE_API_URL=${VITE_API_URL}
# Build frontend
RUN pnpm --filter @codeinsight/frontend build
# ==================================================
# Stage 2: Nginx Production Server
# ==================================================
FROM nginx:alpine AS production
# Copy built frontend to nginx
COPY --from=builder /app/packages/frontend/dist /usr/share/nginx/html
# Create nginx configuration
RUN echo 'server { \n\
listen 80; \n\
server_name _; \n\
root /usr/share/nginx/html; \n\
index index.html; \n\
\n\
# Gzip compression \n\
gzip on; \n\
gzip_vary on; \n\
gzip_min_length 1024; \n\
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/javascript application/json; \n\
\n\
# Security headers \n\
add_header X-Frame-Options "SAMEORIGIN" always; \n\
add_header X-Content-Type-Options "nosniff" always; \n\
add_header X-XSS-Protection "1; mode=block" always; \n\
\n\
# SPA routing - all routes go to index.html \n\
location / { \n\
try_files $uri $uri/ /index.html; \n\
} \n\
\n\
# Cache static assets \n\
location ~* \\.(?:css|js|jpg|jpeg|gif|png|ico|svg|woff|woff2|ttf|eot)$ { \n\
expires 1y; \n\
add_header Cache-Control "public, immutable"; \n\
} \n\
\n\
# Disable cache for index.html \n\
location = /index.html { \n\
add_header Cache-Control "no-cache, no-store, must-revalidate"; \n\
expires 0; \n\
} \n\
}' > /etc/nginx/conf.d/default.conf
# Expose port 80
EXPOSE 80
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1
# Start nginx
CMD ["nginx", "-g", "daemon off;"]