FROM node:lts-alpine AS builder

WORKDIR /app

COPY package.json yarn.lock .yarnrc.yml ./
COPY .yarn ./.yarn

RUN yarn install --immutable
COPY . .

ARG COMMIT_SHA=unknown
ARG API_BASE_URL

ENV COMMIT_SHA=$COMMIT_SHA \
    API_BASE_URL=$API_BASE_URL

RUN yarn generate

FROM nginx:stable-alpine

COPY --from=builder /app/.output/public /usr/share/nginx/html

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]