Greatly reduce the size of A1 docker from 1.25GB to 278MB
Change-Id: I9850d20dc56f4cddfcb5643066ef5eba484148ec
Signed-off-by: Tommy Carpenter <tommy@research.att.com>
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..eeb8a6e
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1 @@
+**/__pycache__
diff --git a/Dockerfile b/Dockerfile
index 658963f..6d1f78a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -14,41 +14,35 @@
# 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
+# 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
-# 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
-
-# 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
-
# 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
+# Gevent needs gcc; TODO: this will get fixed
+RUN apk add gcc musl-dev
-# Run the unit tests
-RUN tox
-
-# 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
index 0000000..882b759
--- /dev/null
+++ b/Dockerfile-Unit-Test
@@ -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
diff --git a/container-tag.yaml b/container-tag.yaml
index 60b7de3..572aef3 100644
--- a/container-tag.yaml
+++ b/container-tag.yaml
@@ -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
diff --git a/docs/developer-guide.rst b/docs/developer-guide.rst
index 2274b6e..660bd62 100644
--- a/docs/developer-guide.rst
+++ b/docs/developer-guide.rst
@@ -53,6 +53,12 @@
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.
diff --git a/docs/release-notes.rst b/docs/release-notes.rst
index b506db7..75653df 100644
--- a/docs/release-notes.rst
+++ b/docs/release-notes.rst
@@ -23,6 +23,14 @@
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
::
diff --git a/integration_tests/a1mediator/Chart.yaml b/integration_tests/a1mediator/Chart.yaml
index 188872c..0166330 100644
--- a/integration_tests/a1mediator/Chart.yaml
+++ b/integration_tests/a1mediator/Chart.yaml
@@ -1,4 +1,4 @@
apiVersion: v1
description: A1 Helm chart for Kubernetes
name: a1mediator
-version: 0.10.0
+version: 0.10.1
diff --git a/setup.py b/setup.py
index f0a9dd3..cbdc36a 100644
--- a/setup.py
+++ b/setup.py
@@ -18,13 +18,14 @@
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"]},
)
diff --git a/tox-integration.ini b/tox-integration.ini
index aa2ce36..fb996d1 100644
--- a/tox-integration.ini
+++ b/tox-integration.ini
@@ -31,7 +31,7 @@
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
--- a/tox.ini
+++ b/tox.ini
@@ -23,7 +23,7 @@
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=