build(docker): add multi-stage production Dockerfile with health check

This commit is contained in:
2026-08-12 06:46:04 +03:30
parent d0cde07a1f
commit 3ca098b74d
+28 -4
View File
@@ -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 WORKDIR /app
COPY package*.json ./ 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 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"]