57 lines
2.0 KiB
Docker
57 lines
2.0 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-bookworm-slim AS runner
|
|
WORKDIR /app
|
|
|
|
# Install nginx and MongoDB
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
nginx \
|
|
gnupg \
|
|
curl \
|
|
&& curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor \
|
|
&& echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/debian bookworm/mongodb-org/7.0 main" > /etc/apt/sources.list.d/mongodb-org-7.0.list \
|
|
&& apt-get update && apt-get install -y --no-install-recommends mongodb-org \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& mkdir -p /data/db /run/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
|
|
# public dir may be empty — copy if exists
|
|
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"]
|