FROM node:22-alpine AS build

WORKDIR /app
COPY .yarnrc.yml package.json yarn.lock ./
COPY .yarn/releases ./.yarn/releases
RUN --mount=type=secret,id=JIG_SOFTWARE_GITEA_DEPLOYMENT_TOKEN,env=JIG_SOFTWARE_GITEA_DEPLOYMENT_TOKEN yarn
COPY tsconfig.json tsconfig.build.json ./
COPY src ./src
RUN yarn build
RUN yarn workspaces focus --all --production

FROM node:22-alpine
ENV NODE_ENV=production
WORKDIR /app
COPY .yarnrc.yml package.json yarn.lock ./
COPY --from=build /app/dist ./dist
COPY --from=build /app/.yarn ./.yarn
COPY --from=build /app/.pnp.* ./

CMD ["yarn", "start"]

# Uncomment if healthcheck is needed
# HEALTHCHECK --interval=1m --timeout=10s --start-period=10s --retries=3 \
#   CMD [ "yarn", "health-check"]
