File tree Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Original file line number Diff line number Diff line change 1+ # ---------- Builder stage ----------
2+ FROM node:20-slim AS builder
3+
4+ # Set working directory
5+ WORKDIR /usr/src/app
6+
7+ # Copy package files to the container
8+ COPY package*.json ./
9+
10+ # Install the dependencies and build
11+ RUN npm cache clean --force
12+ RUN npm ci
13+
14+ # Copy source code
15+ COPY . .
16+
17+ # Build the application
18+ RUN npm run build:prod
19+
20+
21+ # ---------- Production stage ----------
22+ FROM nginx:alpine
23+
24+ # Copy built assets from builder stage
25+ COPY --from=builder /usr/src/app/dist /usr/share/nginx/html
26+
27+ COPY nginx.conf /etc/nginx/nginx.conf
28+
29+ # Prepare directories with correct ownership for nginx user
30+ RUN mkdir -p /var/cache/nginx/client_temp /var/run && \
31+ chown -R 65532:65532 /var/cache/nginx /var/run
32+
33+ # Switch to non-root user
34+ USER 65532:65532
35+
36+ # Expose port
37+ EXPOSE 8080
38+
39+ # Set environment variables
40+ ENV PORT=8080
41+
42+ # Start the production server
43+ CMD ["nginx" , "-g" , "daemon off;" ]
Original file line number Diff line number Diff line change 1+
2+ worker_processes 1;
3+
4+ error_log /var/log/nginx/error.log warn;
5+ pid /tmp/nginx.pid ;
6+
7+ events {
8+ worker_connections 1024 ;
9+ }
10+
11+ http {
12+ log_format main '$remote_addr - $remote_user [$time_local] - $http_x_api_version - $upstream - "$request" '
13+ '$status $body_bytes_sent "$http_referer" '
14+ '"$http_user_agent" "$http_x_forwarded_for"' ;
15+
16+ access_log /var/log/nginx/access.log main;
17+
18+ include /etc/nginx/mime.types ;
19+ default_type application/octet-stream ;
20+
21+ server {
22+ listen 8080 ;
23+
24+ location / {
25+ root /usr/share/nginx/html;
26+ index index .html;
27+ }
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments