1 # ==================================================================================
2 # Copyright (c) 2019-2020 Nokia
3 # Copyright (c) 2018-2020 AT&T Intellectual Property.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ==================================================================================
18 # This container uses a 2 stage build!
19 # Tips and tricks were learned from: https://pythonspeed.com/articles/multi-stage-docker-python/
20 FROM python:3.8-alpine AS compile-image
22 RUN pip install --upgrade pip
23 # Gevent needs gcc, make, file, ffi
24 RUN apk update && apk add gcc musl-dev make file libffi-dev g++
25 # create a non-root user. Only really needed in stage 2,
26 # however this makes the copying easier and straighttforward;
27 # pip option --user doesn't do the same thing if run as root
28 RUN addgroup -S a1user && adduser -S -G a1user a1user
29 # switch to the non-root user for installing site packages
31 # Speed hack; we install gevent before a1 because when building repeatedly (eg during dev)
32 # and only changing a1 code, we do not need to keep compiling gevent which takes forever
33 RUN pip install --user gevent
34 COPY setup.py /home/a1user/
35 COPY a1/ /home/a1user/a1
36 RUN pip install --user /home/a1user
40 FROM python:3.8-alpine
42 # copy rmr libraries from builder image in lieu of an Alpine package (10002 is the release portion of the repo)
43 COPY --from=nexus3.o-ran-sc.org:10002/o-ran-sc/bldr-alpine3-rmr:4.5.2 /usr/local/lib64/librmr* /usr/local/lib64/
45 # copy python modules; this makes the 2 stage python build work
46 COPY --from=compile-image /home/a1user/.local /home/a1user/.local
47 # create mount point for dir with rmr routing file as named below
48 RUN mkdir -p /opt/route/
49 # create a non-root user
50 RUN addgroup -S a1user && adduser -S -G a1user a1user
51 # ensure the non-root user can read python files
52 RUN chown -R a1user:a1user /home/a1user/.local
53 # switch to the non-root user for security reasons
57 ENV LD_LIBRARY_PATH /usr/local/lib/:/usr/local/lib64
58 ENV RMR_SEED_RT /opt/route/local.rt
59 # Set to True to run standalone
60 ENV USE_FAKE_SDL False
61 ENV PYTHONUNBUFFERED 1
62 # pip installs console script to ~/.local/bin so PATH is critical
63 ENV PATH /home/a1user/.local/bin:$PATH
64 # prometheus client gathers data here
65 ENV prometheus_multiproc_dir /tmp