#build angular base build containeer
FROM node:12-alpine AS build_base
WORKDIR /usr/src/app
RUN apk add --no-cache git


#build project specific container containing modules
FROM build_base as build_base_project
COPY ./package.json /usr/src/app/package.json
COPY ./package-lock.json /usr/src/app/package-lock.json

RUN npm install

# create build container and build ng project
FROM build_base_project as build
ARG CI_COMMIT_BRANCH
ARG CI_COMMIT_TAG
ARG CI_COMMIT_SHA
ENV CI_COMMIT_BRANCH=$CI_COMMIT_BRANCH
ENV CI_COMMIT_TAG=$CI_COMMIT_TAG
ENV CI_COMMIT_SHA=$CI_COMMIT_SHA
COPY ./ /usr/src/app
RUN npm run build-prod

#build nginx container
FROM nginx

RUN rm /etc/nginx/conf.d/default.conf


RUN chgrp -R root /var/cache/nginx /var/run /var/log/nginx && \
    chmod -R 770 /var/cache/nginx /var/run /var/log/nginx

USER root

COPY --from=build /usr/src/app/dist/uno /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/nginx.conf

EXPOSE 80


