Tommy Carpenter | 5ad8f03 | 2019-05-30 14:33:21 -0400 | [diff] [blame] | 1 | # ================================================================================== |
Tommy Carpenter | 78ba273 | 2020-02-07 14:06:20 -0500 | [diff] [blame] | 2 | # Copyright (c) 2019-2020 Nokia |
| 3 | # Copyright (c) 2018-2020 AT&T Intellectual Property. |
Tommy Carpenter | 5ad8f03 | 2019-05-30 14:33:21 -0400 | [diff] [blame] | 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 | # ================================================================================== |
Tommy Carpenter | 40caa31 | 2019-09-12 16:24:10 -0400 | [diff] [blame] | 17 | |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 18 | # This builds an image for A1 based on ubuntu. The build takes between three and four |
| 19 | # minutes depending on what was previously cached, and results in an image that is |
| 20 | # roughly 260 MiB in size (as of May 2021) |
| 21 | # |
| 22 | |
| 23 | FROM python:3.8 as build |
| 24 | |
Lott, Christopher (cl778h) | fe30c17 | 2020-04-29 15:23:28 -0400 | [diff] [blame] | 25 | # upgrade pip as root |
| 26 | RUN pip install --upgrade pip |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 27 | |
| 28 | # pick up things for gevent build |
| 29 | # |
| 30 | RUN apt-get update |
| 31 | RUN apt-get install -y gcc musl-dev make file libffi-dev g++ |
| 32 | |
| 33 | # --- all root operations must be above this line ------------------------------------ |
| 34 | |
| 35 | |
| 36 | # create a simple user. This is only really needed in stage 2, |
Lott, Christopher (cl778h) | fe30c17 | 2020-04-29 15:23:28 -0400 | [diff] [blame] | 37 | # however this makes the copying easier and straighttforward; |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 38 | # the 'pip option --user' command doesn't do the same thing when |
| 39 | # run as root. |
| 40 | # |
| 41 | RUN addgroup a1user && adduser --ingroup a1user a1user |
| 42 | |
| 43 | # switch to the non-root user for installing python things |
Tommy Carpenter | 78ba273 | 2020-02-07 14:06:20 -0500 | [diff] [blame] | 44 | USER a1user |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 45 | |
| 46 | # Speed hack; we install gevent before anything because when building repeatedly (eg during dev) |
Lott, Christopher (cl778h) | fe30c17 | 2020-04-29 15:23:28 -0400 | [diff] [blame] | 47 | # and only changing a1 code, we do not need to keep compiling gevent which takes forever |
| 48 | RUN pip install --user gevent |
subhash kumar singh | 8b66367 | 2021-05-25 06:59:23 +0000 | [diff] [blame] | 49 | RUN pip install --user requests |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 50 | |
Tommy Carpenter | 78ba273 | 2020-02-07 14:06:20 -0500 | [diff] [blame] | 51 | COPY setup.py /home/a1user/ |
| 52 | COPY a1/ /home/a1user/a1 |
| 53 | RUN pip install --user /home/a1user |
| 54 | |
Lott, Christopher (cl778h) | d26734f | 2020-04-27 17:25:05 -0400 | [diff] [blame] | 55 | |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 56 | |
| 57 | # ----- stage 2 --------------------------------------------------------------------------------- |
| 58 | |
| 59 | # It might be tempting to use python:3.8, but that image is more than |
| 60 | # 800 GiB to start, and the final image size if it is used is over |
| 61 | # 1 GiB!! Using the plain ubuntu image, then installing py3, and taking |
| 62 | # things built in the first stage, the final image size isn't tiny, but should |
| 63 | # be well under the 800GiB start for the python image. |
| 64 | # |
wahidw | 537c182 | 2021-11-12 09:54:20 +0000 | [diff] [blame] | 65 | FROM ubuntu:20.04 |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 66 | |
| 67 | # pick up reference to python so that we can get 3.8 and not the really old default |
| 68 | |
| 69 | RUN apt-get update \ |
| 70 | && apt install -y software-properties-common \ |
| 71 | && add-apt-repository ppa:deadsnakes/ppa \ |
| 72 | && apt-get install -y python3.8 python3-pip wget \ |
| 73 | && apt-get clean |
| 74 | |
| 75 | # fetch and install RMR and any other needed libraries |
| 76 | # |
wahidw | b44e154 | 2021-12-03 10:29:52 +0000 | [diff] [blame] | 77 | ARG RMR_VER=4.8.0 |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 78 | ARG RMR_PKG_URL=https://packagecloud.io/o-ran-sc/release/packages/debian/stretch/ |
| 79 | |
| 80 | RUN wget -nv --content-disposition ${RMR_PKG_URL}/rmr_${RMR_VER}_amd64.deb/download.deb |
| 81 | RUN wget -nv --content-disposition ${RMR_PKG_URL}/rmr-dev_${RMR_VER}_amd64.deb/download.deb |
| 82 | RUN dpkg -i rmr_${RMR_VER}_amd64.deb \ |
| 83 | && dpkg -i rmr-dev_${RMR_VER}_amd64.deb \ |
| 84 | && ldconfig |
Lott, Christopher (cl778h) | d26734f | 2020-04-27 17:25:05 -0400 | [diff] [blame] | 85 | |
Lott, Christopher (cl778h) | fe30c17 | 2020-04-29 15:23:28 -0400 | [diff] [blame] | 86 | # copy python modules; this makes the 2 stage python build work |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 87 | # |
| 88 | COPY --from=build /home/a1user/.local /home/a1user/.local |
| 89 | |
Lott, Christopher (cl778h) | fe30c17 | 2020-04-29 15:23:28 -0400 | [diff] [blame] | 90 | # create mount point for dir with rmr routing file as named below |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 91 | # |
Lott, Christopher (cl778h) | fe30c17 | 2020-04-29 15:23:28 -0400 | [diff] [blame] | 92 | RUN mkdir -p /opt/route/ |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 93 | |
| 94 | # create a non-root user, ensure it can access what it needs, and switch to it |
| 95 | # |
| 96 | RUN addgroup a1user \ |
| 97 | && adduser --disabled-password --disabled-login --gecos "image-user" --no-create-home --ingroup a1user a1user \ |
| 98 | && chown -R a1user:a1user /home/a1user/.local \ |
| 99 | && chown a1user:a1user /home/a1user |
| 100 | |
| 101 | |
| 102 | # ------------------ no root commands after this point ------------------------------------- |
Tommy Carpenter | 78ba273 | 2020-02-07 14:06:20 -0500 | [diff] [blame] | 103 | USER a1user |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 104 | |
| 105 | # the maddening onsey-twosey install of pything crud... |
| 106 | # |
| 107 | RUN pip3 install --user connexion |
| 108 | |
| 109 | # misc |
| 110 | # |
Tommy Carpenter | 9407e11 | 2019-06-24 14:27:35 -0400 | [diff] [blame] | 111 | EXPOSE 10000 |
Tommy Carpenter | 296f8de | 2019-08-07 11:38:44 -0400 | [diff] [blame] | 112 | ENV LD_LIBRARY_PATH /usr/local/lib/:/usr/local/lib64 |
Tommy Carpenter | 5ad8f03 | 2019-05-30 14:33:21 -0400 | [diff] [blame] | 113 | ENV RMR_SEED_RT /opt/route/local.rt |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 114 | |
| 115 | # Set "fake" to True to run standalone |
| 116 | # |
Lott, Christopher (cl778h) | 20d87ed | 2020-04-29 16:50:06 -0400 | [diff] [blame] | 117 | ENV USE_FAKE_SDL False |
Tommy Carpenter | 40caa31 | 2019-09-12 16:24:10 -0400 | [diff] [blame] | 118 | ENV PYTHONUNBUFFERED 1 |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 119 | |
| 120 | # pip installs executable script to $HOME/.local/bin so PATH vars are critical |
| 121 | # |
Lott, Christopher (cl778h) | c91a4a1 | 2020-05-27 15:56:20 -0400 | [diff] [blame] | 122 | ENV PATH /home/a1user/.local/bin:$PATH |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 123 | ENV PYTHONPATH /home/a1user/.local/lib/python3.8/site-packages |
| 124 | |
Lott, Christopher (cl778h) | c91a4a1 | 2020-05-27 15:56:20 -0400 | [diff] [blame] | 125 | # prometheus client gathers data here |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 126 | # |
Lott, Christopher (cl778h) | c91a4a1 | 2020-05-27 15:56:20 -0400 | [diff] [blame] | 127 | ENV prometheus_multiproc_dir /tmp |
Tommy Carpenter | 40caa31 | 2019-09-12 16:24:10 -0400 | [diff] [blame] | 128 | |
E. Scott Daniels | 06a1a14 | 2021-05-13 09:12:28 -0400 | [diff] [blame] | 129 | # by defalt start the application |
| 130 | # |
| 131 | CMD [ "/usr/bin/python3.8", "/home/a1user/.local/bin/run-a1" ] |