Files
wedding/Dockerfile
2026-02-12 20:04:53 +07:00

61 lines
1.2 KiB
Docker

# Multi-stage build for production
FROM node:18-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci
# Copy source code
COPY . .
# Build the client
RUN npm run build
# Production stage
FROM node:18-alpine AS production
# Install system dependencies
RUN apk add --no-cache \
dumb-init \
tini
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install only production dependencies
RUN npm ci --only=production && npm cache clean --force
# Copy built client from builder stage
COPY --from=builder /app/client/dist ./client/dist
# Copy server code
COPY server ./server
# Copy database directory
COPY data ./data
# Create non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nodejs -u 1001
# Change ownership of directories
RUN chown -R nodejs:nodejs /app
# Switch to non-root user
USER nodejs
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/api/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"
# Start the application
CMD ["node", "server/index.js"]