8e9859765c0f6b4852f84489df154a5d633abc44
[osm/devops.git] / docker / NBI / 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:22.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     gcc=4:11.* \
29     python3=3.10.* \
30     python3-dev=3.10.* \
31     python3-pip=22.0.* \
32     curl=7.81.* \
33     && rm -rf /var/lib/apt/lists/*
34
35 #######################################################################################
36 # End of common preparation
37
38 ARG PYTHON3_OSM_COMMON_URL
39 ARG PYTHON3_OSM_IM_URL
40 ARG PYTHON3_OSM_NBI_URL
41
42 RUN curl $PYTHON3_OSM_COMMON_URL -o osm_common.deb
43 RUN dpkg -i ./osm_common.deb
44
45 RUN curl $PYTHON3_OSM_IM_URL -o osm_im.deb
46 RUN dpkg -i ./osm_im.deb
47
48 RUN curl $PYTHON3_OSM_NBI_URL -o osm_nbi.deb
49 RUN dpkg -i ./osm_nbi.deb
50
51 RUN pip3 install \
52     -r /usr/lib/python3/dist-packages/osm_common/requirements.txt \
53     -r /usr/lib/python3/dist-packages/osm_im/requirements.txt \
54     -r /usr/lib/python3/dist-packages/osm_nbi/requirements.txt
55
56 #######################################################################################
57 FROM ubuntu:22.04 as FINAL
58
59 ARG APT_PROXY
60 RUN if [ ! -z $APT_PROXY ] ; then \
61     echo "Acquire::http::Proxy \"$APT_PROXY\";" > /etc/apt/apt.conf.d/proxy.conf ;\
62     echo "Acquire::https::Proxy \"$APT_PROXY\";" >> /etc/apt/apt.conf.d/proxy.conf ;\
63     fi
64
65 RUN DEBIAN_FRONTEND=noninteractive apt-get --yes update && \
66     DEBIAN_FRONTEND=noninteractive apt-get --yes install \
67     python3-minimal=3.10.* \
68     && rm -rf /var/lib/apt/lists/*
69
70 COPY --from=INSTALL /usr/lib/python3/dist-packages /usr/lib/python3/dist-packages
71 COPY --from=INSTALL /usr/local/lib/python3.10/dist-packages  /usr/local/lib/python3.10/dist-packages
72
73 #######################################################################################
74 # End of common preparation
75
76 RUN rm -f /etc/apt/apt.conf.d/proxy.conf
77
78 # Creating the user for the app
79 RUN groupadd -g 1000 appuser && \
80     useradd -u 1000 -g 1000 -d /app appuser && \
81     mkdir -p /app/osm_nbi && \
82     mkdir -p /app/storage/kafka && \
83     mkdir /app/log && \
84     chown -R appuser:appuser /app
85
86 WORKDIR /app/osm_nbi
87
88 # Changing the security context
89 USER appuser
90
91 EXPOSE 9999
92
93 RUN cp -R /usr/lib/python3/dist-packages/osm_nbi/html_public /app/osm_nbi/html_public
94 RUN cp /usr/lib/python3/dist-packages/osm_nbi/nbi.cfg /app/osm_nbi/
95 RUN cp -R /usr/lib/python3/dist-packages/osm_nbi/http /app/osm_nbi/
96
97 # The following ENV can be added with "docker run -e xxx' to configure
98 # server
99 ENV OSMNBI_SOCKET_HOST     0.0.0.0
100 ENV OSMNBI_SOCKET_PORT     9999
101 ENV OSMNBI_SERVER_SSL_CERTIFICATE               /app/osm_nbi/http/cert.pem
102 ENV OSMNBI_SERVER_SSL_PRIVATE_KEY               /app/osm_nbi/http/privkey.pem
103 # storage
104 ENV OSMNBI_STORAGE_PATH    /app/storage
105 # database
106 ENV OSMNBI_DATABASE_DRIVER mongo
107 ENV OSMNBI_DATABASE_URI   mongodb://mongo:27017
108 #ENV OSMNBI_DATABASE_HOST   mongo
109 #ENV OSMNBI_DATABASE_PORT   27017
110
111 # web
112 ENV OSMNBI_STATIC_DIR      /app/osm_nbi/html_public
113 # message
114 ENV OSMNBI_MESSAGE_DRIVER  kafka
115 ENV OSMNBI_MESSAGE_HOST    kafka
116 ENV OSMNBI_MESSAGE_PORT    9092
117 # logs
118 ENV OSMNBI_LOG_FILE        /app/log/nbi.log
119 ENV OSMNBI_LOG_LEVEL       DEBUG
120 # authentication
121 ENV OSMNBI_AUTHENTICATION_BACKEND               internal
122 #ENV OSMNBI_AUTHENTICATION_BACKEND               keystone
123 #ENV OSMNBI_AUTHENTICATION_AUTH_URL              keystone
124 #ENV OSMNBI_AUTHENTICATION_AUTH_PORT             5000
125 #ENV OSMNBI_AUTHENTICATION_USER_DOMAIN_NAME      default
126 #ENV OSMNBI_AUTHENTICATION_PROJECT_DOMAIN_NAME   default
127 #ENV OSMNBI_AUTHENTICATION_SERVICE_USERNAME      nbi
128 #ENV OSMNBI_AUTHENTICATION_SERVICE_PASSWORD      nbi
129 #ENV OSMNBI_AUTHENTICATION_SERVICE_PROJECT       service
130 #prometheus
131 ENV OSMNBI_PROMETHEUS_HOST                      prometheus
132 ENV OSMNBI_PROMETHEUS_PORT                      9090
133
134 HEALTHCHECK --start-period=120s --interval=10s --timeout=5s --retries=5 \
135   CMD curl -k https://localhost:9999/osm/ | grep Welcome || exit 1
136
137 # Run app.py when the container launches
138 CMD python3 -m osm_nbi.nbi