# ── Build stage ── FROM node:22-alpine AS builder WORKDIR /app # Build args needed by $env/static/public at build time ARG PUBLIC_SUPABASE_URL ARG PUBLIC_SUPABASE_ANON_KEY # Copy package files first for better layer caching COPY package*.json ./ # Install all dependencies (including dev) needed for the build RUN npm ci # Copy source files COPY . . # Build the SvelteKit application RUN npm run build # ── Production dependencies stage ── FROM node:22-alpine AS deps WORKDIR /app COPY package*.json ./ # Install only production dependencies RUN npm ci --omit=dev # ── Runtime stage ── FROM node:22-alpine WORKDIR /app # Copy built application and production deps COPY --from=builder /app/build build/ COPY --from=deps /app/node_modules node_modules/ COPY package.json . # Expose port EXPOSE 3000 # Set environment defaults ENV NODE_ENV=production ENV PORT=3000 ENV HOST=0.0.0.0 # SvelteKit node adapter needs ORIGIN for CSRF protection # Override at runtime via docker-compose or -e flag ENV ORIGIN=http://localhost:3000 # Allow file uploads up to 10 MB ENV BODY_SIZE_LIMIT=10485760 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1 # Run the application CMD ["node", "build"]