From 451243b1af47adfd070e1889246337f54882558e Mon Sep 17 00:00:00 2001 From: DustyWalker Date: Tue, 5 Aug 2025 16:48:20 +0200 Subject: [PATCH] feat: add Dockerfile - multi-stage Alpine build optimized for production MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Dockerfile | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9942971 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,126 @@ +# 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"] \ No newline at end of file