blob: e5eeb1bb363d0a4d7e7a425e9e61988291571aa2 [file] [log] [blame]
Tommy Carpenter5ad8f032019-05-30 14:33:21 -04001# ==================================================================================
Tommy Carpenter78ba2732020-02-07 14:06:20 -05002# Copyright (c) 2019-2020 Nokia
3# Copyright (c) 2018-2020 AT&T Intellectual Property.
Tommy Carpenter5ad8f032019-05-30 14:33:21 -04004#
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# ==================================================================================
Tommy Carpenter40caa312019-09-12 16:24:10 -040017
Tommy Carpenter78ba2732020-02-07 14:06:20 -050018# This container uses a 2 stage build!
19# Tips and tricks were learned from: https://pythonspeed.com/articles/multi-stage-docker-python/
Tommy Carpenter102b8952020-03-20 10:02:46 -040020FROM python:3.8-alpine AS compile-image
Lott, Christopher (cl778h)fe30c172020-04-29 15:23:28 -040021# upgrade pip as root
22RUN pip install --upgrade pip
Lott, Christopher (cl778h)e4bbf862020-04-18 08:40:00 -040023# Gevent needs gcc, make, file, ffi
24RUN apk update && apk add gcc musl-dev make file libffi-dev
Lott, Christopher (cl778h)fe30c172020-04-29 15:23:28 -040025# 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
Tommy Carpenter78ba2732020-02-07 14:06:20 -050028RUN addgroup -S a1user && adduser -S -G a1user a1user
Lott, Christopher (cl778h)fe30c172020-04-29 15:23:28 -040029# switch to the non-root user for installing site packages
Tommy Carpenter78ba2732020-02-07 14:06:20 -050030USER a1user
Lott, Christopher (cl778h)fe30c172020-04-29 15:23:28 -040031# 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
Tommy Carpenter78ba2732020-02-07 14:06:20 -050034COPY setup.py /home/a1user/
35COPY a1/ /home/a1user/a1
36RUN pip install --user /home/a1user
37
38###########
39# 2nd stage
Tommy Carpenter102b8952020-03-20 10:02:46 -040040FROM python:3.8-alpine
Lott, Christopher (cl778h)d26734f2020-04-27 17:25:05 -040041
42# copy rmr libraries from builder image in lieu of an Alpine package
43COPY --from=nexus3.o-ran-sc.org:10002/o-ran-sc/bldr-alpine3-rmr:4.0.2 /usr/local/lib64/librmr* /usr/local/lib64/
44
Lott, Christopher (cl778h)fe30c172020-04-29 15:23:28 -040045# copy python modules; this makes the 2 stage python build work
Tommy Carpenter78ba2732020-02-07 14:06:20 -050046COPY --from=compile-image /home/a1user/.local /home/a1user/.local
Lott, Christopher (cl778h)fe30c172020-04-29 15:23:28 -040047# create mount point for dir with rmr routing file as named below
48RUN mkdir -p /opt/route/
49# create a non-root user
Tommy Carpenter78ba2732020-02-07 14:06:20 -050050RUN addgroup -S a1user && adduser -S -G a1user a1user
Lott, Christopher (cl778h)fe30c172020-04-29 15:23:28 -040051# 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
Tommy Carpenter78ba2732020-02-07 14:06:20 -050054USER a1user
Tommy Carpenter9407e112019-06-24 14:27:35 -040055# misc setups
56EXPOSE 10000
Tommy Carpenter296f8de2019-08-07 11:38:44 -040057ENV LD_LIBRARY_PATH /usr/local/lib/:/usr/local/lib64
Tommy Carpenter5ad8f032019-05-30 14:33:21 -040058ENV RMR_SEED_RT /opt/route/local.rt
Tommy Carpenter40caa312019-09-12 16:24:10 -040059ENV PYTHONUNBUFFERED 1
Lott, Christopher (cl778h)fe30c172020-04-29 15:23:28 -040060# pip installs console script to ~/.local/bin so PATH is critical
Tommy Carpenter78ba2732020-02-07 14:06:20 -050061ENV PATH=/home/a1user/.local/bin:$PATH
Tommy Carpenter40caa312019-09-12 16:24:10 -040062
Tommy Carpenter78ba2732020-02-07 14:06:20 -050063# Run!
Lott, Christopher (cl778h)fe30c172020-04-29 15:23:28 -040064CMD run-a1