# Build stage FROM node:23-alpine AS builder # Set working directory for the build stage WORKDIR /build # Copy package files COPY package*.json ./ # Install dependencies RUN npm install # Copy application files COPY . . # Runtime stage FROM node:23-alpine AS runtime # Create a non-root user RUN addgroup -S appgroup && adduser -S appuser -G appgroup # Set working directory for the application WORKDIR /home/appuser/app # Copy only the necessary files from the builder stage COPY --from=builder --chown=appuser:appgroup /build/package*.json ./ COPY --from=builder --chown=appuser:appgroup /build/main.js ./ COPY --from=builder --chown=appuser:appgroup /build/util.js ./ COPY --from=builder --chown=appuser:appgroup /build/worker.js ./ COPY --from=builder --chown=appuser:appgroup /build/node_modules ./node_modules # Create logs directory with correct permissions RUN mkdir -p logs && chown -R appuser:appgroup logs # Expose logs directory as a volume VOLUME ["/home/appuser/app/logs"] # Use an environment variable for thread count (default to 0 to use auto) ENV THREAD_COUNT=0 # Switch to non-root user USER appuser # Run the application - using JSON array format CMD ["sh", "-c", "node main.js ${THREAD_COUNT}"]