From 3ca098b74dae4f8fa80de4d4757482768c696915 Mon Sep 17 00:00:00 2001 From: Kavehhn174 Date: Wed, 12 Aug 2026 06:46:04 +0330 Subject: [PATCH] build(docker): add multi-stage production Dockerfile with health check --- Dockerfile | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index ef670ab..a3d6e04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,37 @@ -FROM node:22-alpine +# Multi-stage production Dockerfile for gameno-api + +# ------------------------------------------------------------------------------ +# Stage 1: Install production dependencies +# ------------------------------------------------------------------------------ +FROM node:22-alpine AS dependencies WORKDIR /app COPY package*.json ./ -RUN npm install +RUN npm ci --omit=dev && npm cache clean --force -COPY . . +# ------------------------------------------------------------------------------ +# Stage 2: Production runtime image +# ------------------------------------------------------------------------------ +FROM node:22-alpine AS production + +WORKDIR /app + +ENV NODE_ENV=production \ + PORT=3000 + +# Copy installed production dependencies and application code with proper ownership +COPY --chown=node:node --from=dependencies /app/node_modules ./node_modules +COPY --chown=node:node . . + +# Run as non-root user +USER node EXPOSE 3000 -CMD ["npm", "start"] +# Healthcheck targeting the API health endpoint +HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ + CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1 + +CMD ["node", "app.js"]