-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
54 lines (39 loc) · 1.65 KB
/
Dockerfile
File metadata and controls
54 lines (39 loc) · 1.65 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
# Dockerfile for Simplistic Tetris
# Multi-stage build and deployment
# Stage 1: Build
FROM node:20-alpine AS builder
# Set the working directory
WORKDIR /tetris
# Copy the dependency files (Docker cache optimization)
COPY package.json package-lock.json ./
# Install the dependencies (npm ci installe toutes les dépendances par défaut)
RUN npm ci && \
npm cache clean --force
# Copy the rest of the source files
COPY . .
# Build the application
RUN npm run build
# Stage 2: Production with Nginx
FROM nginx:1.27-alpine AS production
# Create a non-root user and directories in one layer
# Install curl for healthcheck (lighter than wget)
RUN addgroup -g 1001 -S nginx-user && \
adduser -S -D -H -u 1001 -h /var/cache/nginx -s /sbin/nologin -G nginx-user -g nginx nginx-user && \
mkdir -p /var/run/nginx /var/cache/nginx/client_temp /var/cache/nginx/proxy_temp /var/cache/nginx/fastcgi_temp /var/cache/nginx/uwsgi_temp /var/cache/nginx/scgi_temp && \
apk add --no-cache curl
# Copy the built files from the builder stage
COPY --from=builder /tetris/dist /usr/share/nginx/html
# Copy nginx configuration files
COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
# Change the permissions in one layer
RUN chown -R nginx-user:nginx-user /usr/share/nginx/html /var/cache/nginx /var/log/nginx /etc/nginx/conf.d /var/run/nginx
# Switch to the non-root user
USER nginx-user
# Expose the port 80
EXPOSE 80
# Healthcheck (using curl, lighter than wget)
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:80/ || exit 1
# Start nginx
CMD ["nginx", "-g", "daemon off;"]