Skip to content

Commit f77bc77

Browse files
committed
containerize_frontend_component/#392
Signed-off-by: Noa <[email protected]>
1 parent b2bee1d commit f77bc77

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

workspaces/frontend/.dockerignore

Whitespace-only changes.

workspaces/frontend/Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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;"]

workspaces/frontend/nginx.conf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

0 commit comments

Comments
 (0)