48 lines
1.4 KiB
Docker
48 lines
1.4 KiB
Docker
# Stage 1: Build backend
|
|
FROM node:20-alpine AS backend-builder
|
|
WORKDIR /app/backend
|
|
COPY backend/package*.json ./
|
|
# Use inline NODE_ENV=development so devDeps (nest CLI) are installed
|
|
# but the global NODE_ENV stays production for the actual build
|
|
RUN NODE_ENV=development npm ci --legacy-peer-deps --include=dev
|
|
COPY backend/ .
|
|
RUN ./node_modules/.bin/nest build
|
|
|
|
# Stage 2: Build frontend
|
|
FROM node:20-alpine AS frontend-builder
|
|
WORKDIR /app/frontend
|
|
COPY frontend/package*.json ./
|
|
RUN NODE_ENV=development npm ci --legacy-peer-deps --include=dev
|
|
COPY frontend/ .
|
|
ENV NEXT_PUBLIC_API_URL=/api-backend
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
ENV NODE_ENV=production
|
|
RUN npm run build
|
|
|
|
# Stage 3: Runtime
|
|
FROM node:20-alpine AS runner
|
|
WORKDIR /app
|
|
|
|
# Install nginx
|
|
RUN apk add --no-cache nginx
|
|
|
|
# Copy backend build
|
|
COPY --from=backend-builder /app/backend/dist ./backend/dist
|
|
COPY --from=backend-builder /app/backend/node_modules ./backend/node_modules
|
|
COPY --from=backend-builder /app/backend/package.json ./backend/
|
|
|
|
# Copy frontend build (standalone mode)
|
|
COPY --from=frontend-builder /app/frontend/.next/standalone ./frontend/
|
|
COPY --from=frontend-builder /app/frontend/.next/static ./frontend/.next/static
|
|
COPY --from=frontend-builder /app/frontend/public ./frontend/public
|
|
|
|
# Nginx config
|
|
COPY nginx.conf /etc/nginx/nginx.conf
|
|
|
|
# Start script
|
|
COPY start.sh .
|
|
RUN chmod +x start.sh
|
|
|
|
EXPOSE 80
|
|
CMD ["./start.sh"]
|