FROM node:14.17.6-stretch-slim as BUILD_IMAGE
# python version in this container is 3.5.3
RUN useradd -ms /bin/bash mc

WORKDIR /home/mc
RUN apt update
# for testing with headless chrome browser
RUN apt install -y wget
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt install -y ./google-chrome-stable_current_amd64.deb

WORKDIR /home/mc/mc_frontend
COPY package.json .
# to get the version of the local CLI package, run: npm list @angular/cli | sed 's/[^0-9.]*//g' | sed -n 2p
RUN npm i -g @angular/cli
# this makes the analytics prompt during upcoming "npm install" disappear, so this can also run in CI
RUN ng analytics off
RUN npm install

# use multi-stage image to reduce Docker image size
FROM node:14.17.6-stretch-slim
WORKDIR /home/mc/mc_frontend
COPY --from=BUILD_IMAGE /home/mc/mc_frontend/node_modules node_modules
COPY . .
COPY ./config.xml ./www/config.xml
# workaround to fix the missing binding issue for node-sass
RUN npm rebuild node-sass
# initialize the version file, it will get updated later
RUN echo "export const version = '';" | tee src/version.ts
ENTRYPOINT ng build --prod app