## STAGE 1: Build ##
FROM node:16-alpine as builder
# arg and label to target images for cleanup
ARG APP_NAME=acrconnect-federated-network-ui
ARG CICD_BUILD_ID=0
LABEL build.intermediate=${APP_NAME}${CICD_BUILD_ID}
COPY package.json package-lock.json ./
# Storing node modules on a separate layer will prevent unnecessary npm installs at each build
RUN npm ci && mkdir /ng-app && mv ./node_modules /ng-app
WORKDIR /ng-app
COPY . .
# Build the angular app in production mode and store the artifacts in dist folder
RUN npm run dist

## STAGE 2: Setup ##
FROM nginx:1.19.6-alpine
# arg and label to target images for cleanup
ARG APP_NAME=acrconnect-federated-network-ui
ARG CICD_BUILD_ID=0
LABEL build.intermediate=${APP_NAME}${CICD_BUILD_ID}
# Copy our default nginx config
COPY nginx/default.conf /etc/nginx/conf.d/
# Remove default nginx website
RUN rm -rf /usr/share/nginx/html/*
# From ‘builder’ stage copy over the artifacts in dist folder to default nginx public folder
COPY --from=builder /ng-app/dist /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
