69 lines
1.5 KiB
Docker
69 lines
1.5 KiB
Docker
# Multi-stage build for production optimization
|
|
FROM node:18-alpine AS builder
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
COPY tsconfig.json ./
|
|
|
|
# Install all dependencies (including devDependencies for build)
|
|
RUN npm ci && npm cache clean --force
|
|
|
|
# Copy source code
|
|
COPY src/ ./src/
|
|
COPY .env.example ./
|
|
|
|
# Build the application (using Linux-compatible build command)
|
|
RUN npm run build:linux
|
|
|
|
# Production stage
|
|
FROM node:18-alpine AS production
|
|
|
|
# Create app directory
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
|
|
# Install only production dependencies
|
|
RUN npm ci --only=production && npm cache clean --force
|
|
|
|
# Copy built application from builder stage
|
|
COPY --from=builder /app/dist ./dist
|
|
COPY --from=builder /app/.env.example ./.env.example
|
|
|
|
# Copy database migrations
|
|
COPY src/database/migrations/ ./dist/database/migrations/
|
|
|
|
# Copy locales
|
|
COPY src/locales/ ./dist/locales/
|
|
|
|
# Copy scripts
|
|
COPY scripts/startup.sh ./startup.sh
|
|
RUN chmod +x ./startup.sh
|
|
|
|
# Create directories
|
|
RUN mkdir -p uploads logs
|
|
|
|
# Create non-root user for security
|
|
RUN addgroup -g 1001 -S nodejs
|
|
RUN adduser -S nodeuser -u 1001
|
|
|
|
# Change ownership of the app directory
|
|
RUN chown -R nodeuser:nodejs /app
|
|
|
|
# Switch to non-root user
|
|
USER nodeuser
|
|
|
|
# Expose port
|
|
EXPOSE 3000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
|
|
|
|
# Start the application with migration script
|
|
CMD ["./startup.sh"]
|