-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (44 loc) · 1.44 KB
/
Dockerfile
File metadata and controls
64 lines (44 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
53
54
55
56
57
58
59
60
61
62
63
64
# Multi-stage build for coding interview platform
# Stage 1: Build frontend
FROM node:20-alpine AS frontend-builder
WORKDIR /app/frontend
# Copy frontend package files
COPY frontend/package*.json ./
# Install frontend dependencies (including dev dependencies for build)
RUN npm ci
# Copy frontend source
COPY frontend/ ./
# Build frontend for production
RUN npm run build
# Stage 2: Build backend
FROM node:20-alpine AS backend-builder
WORKDIR /app/backend
# Copy backend package files
COPY backend/package*.json ./
COPY backend/tsconfig.json ./
# Install backend dependencies (including dev dependencies for build)
RUN npm ci
# Copy backend source
COPY backend/src ./src
# Build backend TypeScript
RUN npm run build
# Stage 3: Production image
FROM node:20-alpine
WORKDIR /app
# Install production dependencies for backend
COPY backend/package*.json ./
RUN npm ci --only=production && npm cache clean --force
# Copy built backend from builder
COPY --from=backend-builder /app/backend/dist ./dist
# Copy built frontend from builder
COPY --from=frontend-builder /app/frontend/dist ./frontend/dist
# Set environment to production
ENV NODE_ENV=production
ENV PORT=3000
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# Start the application
CMD ["node", "dist/server.js"]