1
|
#src: https://mherman.org/blog/dockerizing-an-angular-app/
|
2
|
#############
|
3
|
### build ###
|
4
|
#############
|
5
|
|
6
|
# base image
|
7
|
FROM node:12.2.0 as build
|
8
|
|
9
|
# install chrome for protractor tests
|
10
|
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
|
11
|
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
|
12
|
RUN apt-get update && apt-get install -yq google-chrome-stable
|
13
|
|
14
|
# set working directory
|
15
|
WORKDIR /app
|
16
|
|
17
|
# add `/app/node_modules/.bin` to $PATH
|
18
|
ENV PATH /app/node_modules/.bin:$PATH
|
19
|
|
20
|
# install and cache app dependencies
|
21
|
COPY package.json /app/package.json
|
22
|
RUN npm install
|
23
|
RUN npm install -g @angular/cli@8.3.8
|
24
|
|
25
|
# add app
|
26
|
COPY . /app
|
27
|
|
28
|
# run tests - COMMENTED, later
|
29
|
#RUN ng test --watch=false
|
30
|
#RUN ng e2e --port 4202
|
31
|
|
32
|
# generate build
|
33
|
RUN ng build --output-path=dist
|
34
|
|
35
|
############
|
36
|
### prod ###
|
37
|
############
|
38
|
|
39
|
# base image
|
40
|
FROM nginx:1.16.0-alpine
|
41
|
|
42
|
# copy nginx configuration
|
43
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
44
|
|
45
|
# copy artifact build from the 'build environment'
|
46
|
COPY --from=build /app/dist /usr/share/nginx/html
|
47
|
|
48
|
# expose port 80
|
49
|
EXPOSE 80
|
50
|
|
51
|
# run nginx
|
52
|
CMD ["nginx", "-g", "daemon off;"]
|