# Use Node.js 20 Alpine for smaller image size FROM node:20-alpine AS base # Install system dependencies RUN apk add --no-cache \ libc6-compat \ openssl \ sqlite \ wget \ dumb-init # Set working directory WORKDIR /app # Install dependencies only when needed FROM base AS deps # Copy package files COPY package.json package-lock.json* ./ RUN npm ci --only=production --frozen-lockfile && npm cache clean --force # Rebuild the source code only when needed FROM base AS builder # Copy package files COPY package.json package-lock.json* ./ RUN npm ci --frozen-lockfile # Copy source code COPY . . # Generate Prisma client RUN npx prisma generate # Build the application RUN npm run build # Production image, copy all the files and run the app FROM base AS runner # Create a non-root user RUN addgroup --system --gid 1001 nodejs && \ adduser --system --uid 1001 remix # Copy built application COPY --from=builder --chown=remix:nodejs /app/build ./build COPY --from=builder --chown=remix:nodejs /app/public ./public COPY --from=builder --chown=remix:nodejs /app/package.json ./package.json COPY --from=builder --chown=remix:nodejs /app/prisma ./prisma COPY --from=builder --chown=remix:nodejs /app/scripts ./scripts # Copy production dependencies COPY --from=deps --chown=remix:nodejs /app/node_modules ./node_modules # Create necessary directories RUN mkdir -p /app/data /app/logs && \ chown -R remix:nodejs /app/data /app/logs # Create startup script COPY --chown=remix:nodejs <