# Added by the Noite project on 2026-11-10 under the Apache License 2.0: production image of the Noite server for Dokploy, built from the repo root with only the server's dependencies, compiled to JavaScript, applying Prisma migrations on start.
FROM node:22.22.1-bookworm-slim AS build
RUN apt-get update && apt-get install -y --no-install-recommends openssl ca-certificates && rm -rf /var/lib/apt/lists/*
RUN npm install -g pnpm@11.1.3 && pnpm --version
ENV CI=1
WORKDIR /repo
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY patches ./patches
COPY apps/server ./apps/server
RUN pnpm --config.inject-workspace-packages=true --config.allow-unused-patches=true --config.strict-dep-builds=false \
    --filter @noite/server deploy /srv \
  && test ! -d /srv/node_modules/react-native
WORKDIR /srv
RUN ./node_modules/.bin/prisma generate \
  && ./node_modules/.bin/tsc -p tsconfig.build.json \
  && test -f dist/index.js

FROM node:22.22.1-bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends openssl ca-certificates && rm -rf /var/lib/apt/lists/*
ENV NODE_ENV=production PORT=8787
WORKDIR /app
COPY --from=build /srv/package.json ./package.json
COPY --from=build /srv/node_modules ./node_modules
COPY --from=build /srv/prisma ./prisma
COPY --from=build /srv/dist ./dist
USER node
EXPOSE 8787
HEALTHCHECK --interval=15s --timeout=5s --start-period=60s --retries=3 \
  CMD node -e "fetch('http://127.0.0.1:'+(process.env.PORT||8787)+'/health').then(r=>process.exit(r.ok?0:1),()=>process.exit(1))"
CMD ["sh", "-c", "node_modules/.bin/prisma migrate deploy && exec node --enable-source-maps dist/index.js"]
