FROM node:22-alpine AS build

WORKDIR /app

COPY package.json package-lock.json tsconfig.base.json ./
COPY apps ./apps
COPY packages ./packages
COPY registry ./registry
COPY scripts ./scripts
COPY server ./server

RUN npm ci
RUN npm run build

FROM node:22-alpine AS runtime

WORKDIR /app

ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV PORT=3333

COPY --from=build /app/server ./server
COPY --from=build /app/apps/catalog/dist ./apps/catalog/dist
COPY --from=build /app/registry ./registry
COPY runtime-seed ./runtime-seed

EXPOSE 3333

ENTRYPOINT ["node", "/app/server/runtime-entrypoint.mjs"]
CMD ["node", "server/catalog-server.mjs"]
