# Server-side image — NO npm/pnpm/network. Requires iran-bundle/ from scripts/bundle-for-iran.sh (run on Mac).
# Use full bookworm image (not slim): includes libssl.so.3 for Prisma; apt-get is blocked on Iran servers.
FROM docker.arvancloud.ir/library/node:20-bookworm AS runner
WORKDIR /app

ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
ENV NEXT_TELEMETRY_DISABLED=1
ENV PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING=1
ENV PRISMA_QUERY_ENGINE_LIBRARY=/app/prisma-binaries/libquery_engine-debian-openssl-3.0.x.so.node

RUN addgroup --system --gid 1001 nodejs && \
    adduser --system --uid 1001 nextjs

COPY iran-bundle/standalone ./
COPY iran-bundle/static ./.next/static
COPY iran-bundle/public ./public
COPY iran-bundle/prisma-binaries ./prisma-binaries
# Standalone ships a stub @prisma/client; replace with full Prisma runtime from the bundle.
COPY iran-bundle/node_modules /tmp/prisma-nm
RUN rm -rf ./node_modules/@prisma ./node_modules/.prisma && \
    cp -a /tmp/prisma-nm/.prisma ./node_modules/ && \
    cp -a /tmp/prisma-nm/@prisma ./node_modules/@prisma && \
    rm -rf /tmp/prisma-nm

RUN mkdir -p /app/public/uploads && chown -R nextjs:nodejs /app/public/uploads

USER nextjs
EXPOSE 3000
CMD ["node", "server.js"]
