Greatly reduce the size of A1 docker from 1.25GB to 278MB 72/672/1
authorTommy Carpenter <tommy@research.att.com>
Wed, 7 Aug 2019 15:38:44 +0000 (11:38 -0400)
committerTommy Carpenter <tommy@research.att.com>
Fri, 9 Aug 2019 15:08:39 +0000 (11:08 -0400)
Change-Id: I9850d20dc56f4cddfcb5643066ef5eba484148ec
Signed-off-by: Tommy Carpenter <tommy@research.att.com>
.dockerignore [new file with mode: 0644]
Dockerfile
Dockerfile-Unit-Test [new file with mode: 0644]
container-tag.yaml
docs/developer-guide.rst
docs/release-notes.rst
integration_tests/a1mediator/Chart.yaml
setup.py
tox-integration.ini
tox.ini

diff --git a/.dockerignore b/.dockerignore
new file mode 100644 (file)
index 0000000..eeb8a6e
--- /dev/null
@@ -0,0 +1 @@
+**/__pycache__
index 658963f..6d1f78a 100644 (file)
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 # ==================================================================================
-# TODO: switch to alpine once rmr apk available
-FROM python:3.7
+FROM python:3.7-alpine
 
-COPY . /tmp
-WORKDIR /tmp
-
-# copy NNG out of the  CI builder nng
-COPY --from=nexus3.o-ran-sc.org:10004/bldr-debian-python:3-py3.7-nng1.1.1 /usr/local/lib/libnng.so /usr/local/lib/libnng.so
+# copy NNG and rmr out of the  CI builder nng
+COPY --from=nexus3.o-ran-sc.org:10004/bldr-alpine3:3-a3.9 /usr/local/lib64/libnng.so /usr/local/lib64/libnng.so
+COPY --from=nexus3.o-ran-sc.org:10004/bldr-alpine3:3-a3.9 /usr/local/lib64/librmr_nng.so /usr/local/lib64/librmr_nng.so
 
-# Installs RMr using debian package hosted at packagecloud.io
-RUN wget --content-disposition https://packagecloud.io/o-ran-sc/master/packages/debian/stretch/rmr_1.0.36_amd64.deb/download.deb
-RUN dpkg -i rmr_1.0.36_amd64.deb
+COPY a1/ /tmp/a1
+COPY tests/ /tmp/tests
+COPY setup.py tox.ini /tmp/
+WORKDIR /tmp
 
 # dir that rmr routing file temp goes into
 RUN mkdir -p /opt/route/
 
-# Install RMr python bindings
-# this writes into /usr/local, need root
-RUN pip install --upgrade pip && pip install rmr==0.10.1 tox
-
-# Run the unit tests
-RUN tox
+# Gevent needs gcc; TODO: this will get fixed
+RUN apk add gcc musl-dev
 
-# do the actual install
+# do the actual install; this writes into /usr/local, need root
 RUN pip install .
 
 # 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.
-# https://stackoverflow.com/questions/27701930/add-user-to-docker-container
-RUN adduser --disabled-password --gecos '' a1user
-USER a1user
+ENV A1USER a1user
+RUN addgroup -S $A1USER && adduser -S -G $A1USER $A1USER 
+USER $A1USER
 
 # misc setups
 EXPOSE 10000
-ENV LD_LIBRARY_PATH /usr/local/lib
+ENV LD_LIBRARY_PATH /usr/local/lib/:/usr/local/lib64
 ENV RMR_SEED_RT /opt/route/local.rt
 
 CMD run.py
diff --git a/Dockerfile-Unit-Test b/Dockerfile-Unit-Test
new file mode 100644 (file)
index 0000000..882b759
--- /dev/null
@@ -0,0 +1,38 @@
+# ==================================================================================
+#       Copyright (c) 2019 Nokia
+#       Copyright (c) 2018-2019 AT&T Intellectual Property.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+# ==================================================================================
+FROM python:3.7-alpine
+
+# copy NNG and rmr out of the  CI builder nng
+COPY --from=nexus3.o-ran-sc.org:10004/bldr-alpine3:3-a3.9 /usr/local/lib64/libnng.so /usr/local/lib64/libnng.so
+COPY --from=nexus3.o-ran-sc.org:10004/bldr-alpine3:3-a3.9 /usr/local/lib64/librmr_nng.so /usr/local/lib64/librmr_nng.so
+
+COPY a1/ /tmp/a1
+COPY tests/ /tmp/tests
+COPY setup.py tox.ini /tmp/
+WORKDIR /tmp
+
+# dir that rmr routing file temp goes into
+RUN mkdir -p /opt/route/
+
+# Gevent needs gcc; TODO: this will get fixed
+RUN apk add gcc musl-dev
+
+# Upgrade pip, install tox
+RUN pip install --upgrade pip && pip install tox
+
+# Run the unit tests
+RUN tox
index 60b7de3..572aef3 100644 (file)
@@ -1,4 +1,4 @@
 # The Jenkins job uses this string for the tag in the image name
 # for example nexus3.o-ran-sc.org:10004/my-image-name:my-tag
 ---
-tag: 0.10.0
+tag: 0.10.1
index 2274b6e..660bd62 100644 (file)
@@ -53,6 +53,12 @@ Also, this requires the python packages ``tox`` and ``pytest``.
    tox
    open htmlcov/index.html
 
+Alternatively, you can run the unit tests in Docker (this is somewhat less nice because you don't get the pretty HTML)
+
+::
+
+   docker build  --no-cache -t a1test:latest -f Dockerfile-Unit-Test
+
 Integration testing
 ===================
 This tests A1’s external API with two test receivers. This depends on helm+k8s, meaning you cannot run this if this is not installed.
index b506db7..75653df 100644 (file)
@@ -23,6 +23,14 @@ All notable changes to this project will be documented in this file.
 The format is based on `Keep a Changelog <http://keepachangelog.com/>`__
 and this project adheres to `Semantic Versioning <http://semver.org/>`__.
 
+[0.10.1] - 8/9/2019
+
+::
+
+    * Greatly reduce the size of A1 docker from 1.25GB to ~278MB.
+    * Add a seperate dockerfile for unit testing
+
+
 [0.10.0] - 7/30/2019
 
 ::
index 188872c..0166330 100644 (file)
@@ -1,4 +1,4 @@
 apiVersion: v1
 description: A1 Helm chart for Kubernetes
 name: a1mediator
-version: 0.10.0
+version: 0.10.1
index f0a9dd3..cbdc36a 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -18,13 +18,14 @@ from setuptools import setup, find_packages
 
 setup(
     name="a1",
-    version="0.10.0",
+    version="0.10.1",
     packages=find_packages(exclude=["tests.*", "tests"]),
     author="Tommy Carpenter",
     description="RIC A1 Mediator for policy/intent changes",
     url="https://gerrit.o-ran-sc.org/r/admin/repos/ric-plt/a1",
     entry_points={"console_scripts": ["run.py=a1.run:main"]},
     # we require jsonschema, should be in that list, but connexion already requires a specific version of it
-    install_requires=["requests", "Flask", "connexion[swagger-ui]", "gevent", "rmr>=0.10.0"],
+    # rmr 0.10.4 has a bugfix required on alpine
+    install_requires=["requests", "Flask", "connexion[swagger-ui]", "gevent", "rmr>=0.10.4"],
     package_data={"a1": ["openapi.yaml"]},
 )
index aa2ce36..fb996d1 100644 (file)
@@ -31,7 +31,7 @@ changedir=integration_tests
 commands_pre=
     helm install --devel testreceiver -n testreceiver
     helm install --devel a1mediator/ -n a1
-    sleep 10
+    sleep 20
     ./portforward.sh
     sleep 2
 commands=
diff --git a/tox.ini b/tox.ini
index 976ddc7..5393490 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -23,7 +23,7 @@ deps=
     coverage
     pytest-cov
 setenv =
-    LD_LIBRARY_PATH = /usr/local/lib/
+    LD_LIBRARY_PATH = /usr/local/lib/:/usr/local/lib64
     RMR_RCV_RETRY_INTERVAL = 1
     RMR_RETRY_TIMES = 2
 commands=