Mostly integration test work:
[ric-plt/a1.git] / Dockerfile
1 # ==================================================================================
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/
20 FROM python:3.7-alpine AS compile-image
21 # Gevent needs gcc
22 RUN apk update && apk add gcc musl-dev
23 # do the install of a1
24
25 # Switch to a non-root user for security reasons
26 # This is only really needed in stage 2 however this makes the copying easier and straitforward! --user doesn't do the same thing if run as root!
27 RUN addgroup -S a1user && adduser -S -G a1user a1user
28 USER a1user
29
30 # Speed hack; we install gevent FIRST because when building repeatedly (eg during dev) and only changing a1 code, we do not need to keep compiling gevent which takes forever
31 RUN pip install --upgrade pip && pip install --user gevent
32 COPY setup.py /home/a1user/
33 COPY a1/ /home/a1user/a1
34 RUN pip install --user /home/a1user
35
36 ###########
37 # 2nd stage
38 FROM python:3.7-alpine
39 # dir that rmr routing file temp goes into
40 RUN mkdir -p /opt/route/
41 # python copy; this basically makes the 2 stage python build work
42 COPY --from=compile-image /home/a1user/.local /home/a1user/.local
43 # copy rmr .sos from the builder image
44 COPY --from=nexus3.o-ran-sc.org:10004/bldr-alpine3-go:1-rmr1.13.1 /usr/local/lib64/libnng.so /usr/local/lib64/libnng.so
45 COPY --from=nexus3.o-ran-sc.org:10004/bldr-alpine3-go:1-rmr1.13.1 /usr/local/lib64/librmr_nng.so /usr/local/lib64/librmr_nng.so
46 # Switch to a non-root user for security reasons. a1 does not currently write into any dirs so no chowns are needed at this time.
47 RUN addgroup -S a1user && adduser -S -G a1user a1user
48 USER a1user
49 # misc setups
50 EXPOSE 10000
51 ENV LD_LIBRARY_PATH /usr/local/lib/:/usr/local/lib64
52 ENV RMR_SEED_RT /opt/route/local.rt
53 ENV PYTHONUNBUFFERED 1
54 # This step is critical
55 ENV PATH=/home/a1user/.local/bin:$PATH
56
57 # Run!
58 CMD run.py