# Stage 1: Dependencies FROM node:20-slim AS deps WORKDIR /app COPY package.json package-lock.json ./ RUN npm ci --ignore-scripts COPY prisma ./prisma/ RUN npx prisma generate # Stage 2: Build FROM node:20-slim AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . ENV NEXT_TELEMETRY_DISABLED=1 ENV NODE_ENV=production RUN npm run build # Stage 3: Runner FROM node:20-slim AS runner WORKDIR /app ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 ENV PORT=3000 RUN apt-get update && apt-get install -y --no-install-recommends \ openssl \ && rm -rf /var/lib/apt/lists/* && \ addgroup --system --gid 1001 nodejs && \ adduser --system --uid 1001 nextjs COPY --from=builder /app/public ./public COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/static ./.next/static COPY --from=builder /app/prisma ./prisma COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/scripts ./scripts # /app/storage holds the IPA files and tweak icons and is shared with the # worker. NOTE: a bind mount there shadows this directory, so the host path must # already be owned by uid/gid 1001 — the build-time chown does not reach it. RUN mkdir -p /app/tdlib-data/db /app/tdlib-data/files \ /app/storage/ipa /app/storage/icons /app/storage/tmp \ /tmp/ftstore && \ chown -R nextjs:nodejs /app /tmp/ftstore USER nextjs EXPOSE 3000 CMD ["sh", "-c", "node node_modules/prisma/build/index.js db push --skip-generate && node server.js"]