rwadurian/backend/services/leaderboard-service/Dockerfile

73 lines
1.2 KiB
Docker

# Multi-stage build for production
FROM node:20-alpine AS builder
WORKDIR /app
# Install OpenSSL for Prisma
RUN apk add --no-cache openssl
# Copy package files
COPY package*.json ./
COPY prisma ./prisma/
# Install dependencies
RUN npm ci
# Generate Prisma client
RUN npx prisma generate
# Copy source code
COPY . .
# Build the application
RUN npm run build
# Production stage
FROM node:20-alpine AS production
WORKDIR /app
# Install OpenSSL for Prisma
RUN apk add --no-cache openssl
# Copy package files and install production dependencies
COPY package*.json ./
RUN npm ci --only=production
# Copy Prisma files and generate client
COPY prisma ./prisma/
RUN npx prisma generate
# Copy built application
COPY --from=builder /app/dist ./dist
# Expose port
EXPOSE 3000
# Start the application
CMD ["node", "dist/main"]
# Test stage
FROM node:20-alpine AS test
WORKDIR /app
# Install OpenSSL for Prisma
RUN apk add --no-cache openssl
# Copy package files
COPY package*.json ./
COPY prisma ./prisma/
# Install all dependencies (including devDependencies)
RUN npm ci
# Generate Prisma client
RUN npx prisma generate
# Copy source code
COPY . .
# Default command for tests
CMD ["npm", "test"]