FROM node:26-alpine AS build

WORKDIR /app
ENV NPM_CONFIG_FETCH_RETRIES=5 \
    NPM_CONFIG_FETCH_RETRY_MINTIMEOUT=20000 \
    NPM_CONFIG_FETCH_RETRY_MAXTIMEOUT=120000 \
    NPM_CONFIG_AUDIT=false \
    NPM_CONFIG_FUND=false
COPY package.json package-lock.json ./
COPY apps/gateway/package.json apps/gateway/tsconfig.json apps/gateway/
RUN npm ci --workspace @fable/gateway

COPY apps/gateway/src apps/gateway/src
RUN npm --workspace @fable/gateway run build

FROM node:26-alpine

WORKDIR /app
ENV NODE_ENV=production \
    NPM_CONFIG_FETCH_RETRIES=5 \
    NPM_CONFIG_FETCH_RETRY_MINTIMEOUT=20000 \
    NPM_CONFIG_FETCH_RETRY_MAXTIMEOUT=120000 \
    NPM_CONFIG_AUDIT=false \
    NPM_CONFIG_FUND=false
COPY package.json package-lock.json ./
COPY apps/gateway/package.json apps/gateway/package.json
RUN npm ci --workspace @fable/gateway --omit=dev

COPY --from=build /app/apps/gateway/dist apps/gateway/dist
EXPOSE 3000
CMD ["node", "apps/gateway/dist/index.js"]
