-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathDockerfile
More file actions
52 lines (36 loc) · 1.44 KB
/
Dockerfile
File metadata and controls
52 lines (36 loc) · 1.44 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
FROM --platform=$BUILDPLATFORM node:21.6.2 AS builder
WORKDIR /src
# Enable corepack to use pnpm version from package.json packageManager field
RUN corepack enable
# Copy dependency files for better layer caching
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY packages/web/package.json packages/web/
# Install dependencies
RUN pnpm install --frozen-lockfile
# Copy source code
COPY . .
# Build application
RUN make build-bff build-web
# Remove devDependencies to reduce image size (only keep production dependencies)
RUN CI=true pnpm prune --prod
# Clean pnpm store cache to reduce image size
RUN pnpm store prune
FROM node:21.6.2-slim
# Set production environment
ENV NODE_ENV=production
# Create app directory and non-root user for security
WORKDIR /apps
RUN groupadd -r appuser && useradd -r -g appuser appuser
# Copy built artifacts from builder stage
COPY --from=builder --chown=appuser:appuser /src/dist/ ./dist/
COPY --from=builder --chown=appuser:appuser /src/node_modules/ ./node_modules/
COPY --from=builder --chown=appuser:appuser /src/public/ ./public/
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 3000
# Health check using the application's health_check endpoint
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/health_check', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})" || exit 1
# Start application
CMD ["node", "dist/main"]