
# step 1, build
FROM mcd.jfrog.io/brep-docker/node:16-alpine3.15 AS build

#ENTRYPOINT ["bin/sh"]

ARG env
ENV env ${env}

#RUN echo ng serve --${env}

RUN mkdir /app
WORKDIR /app

COPY .npmrc /
#only copy package,json so that install step is cached
COPY .npmrc bref-main/package*.json ./

#install packages
RUN npm i --force

#delete npmrc from image
RUN rm -f .npmrc

#copy rest of files
COPY bref-main /app

#add ng command to path
ENV PATH "/app/node_modules/.bin:${PATH}"

#docker image build will fail if tests fail
RUN ng test

RUN echo ng build --${env}

# generate build
RUN ng build --prod

# create server

FROM mcd.jfrog.io/brep-docker/nginx:1.23.1

RUN apt-get update && apt install -y nginx-extras

COPY nginx_server.config /etc/nginx/nginx.conf

COPY nginx.conf /etc/nginx/conf.d/default.conf

# copying build of app

COPY --from=build /app/dist/bref-main /usr/share/nginx/html

# copying coverage report for sonar qube

COPY --from=build /app/coverage/lcov.info /etc/lcov.info

EXPOSE 80

