# Typescript Build
FROM registry.odit.services/hub/library/node:19.0.1-alpine3.16 as build
ARG NPM_REGISTRY_URL=https://registry.npmjs.org
WORKDIR /app

COPY package.json ./
RUN npm config set registry $NPM_REGISTRY_URL && npm i -g pnpm@8.0.0
RUN mkdir /pnpm && pnpm config set store-dir /pnpm && pnpm i

COPY tsconfig.json ./
COPY src ./src
RUN pnpm run build \
    && rm -rf /app/node_modules \
    && pnpm i --production --prefer-offline

# final image
FROM registry.odit.services/hub/library/node:19.0.1-alpine3.16
WORKDIR /app
COPY --from=build /app/package.json /app/package.json
COPY --from=build /app/dist /app/dist
COPY --from=build /app/node_modules /app/node_modules
ENTRYPOINT ["node", "/app/dist/app.js"]