complete working on docker compose now need to deploy on k8s

This commit is contained in:
tusuii
2026-02-20 00:45:05 +05:30
parent 173293efaa
commit 00f9566940

View File

@@ -1,40 +1,36 @@
# ── Stage 1: builder ─────────────────────────────────────────────── # Use node-alpine but add necessary build tools
FROM node:18-alpine AS builder FROM node:20-alpine AS builder
# 1. Install openssl and libc6-compat (required for Prisma on Alpine)
RUN apk add --no-cache openssl libc6-compat
WORKDIR /app WORKDIR /app
COPY package.json package-lock.json ./
COPY prisma ./prisma/ COPY package*.json ./
RUN npm ci --no-audit --no-fund
# 2. Install dependencies (make sure prisma is in your package.json)
RUN npm ci
COPY . .
# 3. Generate Prisma Client during build time
# This bakes the engine into the image so 'npx' doesn't try to download it later
RUN npx prisma generate RUN npx prisma generate
# ── Stage 2: production ──────────────────────────────────────────── RUN npm run build
FROM node:18-alpine AS production
ENV NODE_ENV=production # --- Runner Stage ---
FROM node:20-alpine AS runner
# 4. Must also install openssl in the runner stage!
RUN apk add --no-cache openssl libc6-compat
WORKDIR /app WORKDIR /app
# Non-root user # Copy everything from builder
RUN addgroup -S appgroup && adduser -S appuser -G appgroup COPY --from=builder /app /app
# Production-only npm dependencies
COPY package.json package-lock.json ./
RUN npm ci --omit=dev --no-audit --no-fund
# Copy generated Prisma client from builder
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
# Copy prisma CLI so init container can run 'prisma migrate deploy'
COPY --from=builder /app/node_modules/prisma ./node_modules/prisma
COPY --from=builder /app/node_modules/.bin/prisma ./node_modules/.bin/prisma
# Copy app source + Prisma schema/migrations
COPY src ./src
COPY prisma ./prisma
# Temp uploads dir (emptyDir volume mounted here in k8s)
RUN mkdir -p uploads
USER appuser
EXPOSE 3000 EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ # This is the command that the migration service or backend will use
CMD wget -qO- http://localhost:3000/health || exit 1 CMD ["npm", "start"]
CMD ["node", "src/server.js"]