9c23262f215fe83eb5c507f8d440aeb842b84037
[osm/devops.git] / docker / PLA / 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 prepration
37
38 ARG PYTHON3_OSM_COMMON_URL
39 ARG PYTHON3_OSM_PLA_URL
40
41 RUN curl $PYTHON3_OSM_COMMON_URL -o osm_common.deb
42 RUN dpkg -i ./osm_common.deb
43
44 RUN curl $PYTHON3_OSM_PLA_URL -o osm_pla.deb
45 RUN dpkg -i ./osm_pla.deb
46
47 RUN pip3 install \
48     -r /usr/lib/python3/dist-packages/osm_common/requirements.txt \
49     -r /usr/lib/python3/dist-packages/osm_pla/requirements.txt
50
51 ADD https://github.com/MiniZinc/MiniZincIDE/releases/download/2.4.2/MiniZincIDE-2.4.2-bundle-linux-x86_64.tgz /minizinc.tgz
52
53 RUN tar -zxf /minizinc.tgz && \
54     mv /MiniZincIDE-2.4.2-bundle-linux /minizinc
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 prepration
75
76 RUN rm -f /etc/apt/apt.conf.d/proxy.conf
77
78 LABEL authors="Lars-Göran Magnusson"
79
80 COPY --from=INSTALL /usr/bin/osm* /usr/bin/
81 COPY --from=INSTALL /minizinc /minizinc
82
83 RUN mkdir /entry_data && \
84     mkdir /placement && \
85     mkdir /entry_data/mzn-lib && \
86     ln -s /entry_data/mzn-lib /minizinc/share/minizinc/exec
87
88 COPY scripts/ /app/osm_pla/scripts/
89
90 # Creating the user for the app
91 RUN groupadd -g 1000 appuser && \
92     useradd -u 1000 -g 1000 -d /app appuser && \
93     mkdir -p /app/osm_pla && \
94     chown -R appuser:appuser /app && \
95     chown -R appuser:appuser /entry_data && \
96     chown -R appuser:appuser /minizinc && \
97     chown -R appuser:appuser /placement
98
99 WORKDIR /app/osm_pla
100
101 # Changing the security context
102 USER appuser
103
104 ENV OSMPLA_MESSAGE_DRIVER kafka
105 ENV OSMPLA_MESSAGE_HOST kafka
106 ENV OSMPLA_MESSAGE_PORT 9092
107
108 ENV OSMPLA_DATABASE_DRIVER mongo
109 ENV OSMPLA_DATABASE_URI mongodb://mongo:27017
110
111 ENV OSMPLA_SQL_DATABASE_URI sqlite:///pla_sqlite.db
112
113 ENV OSMPLA_GLOBAL_LOG_LEVEL INFO
114
115 ENV FZNEXEC "/entry_data/fzn-exec"
116 ENV PATH "/minizinc/bin:${PATH}"
117 ENV LD_LIBRARY_PATH "/minizinc/lib:${LD_LIBRARY_PATH}"
118
119 # No healtcheck yet...
120 #HEALTHCHECK --start-period=120s --interval=10s --timeout=5s --retries=5 \
121 #  CMD osm-pla-healthcheck || exit 1
122
123 CMD [ "/bin/bash", "scripts/start.sh" ]