Skip to content

Commit 2477967

Browse files
committed
Fix Dockerfile to work with npm workspaces
- Use single deps stage to install all workspace dependencies - Copy node_modules from deps stage to build stages - Fixes npm ci error in GitHub Actions build
1 parent 691c1cc commit 2477967

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

Dockerfile

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,69 @@
1-
# Stage 1: Build frontend
2-
FROM node:20-alpine AS frontend-build
1+
# Stage 1: Install dependencies
2+
FROM node:20-alpine AS deps
3+
4+
WORKDIR /app
35

4-
WORKDIR /app/frontend
6+
# Copy workspace package files
7+
COPY package*.json ./
8+
COPY backend/package*.json ./backend/
9+
COPY frontend/package*.json ./frontend/
510

6-
COPY frontend/package*.json ./
11+
# Install all dependencies (workspaces)
712
RUN npm ci
813

9-
COPY frontend/ ./
10-
RUN npm run build
14+
# Stage 2: Build frontend
15+
FROM node:20-alpine AS frontend-build
16+
17+
WORKDIR /app
18+
19+
# Copy dependencies from deps stage
20+
COPY --from=deps /app/node_modules ./node_modules
21+
COPY --from=deps /app/frontend/node_modules ./frontend/node_modules
22+
23+
# Copy frontend source
24+
COPY frontend/ ./frontend/
25+
COPY package*.json ./
26+
27+
# Build frontend
28+
RUN npm run build:frontend
1129

12-
# Stage 2: Build backend
30+
# Stage 3: Build backend
1331
FROM node:20-alpine AS backend-build
1432

15-
WORKDIR /app/backend
33+
WORKDIR /app
1634

17-
COPY backend/package*.json ./
18-
RUN npm ci
35+
# Copy dependencies from deps stage
36+
COPY --from=deps /app/node_modules ./node_modules
37+
COPY --from=deps /app/backend/node_modules ./backend/node_modules
38+
39+
# Copy backend source
40+
COPY backend/ ./backend/
41+
COPY package*.json ./
1942

20-
COPY backend/ ./
21-
RUN npm run build
43+
# Build backend
44+
RUN npm run build:backend
2245

23-
# Stage 3: Production
46+
# Stage 4: Production
2447
FROM node:20-alpine
2548

2649
WORKDIR /app
2750

28-
# Install nginx
51+
# Install runtime dependencies
2952
RUN apk add --no-cache nginx supervisor
3053

31-
# Copy backend
54+
# Copy built backend
3255
COPY --from=backend-build /app/backend/dist ./backend/dist
3356
COPY --from=backend-build /app/backend/node_modules ./backend/node_modules
3457
COPY --from=backend-build /app/backend/package.json ./backend/
3558

36-
# Copy frontend
59+
# Copy built frontend
3760
COPY --from=frontend-build /app/frontend/dist ./frontend/dist
3861

3962
# Copy nginx config
4063
COPY nginx/nginx.conf /etc/nginx/nginx.conf
4164

42-
# Copy application config
43-
COPY config ./config
65+
# Copy application config example
66+
COPY config/apps.yaml.example ./config/apps.yaml.example
4467

4568
# Create supervisor config
4669
RUN mkdir -p /var/log/supervisor

0 commit comments

Comments
 (0)