- Create Dockerfile with multi-stage build using node:22-alpine - Run as non-root 'nodejs' user for security - Add HEALTHCHECK for container orchestration - Create docker-compose.yml with taskplaner_data named volume - Add .dockerignore to optimize build context
55 lines
1.2 KiB
Docker
55 lines
1.2 KiB
Docker
# Build stage
|
|
FROM node:22-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
|
|
# Install dependencies
|
|
RUN npm ci
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN npm run build
|
|
|
|
# Prune dev dependencies
|
|
RUN npm prune --production
|
|
|
|
# Production stage
|
|
FROM node:22-alpine AS production
|
|
|
|
WORKDIR /app
|
|
|
|
# Create non-root user
|
|
RUN addgroup -g 1001 -S nodejs && \
|
|
adduser -S nodejs -u 1001
|
|
|
|
# Copy built application from builder
|
|
COPY --from=builder --chown=nodejs:nodejs /app/build ./build
|
|
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
|
|
COPY --from=builder --chown=nodejs:nodejs /app/package.json ./
|
|
|
|
# Create data directory with proper ownership
|
|
RUN mkdir -p /app/data && chown -R nodejs:nodejs /app/data
|
|
|
|
# Switch to non-root user
|
|
USER nodejs
|
|
|
|
# Set environment variables
|
|
ENV NODE_ENV=production
|
|
ENV TASKPLANER_DATA_DIR=/app/data
|
|
ENV PORT=3000
|
|
|
|
# Expose port
|
|
EXPOSE 3000
|
|
|
|
# Health check (endpoint created in Plan 02)
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
|
|
|
|
# Start the application
|
|
CMD ["node", "build/index.js"]
|