Skip to content

Commit 2f562ca

Browse files
committed
Improved web dockerfile
1 parent 9273ac4 commit 2f562ca

4 files changed

Lines changed: 50 additions & 26 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
docker run --rm ${{ env.IMAGE_PREFIX }}/cli:${{ github.ref_name }} --help
4242
4343
# Run Web UI
44-
docker run -p 80:80 ${{ env.IMAGE_PREFIX }}/web:${{ github.ref_name }}
44+
docker run -p 8080:8080 ${{ env.IMAGE_PREFIX }}/web:${{ github.ref_name }}
4545
```
4646
4747
## Changes

packages/web/.dockerignore

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
# Dependencies
1+
# Dependencies (these will be installed via package.json)
22
node_modules
33
npm-debug.log*
44
yarn-debug.log*
55
yarn-error.log*
66

7-
# Development files
8-
src
9-
public
10-
*.md
7+
# Environment files (should be passed as build args)
118
.env.local
129
.env.development.local
1310
.env.test.local
1411
.env.production.local
1512

16-
# Build tools
17-
vite.config.ts
18-
tsconfig.json
19-
tsconfig.app.json
20-
tsconfig.node.json
21-
2213
# IDE and editor files
2314
.vscode
2415
.idea
@@ -38,7 +29,10 @@ Thumbs.db
3829
.git
3930
.gitignore
4031

41-
# Misc
42-
*.log
32+
# Development artifacts
4333
coverage
4434
.nyc_output
35+
dist
36+
37+
# Documentation (not needed for build)
38+
README.md

packages/web/Dockerfile

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
# Multi-stage build for production
1+
# Build stage
22
FROM node:20-alpine AS builder
33

4+
# Install security updates
5+
RUN apk update && apk upgrade && apk add --no-cache dumb-init
6+
7+
# Create app user for security
8+
RUN addgroup -g 1001 -S nodejs && \
9+
adduser -S nextjs -u 1001
10+
411
# Set working directory
512
WORKDIR /app
613

7-
# Copy package files
14+
# Copy package files for dependency caching
815
COPY package*.json ./
916

10-
# Install dependencies
11-
RUN npm ci --only=production
17+
# Install ALL dependencies (including dev deps for TypeScript compilation)
18+
RUN npm ci --include=dev && npm cache clean --force
1219

1320
# Copy source code
14-
COPY . .
21+
COPY --chown=nextjs:nodejs . .
1522

1623
# Build arguments for environment variables
1724
ARG VITE_BASE_API_URL
@@ -21,20 +28,43 @@ ENV VITE_BASE_API_URL=$VITE_BASE_API_URL
2128
RUN npm run build
2229

2330
# Production stage
24-
FROM nginx:alpine
31+
FROM nginx:1.25-alpine AS runtime
32+
33+
# Install security updates and curl for health checks
34+
RUN apk update && apk upgrade && \
35+
apk add --no-cache curl dumb-init && \
36+
rm -rf /var/cache/apk/*
37+
38+
# Create non-root user
39+
RUN addgroup -g 1001 -S nginx-app && \
40+
adduser -S nginx-app -u 1001 -G nginx-app
2541

2642
# Copy built files from builder stage
27-
COPY --from=builder /app/dist /usr/share/nginx/html
43+
COPY --from=builder --chown=nginx-app:nginx-app /app/dist /usr/share/nginx/html
2844

2945
# Copy nginx configuration
30-
COPY nginx.conf /etc/nginx/conf.d/default.conf
46+
COPY --chown=nginx-app:nginx-app nginx.conf /etc/nginx/conf.d/default.conf
3147

32-
# Expose port 80
33-
EXPOSE 80
48+
# Set proper permissions
49+
RUN chown -R nginx-app:nginx-app /usr/share/nginx/html && \
50+
chown -R nginx-app:nginx-app /var/cache/nginx && \
51+
chown -R nginx-app:nginx-app /var/log/nginx && \
52+
chown -R nginx-app:nginx-app /etc/nginx/conf.d && \
53+
touch /var/run/nginx.pid && \
54+
chown -R nginx-app:nginx-app /var/run/nginx.pid
55+
56+
# Switch to non-root user
57+
USER nginx-app
58+
59+
# Expose port 8080 (non-privileged port)
60+
EXPOSE 8080
3461

3562
# Health check
3663
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
37-
CMD curl -f http://localhost/ || exit 1
64+
CMD curl -f http://localhost:8080/health || curl -f http://localhost:8080/ || exit 1
65+
66+
# Use dumb-init to handle signals properly
67+
ENTRYPOINT ["dumb-init", "--"]
3868

3969
# Start nginx
4070
CMD ["nginx", "-g", "daemon off;"]

packages/web/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
server {
2-
listen 80;
2+
listen 8080;
33
server_name localhost;
44

55
root /usr/share/nginx/html;

0 commit comments

Comments
 (0)