blob: 9d4b7890289b075070cafd3953e0410fad12ae69 [file] [log] [blame]
E. Scott Daniels06a1a142021-05-13 09:12:28 -04001# ==================================================================================
2# Copyright (c) 2019-2020 Nokia
3# Copyright (c) 2018-2020 AT&T Intellectual Property.
4#
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
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
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# ==================================================================================
17
18# This container uses a 2 stage build!
19# Tips and tricks were learned from: https://pythonspeed.com/articles/multi-stage-docker-python/
20FROM python:3.8-alpine AS compile-image
21# upgrade pip as root
22RUN pip install --upgrade pip
23# Gevent needs gcc, make, file, ffi
24RUN 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
28RUN addgroup -S a1user && adduser -S -G a1user a1user
29# switch to the non-root user for installing site packages
30USER a1user
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
33RUN pip install --user gevent
34COPY setup.py /home/a1user/
35COPY a1/ /home/a1user/a1
36RUN pip install --user /home/a1user
37
38###########
39# 2nd stage
40FROM python:3.8-alpine
41
42# copy rmr libraries from builder image in lieu of an Alpine package (10002 is the release portion of the repo)
43COPY --from=nexus3.o-ran-sc.org:10002/o-ran-sc/bldr-alpine3-rmr:4.5.2 /usr/local/lib64/librmr* /usr/local/lib64/
44
45# copy python modules; this makes the 2 stage python build work
46COPY --from=compile-image /home/a1user/.local /home/a1user/.local
47# create mount point for dir with rmr routing file as named below
48RUN mkdir -p /opt/route/
49# create a non-root user
50RUN addgroup -S a1user && adduser -S -G a1user a1user
51# ensure the non-root user can read python files
52RUN chown -R a1user:a1user /home/a1user/.local
53# switch to the non-root user for security reasons
54USER a1user
55# misc setups
56EXPOSE 10000
57ENV LD_LIBRARY_PATH /usr/local/lib/:/usr/local/lib64
58ENV RMR_SEED_RT /opt/route/local.rt
59# Set to True to run standalone
60ENV USE_FAKE_SDL False
61ENV PYTHONUNBUFFERED 1
62# pip installs console script to ~/.local/bin so PATH is critical
63ENV PATH /home/a1user/.local/bin:$PATH
64# prometheus client gathers data here
65ENV prometheus_multiproc_dir /tmp
66
67# Run!
68CMD run-a1