6e9e79d0f9bc01fb48edb5ec03074f2cd26a3f89
[osm/devops.git] / docker / NG-UI / Dockerfile
1 #######################################################################################
2 # Copyright ETSI Contributors and Others.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #######################################################################################
17
18 FROM ubuntu:20.04 as INSTALL
19
20 ARG APT_PROXY
21 RUN if [ ! -z $APT_PROXY ] ; then \
22     echo "Acquire::http::Proxy \"$APT_PROXY\";" > /etc/apt/apt.conf.d/proxy.conf ;\
23     echo "Acquire::https::Proxy \"$APT_PROXY\";" >> /etc/apt/apt.conf.d/proxy.conf ;\
24     fi
25
26 RUN DEBIAN_FRONTEND=noninteractive apt-get --yes update && \
27     DEBIAN_FRONTEND=noninteractive apt-get --yes install \
28     apt-transport-https=2.0.* \
29     curl=7.68.* \
30     gnupg2=2.2.* \
31     nginx=1.18.* \
32     software-properties-common=0.99.* \
33     xz-utils=5.2.*
34
35 RUN curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \
36     echo "deb https://deb.nodesource.com/node_10.x focal main" | tee -a /etc/apt/sources.list.d/nodesource.list && \
37     DEBIAN_FRONTEND=noninteractive apt-get update && \
38     DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs=10.24.*
39
40 ARG OSM_NGUI_URL
41
42 RUN curl $OSM_NGUI_URL -o osm_ngui.deb
43 RUN dpkg -i ./osm_ngui.deb
44
45 WORKDIR /usr/share/osm-ngui
46 RUN npm install
47
48 # Building app.
49 RUN npm run build
50
51 #######################################################################################
52 FROM ubuntu:20.04 AS FINAL
53
54 ARG APT_PROXY
55 RUN if [ ! -z $APT_PROXY ] ; then \
56     echo "Acquire::http::Proxy \"$APT_PROXY\";" > /etc/apt/apt.conf.d/proxy.conf ;\
57     echo "Acquire::https::Proxy \"$APT_PROXY\";" >> /etc/apt/apt.conf.d/proxy.conf ;\
58     fi
59
60 RUN DEBIAN_FRONTEND=noninteractive apt-get --yes update && \
61     DEBIAN_FRONTEND=noninteractive apt-get --yes install \
62     nginx=1.18.* && \
63     rm -rf /var/lib/apt/lists/*
64
65 # Removing the Nginx default page.
66 RUN rm -rf /usr/share/nginx/html/*
67
68 # Creating the user for the app
69 RUN groupadd -g 1000 appuser && \
70     useradd -u 1000 -g 1000 -d /usr appuser && \
71     chown -R appuser:appuser /usr /var/lib/nginx /var/log/nginx /etc/nginx /run
72
73 # Changing the security context
74 USER appuser
75
76 # Copying Nginx configuration
77 COPY --from=INSTALL /usr/share/osm-ngui/nginx/nginx.conf /etc/nginx/sites-available/default
78
79 # Copying angular build to Nginx default page.
80 COPY --from=INSTALL /usr/share/osm-ngui/dist/osm /usr/share/nginx/html
81
82 EXPOSE 80
83
84 HEALTHCHECK --start-period=130s --interval=10s --timeout=5s --retries=12 \
85   CMD curl --silent --fail localhost:80 || exit 1
86
87 # Starting server.
88 CMD ["nginx", "-g", "daemon off;"]