managarten/mana-core-auth/Dockerfile
2025-11-25 18:56:35 +01:00

63 lines
1.5 KiB
Docker

# Build stage
FROM node:20-alpine AS builder
# Install pnpm
RUN npm install -g pnpm@9.15.0
WORKDIR /app
# Copy package files
COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml* ./
COPY mana-core-auth/package.json ./mana-core-auth/
# Install dependencies
RUN pnpm install --frozen-lockfile
# Copy source code
COPY mana-core-auth ./mana-core-auth
# Build the application
WORKDIR /app/mana-core-auth
RUN pnpm build
# Production stage
FROM node:20-alpine AS production
# Install pnpm
RUN npm install -g pnpm@9.15.0
WORKDIR /app
# Copy package files
COPY --from=builder /app/package.json /app/pnpm-lock.yaml* /app/pnpm-workspace.yaml* ./
COPY --from=builder /app/mana-core-auth/package.json ./mana-core-auth/
# Install production dependencies only
RUN pnpm install --prod --frozen-lockfile
# Copy built application
COPY --from=builder /app/mana-core-auth/dist ./mana-core-auth/dist
COPY --from=builder /app/mana-core-auth/src/db ./mana-core-auth/src/db
# Set working directory to the app
WORKDIR /app/mana-core-auth
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nestjs -u 1001
# Change ownership
RUN chown -R nestjs:nodejs /app
# Switch to non-root user
USER nestjs
# Expose port
EXPOSE 3001
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD node -e "require('http').get('http://localhost:3001/api/v1/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# Start the application
CMD ["node", "dist/main.js"]