# Version: 0.1.0
FROM node:22-alpine AS build
WORKDIR /app
COPY package.json ./
COPY apps/api/package.json apps/api/
COPY apps/editor/package.json apps/editor/
RUN npm install --workspaces --include-workspace-root
COPY tsconfig.base.json ./
COPY apps ./apps
RUN npm run build -w apps/editor && npm run build -w apps/api

FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY package.json ./
COPY apps/api/package.json apps/api/
RUN npm install --omit=dev -w apps/api --include-workspace-root=false && npm cache clean --force
COPY --from=build /app/apps/api/dist apps/api/dist
COPY --from=build /app/apps/api/public apps/api/public
COPY apps/api/src/migrations apps/api/dist/migrations
EXPOSE 3000
CMD ["node", "apps/api/dist/index.js"]
