ARG WS_VERSION=dev FROM node:14.16-alpine3.12 as base RUN apk update && apk add --virtual build-dependencies \ git \ python2 \ g++ \ make \ && rm -rf /var/cache/apk/* # Create vlapipe group # and create vlapipe in vlapipe group RUN addgroup --gid 6000 vlapipe && \ adduser --disabled-password --gecos "" --ingroup vlapipe --uid 6000 vlapipe FROM base as dev # set container working directory to /code WORKDIR /code/ # copy web app from host to container COPY ./apps/web ./ # Disable Angular Analytics prompt ENV NG_CLI_ANALYTICS=false # install node_modules RUN npm install # start Angular development server CMD [ "./node_modules/.bin/ng", "serve", "--host", "0.0.0.0" ] FROM base as base-build # Requires build-arg $env # Build arg that sets environment; sets to "dev" if no build arg is given ARG env=dev ENV ENV=${env} # Requires build-arg WS_VERSION # Build arg that sets Workspaces Version; defaults to "dev" if no build arg is given ENV NG_APP_WS_VERSION=${WS_VERSION} # Switch to vlapipe USER vlapipe # Create ~/app RUN mkdir -p /home/vlapipe/app # Set NPM environment variables for vlapipe ENV NPM_CONFIG_PREFIX=/home/vlapipe/.npm-global ENV PATH=$PATH:/home/vlapipe/.npm-global/bin # Change working directory to /home/vlapipe/app WORKDIR /home/vlapipe/app # Copy package.json to /home/vlapipe/app in the image # set ownership of content to vlapipe and the vlapipe group COPY --chown=vlapipe:vlapipe /apps/web/package-lock.json . COPY --chown=vlapipe:vlapipe /apps/web/package.json . ENV NG_CLI_ANALYTICS=false # Install node modules RUN npm install # Switch to root USER root # remove build packages RUN apk del build-dependencies # Switch to vlapipe USER vlapipe # Copy web directory to /home/vlapipe/app in the image # set ownership of content to vlapipe and the vlapipe group COPY --chown=vlapipe:vlapipe ./apps/web ./ # Build the angular app RUN ./node_modules/.bin/ng build --configuration=${ENV} --output-path=dist # ## NGINX section of multi-stage image # # Use nginx base image FROM nginx:1.19.7-alpine as prod # Copy WS nginx config from base-build stage COPY --from=base-build /home/vlapipe/app/ws-nginx.conf.template /etc/nginx/templates/ # Remove default nginx config RUN rm /etc/nginx/conf.d/default.conf # Copy Angular build from base-build stage COPY --from=base-build /home/vlapipe/app/dist /usr/share/nginx/html