complete working on docker compose now need to deploy on k8s
This commit is contained in:
60
Dockerfile
60
Dockerfile
@@ -1,40 +1,36 @@
|
||||
# ── Stage 1: builder ───────────────────────────────────────────────
|
||||
FROM node:18-alpine AS builder
|
||||
# Use node-alpine but add necessary build tools
|
||||
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
|
||||
COPY package.json package-lock.json ./
|
||||
COPY prisma ./prisma/
|
||||
RUN npm ci --no-audit --no-fund
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
# 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
|
||||
|
||||
# ── Stage 2: production ────────────────────────────────────────────
|
||||
FROM node:18-alpine AS production
|
||||
ENV NODE_ENV=production
|
||||
RUN npm run build
|
||||
|
||||
# --- 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
|
||||
|
||||
# Non-root user
|
||||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
||||
# Copy everything from builder
|
||||
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
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD wget -qO- http://localhost:3000/health || exit 1
|
||||
|
||||
CMD ["node", "src/server.js"]
|
||||
# This is the command that the migration service or backend will use
|
||||
CMD ["npm", "start"]
|
||||
|
||||
Reference in New Issue
Block a user