FROM public.ecr.aws/docker/library/node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm i --legacy-peer-deps
COPY . .
# baseHref comes from angular.json (docker configuration = "/app/"). Do not pass an
# absolute --base-href here: it bakes a hostname into the bundle and forces a rebuild
# whenever the public URL changes.
# setup.sh / setup.bat build these apps with `ng build --configuration=docker` and
# nothing else. update-version.js is not on master (only on origin/dev and
# origin/development) and would be a no-op in the image regardless: it stamps
# environment.ts/prod/demo/uat/local/preprod, none of which the docker configuration
# uses, and writes ../b2g_digitall/config/app-version.json - a path outside this
# build context. The digitall backend reads that manifest from its OWN repo.
RUN npx ng build --configuration=docker

FROM public.ecr.aws/docker/library/nginx:alpine
COPY --from=build /app/dist/b2g-frontend/browser /usr/share/nginx/html
COPY docker/nginx-spa.conf /etc/nginx/conf.d/default.conf
# assets/env.js carries the runtime config that cannot live in environment.*.ts
# (those are compiled into the bundle). It is generated at start-up from
# MICROFE_HOST so one image serves every tier - see docker/spa-entrypoint.sh.
COPY docker/spa-entrypoint.sh /usr/local/bin/spa-entrypoint.sh
RUN chmod +x /usr/local/bin/spa-entrypoint.sh
ENTRYPOINT ["/usr/local/bin/spa-entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
EXPOSE 80
