Skip to content
Snippets Groups Projects
Commit c9548873 authored by rhenck's avatar rhenck
Browse files

Improve multistage building of docker images

This includes running unit tests when building.
The docker compose setup uses only the first stage of the image building 
process, which uses node as server. The next step, for production, uses 
nginx as server software.
parent a5469739
No related branches found
No related tags found
No related merge requests found
FROM node:14.8
FROM node:13.14.0 as dev
# install chrome for protractor tests
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
......@@ -18,6 +18,20 @@ RUN npx webdriver-manager update
COPY . /app
RUN ng test --watch=false
RUN ng build --output-path=dist
EXPOSE 4200
CMD ng serve --disableHostCheck --host 0.0.0.0
# ===========================================
FROM nginx:1.19.1-alpine as prod
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
FROM node:13.14.0 as build
# install chrome for protractor tests
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update && apt-get install -yq google-chrome-stable
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /app/package.json
RUN npm install
# install webdriver for browser testing
RUN npm i --prefix=./node_modules/protractor --save webdriver-manager@latest
RUN npx webdriver-manager update
COPY . /app
RUN ng test --watch=false
RUN ng e2e --webdriver-update=false --port 4202
RUN ng build --output-path=dist
# ===========================================
FROM nginx:1.19.1-alpine
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
......@@ -6,6 +6,7 @@ services:
build:
context: ../
dockerfile: docker/Dockerfile
target: dev
container_name: testcenter-frontend-dev
volumes:
- ../:/app
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment