SEO_iamge_renamer_starting_.../Dockerfile
DustyWalker 451243b1af feat: add Dockerfile - multi-stage Alpine build optimized for production
Multi-stage Dockerfile with:
- Alpine Linux base for minimal size (<300MB target)
- Separate stages for builder, production, worker, and development
- Security-focused with non-root user execution
- VIPS library integration for image processing
- pnpm package manager support
- Health checks and proper signal handling with tini
- Optimized layer caching and dependency installation
- Production and development configurations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-05 16:48:20 +02:00

126 lines
No EOL
2.5 KiB
Docker

# Multi-stage Dockerfile for AI Bulk Image Renamer
# Target: Alpine Linux for minimal size (<300MB)
# Build stage
FROM node:18-alpine AS builder
# Install build dependencies
RUN apk add --no-cache \
python3 \
make \
g++ \
libc6-compat \
vips-dev
# Enable pnpm
RUN corepack enable pnpm
# Set working directory
WORKDIR /app
# Copy package files
COPY package.json pnpm-lock.yaml* ./
COPY packages/*/package.json ./packages/*/
# Install dependencies
RUN pnpm install --frozen-lockfile
# Copy source code
COPY . .
# Build all packages
RUN pnpm build
# Prune dev dependencies
RUN pnpm prune --prod
# Production stage
FROM node:18-alpine AS production
# Install runtime dependencies
RUN apk add --no-cache \
vips \
curl \
tini \
dumb-init \
&& addgroup -g 1001 -S nodejs \
&& adduser -S nodeuser -u 1001
# Enable pnpm
RUN corepack enable pnpm
# Set working directory
WORKDIR /app
# Copy package files and node_modules from builder
COPY --from=builder --chown=nodeuser:nodejs /app/package.json ./
COPY --from=builder --chown=nodeuser:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nodeuser:nodejs /app/packages ./packages
# Create necessary directories
RUN mkdir -p /app/logs /app/uploads /app/temp \
&& chown -R nodeuser:nodejs /app
# Switch to non-root user
USER nodeuser
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:3000/health || exit 1
# Expose port
EXPOSE 3000
# Use tini as PID 1
ENTRYPOINT ["/sbin/tini", "--"]
# Default command (can be overridden)
CMD ["pnpm", "start"]
# Worker stage (for background processing)
FROM production AS worker
# Override default command for worker
CMD ["pnpm", "start:worker"]
# Development stage
FROM node:18-alpine AS development
# Install development dependencies
RUN apk add --no-cache \
python3 \
make \
g++ \
libc6-compat \
vips-dev \
git \
curl
# Enable pnpm
RUN corepack enable pnpm
# Create user
RUN addgroup -g 1001 -S nodejs \
&& adduser -S nodeuser -u 1001
WORKDIR /app
# Copy package files
COPY package.json pnpm-lock.yaml* ./
COPY packages/*/package.json ./packages/*/
# Install all dependencies (including dev)
RUN pnpm install --frozen-lockfile
# Create necessary directories
RUN mkdir -p /app/logs /app/uploads /app/temp \
&& chown -R nodeuser:nodejs /app
# Switch to non-root user
USER nodeuser
# Expose port
EXPOSE 3000
# Start development server
CMD ["pnpm", "dev"]