FROM 086679231553.dkr.ecr.us-east-1.amazonaws.com/docker-parent-images:node24 AS base
WORKDIR /var/app
COPY package.json yarn.lock ./

FROM base AS dev
RUN --mount=type=secret,id=github_npm_token,required=true \
    GITHUB_NPM_TOKEN=$(cat /run/secrets/github_npm_token) yarn --frozen-lockfile
COPY src ./src
CMD ["yarn", "start:dev"]

FROM base AS test
RUN --mount=type=secret,id=github_npm_token,required=true \
    GITHUB_NPM_TOKEN=$(cat /run/secrets/github_npm_token) yarn --frozen-lockfile
COPY src ./src
CMD ["yarn", "test"]

FROM base AS build
RUN --mount=type=secret,id=github_npm_token,required=true \
    GITHUB_NPM_TOKEN=$(cat /run/secrets/github_npm_token) yarn --frozen-lockfile --production=false
COPY src ./src
RUN --mount=type=secret,id=github_npm_token,required=true \
    GITHUB_NPM_TOKEN=$(cat /run/secrets/github_npm_token) yarn build

FROM base AS deploy
COPY --from=build --chown=node:node /var/app/node_modules ./node_modules
COPY --from=build --chown=node:node /var/app/build ./build
USER node
CMD ["node", "build/index.js"]
