|
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 |
3 | 5 |
|
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/ |
5 | 10 |
|
6 | | -COPY frontend/package*.json ./ |
| 11 | +# Install all dependencies (workspaces) |
7 | 12 | RUN npm ci |
8 | 13 |
|
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 |
11 | 29 |
|
12 | | -# Stage 2: Build backend |
| 30 | +# Stage 3: Build backend |
13 | 31 | FROM node:20-alpine AS backend-build |
14 | 32 |
|
15 | | -WORKDIR /app/backend |
| 33 | +WORKDIR /app |
16 | 34 |
|
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 ./ |
19 | 42 |
|
20 | | -COPY backend/ ./ |
21 | | -RUN npm run build |
| 43 | +# Build backend |
| 44 | +RUN npm run build:backend |
22 | 45 |
|
23 | | -# Stage 3: Production |
| 46 | +# Stage 4: Production |
24 | 47 | FROM node:20-alpine |
25 | 48 |
|
26 | 49 | WORKDIR /app |
27 | 50 |
|
28 | | -# Install nginx |
| 51 | +# Install runtime dependencies |
29 | 52 | RUN apk add --no-cache nginx supervisor |
30 | 53 |
|
31 | | -# Copy backend |
| 54 | +# Copy built backend |
32 | 55 | COPY --from=backend-build /app/backend/dist ./backend/dist |
33 | 56 | COPY --from=backend-build /app/backend/node_modules ./backend/node_modules |
34 | 57 | COPY --from=backend-build /app/backend/package.json ./backend/ |
35 | 58 |
|
36 | | -# Copy frontend |
| 59 | +# Copy built frontend |
37 | 60 | COPY --from=frontend-build /app/frontend/dist ./frontend/dist |
38 | 61 |
|
39 | 62 | # Copy nginx config |
40 | 63 | COPY nginx/nginx.conf /etc/nginx/nginx.conf |
41 | 64 |
|
42 | | -# Copy application config |
43 | | -COPY config ./config |
| 65 | +# Copy application config example |
| 66 | +COPY config/apps.yaml.example ./config/apps.yaml.example |
44 | 67 |
|
45 | 68 | # Create supervisor config |
46 | 69 | RUN mkdir -p /var/log/supervisor |
|
0 commit comments