# Build stage FROM node:18-alpine AS build # Set build arguments ARG NODE_ENV=production ENV NODE_ENV=${NODE_ENV} WORKDIR /app # Copy package files and install dependencies COPY package*.json ./ RUN npm ci --no-audit --no-fund # Copy source code COPY . . # Build the application RUN npm run build # Production stage FROM node:18-alpine WORKDIR /app # Install wget for health check and other utilities RUN apk --no-cache add wget curl # Create a non-root user RUN addgroup -S appgroup && adduser -S appuser -G appgroup # Copy only production dependencies COPY package*.json ./ RUN npm ci --only=production --no-audit --no-fund # Copy built application from build stage COPY --from=build /app/dist ./dist COPY --from=build /app/server.cjs ./ COPY --from=build /app/api ./api # Set environment variables ENV NODE_ENV=production ENV PORT=3001 # Create a directory for environment files RUN mkdir -p /app/config # Note: Environment variables should be passed at runtime # Example: docker run -e GEMINI_API_KEY=your_key -e DATABASE_URL=your_url ... # Expose the port EXPOSE 3001 # Add health check HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3001/health || exit 1 # Switch to non-root user USER appuser # Start the server CMD ["node", "server.cjs"]