-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.frontend
More file actions
54 lines (38 loc) · 1.27 KB
/
Dockerfile.frontend
File metadata and controls
54 lines (38 loc) · 1.27 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
# Build stage
FROM node:18.18.2-alpine3.18 AS build
WORKDIR /app
# Copy package files
COPY frontend/package*.json ./
# Install dependencies with audit level set to critical and skip husky
RUN npm install --only=production --audit-level=critical --ignore-scripts
# Copy source code
COPY frontend/ .
# Set environment variables
ENV NODE_ENV=production
# Build the app
RUN npm run build
# Production stage
FROM nginx:1.25.3-alpine
# Remove default nginx static assets
RUN rm -rf /usr/share/nginx/html/*
# Copy built assets from build stage
COPY --from=build /app/build /usr/share/nginx/html
# Copy nginx config
COPY nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
# Set permissions for nginx user
RUN chown -R nginx:nginx /var/cache/nginx && \
chown -R nginx:nginx /var/log/nginx && \
chown -R nginx:nginx /etc/nginx/conf.d && \
chown -R nginx:nginx /usr/share/nginx/html
# Create and set permissions for nginx pid file
RUN touch /var/run/nginx.pid && \
chown -R nginx:nginx /var/run/nginx.pid
# Run as non-root user
USER nginx
# Expose port 80
EXPOSE 80
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost/ || exit 1
# Start Nginx
CMD ["nginx", "-g", "daemon off;"]