Split build steps out of Dockerfile to script 07/2507/1
authorLott, Christopher (cl778h) <cl778h@att.com>
Thu, 13 Feb 2020 14:41:21 +0000 (09:41 -0500)
committerLott, Christopher (cl778h) <cl778h@att.com>
Thu, 13 Feb 2020 14:42:33 +0000 (09:42 -0500)
Create build-e2mgr-ubuntu.sh shell script that installs prerequisites,
builds the main binary and runs unit tests. This allows the same steps
to be run in a sonar analysis & reporting job without duplication.

Signed-off-by: Lott, Christopher (cl778h) <cl778h@att.com>
Change-Id: I1e5e3e2880c39b49105949635a1ef5389efbe91b

E2Manager/Dockerfile [changed mode: 0644->0755]
E2Manager/build-e2mgr-ubuntu.sh [new file with mode: 0755]

old mode 100644 (file)
new mode 100755 (executable)
index 25a972a..99dfc35
@@ -24,30 +24,11 @@ FROM nexus3.o-ran-sc.org:10004/bldr-ubuntu16-c-go:3-u16.04-nng as ubuntu
 
 WORKDIR /opt/E2Manager
 COPY . . 
-ENV PATH=$PATH:/usr/local/go/bin:/usr/lib/go-1.12/bin
-#RUN git clone https://gerrit.o-ran-sc.org/r/ric-plt/lib/rmr && cd rmr/; mkdir build; cd build; /opt/bin/cmake -DDEV_PKG=1 ..; make install
-# Install RMr library and dev files
-RUN wget --content-disposition  https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/rmr_1.13.0_amd64.deb/download.deb
-RUN dpkg -i rmr_1.13.0_amd64.deb
-RUN wget --content-disposition https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/rmr-dev_1.13.0_amd64.deb/download.deb
-RUN dpkg -i rmr-dev_1.13.0_amd64.deb
 
-RUN cd 3rdparty/asn1codec && make
-RUN go build app/main.go
-
-# Execute UT
-ENV LD_LIBRARY_PATH=/usr/local/lib
-
-# cgocheck=2 enables expensive checks that should not miss any errors, but will cause your program to run slower.
-# clobberfree=1 causes the garbage collector to clobber the memory content of an object with bad content when it frees the object.
-# gcstoptheworld=1 disables concurrent garbage collection, making every garbage collection a stop-the-world event.
-# Setting gcstoptheworld=2 also disables concurrent sweeping after the garbage collection finishes.
-# Setting allocfreetrace=1 causes every allocation to be profiled and a stack trace printed on each object's allocation and free.
-ENV GODEBUG=cgocheck=2,clobberfree=1,gcstoptheworld=2,allocfreetrace=0
-ENV RIC_ID="bbbccc-abcd0e/20"
-ENV RMR_SEED_RT=/opt/E2Manager/router_test.txt
-RUN go-acc $(go list ./... | grep -v e2mgr/mocks | grep -v e2mgr/tests |grep -v e2mgr/e2managererrors| grep -v e2mgr/enums)
+# Install dependencies, compile and test the module
+RUN bash build-e2mgr-ubuntu.sh
 
+# Build deployable container
 FROM ubuntu:16.04
 
 RUN apt-get update && apt-get install -y \
diff --git a/E2Manager/build-e2mgr-ubuntu.sh b/E2Manager/build-e2mgr-ubuntu.sh
new file mode 100755 (executable)
index 0000000..693ca84
--- /dev/null
@@ -0,0 +1,95 @@
+#!/bin/bash
+##############################################################################
+#
+#   Copyright (c) 2020 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.
+#
+##############################################################################
+
+# Installs libraries and builds E2 manager
+# Prerequisites:
+#   Debian distro; e.g., Ubuntu
+#   cmake (version?)
+#   gcc/g++ compiler (version?)
+#   golang (go), tested with version 1.12.0
+#   current working directory is E2Manager
+#   running with sudo privs, which is default in Docker
+
+# TODO:
+# 1) drop go from $PATH when build minion is extended
+# 2) drop rewrite of path prefix when SonarScanner is extended
+
+# Stop at first error and be verbose
+set -eux
+
+echo "--> e2mgr-build-ubuntu.sh"
+
+# Build and install NNG, which requires ninja
+apt-get install ninja-build
+git clone https://github.com/nanomsg/nng.git \
+    && cd nng \
+    && git checkout e618abf8f3db2a94269a79c8901a51148d48fcc2 \
+    && mkdir build \
+    && cd build \
+    && cmake -DBUILD_SHARED_LIBS=1 -G Ninja .. \
+    && ninja \
+    && ninja install \
+    && cd ../.. \
+    && rm -r nng
+
+# Install RMR from deb packages at packagecloud.io
+rmr=rmr_1.13.0_amd64.deb
+wget --content-disposition  https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/$rmr/download.deb
+dpkg -i $rmr
+rm $rmr
+rmrdev=rmr-dev_1.13.0_amd64.deb
+wget --content-disposition https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/$rmrdev/download.deb
+dpkg -i $rmrdev
+rm $rmrdev
+
+# required to find nng and rmr libs
+export LD_LIBRARY_PATH=/usr/local/lib
+
+# go installs tools like go-acc to $HOME/go/bin
+# ubuntu minion path lacks go
+export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin
+
+# install the go coverage tool helper
+go get -v github.com/ory/go-acc
+
+cd 3rdparty/asn1codec \
+    && make \
+    && cd ../..
+
+go build -v app/main.go
+
+# Execute UT and measure coverage
+# cgocheck=2 enables expensive checks that should not miss any errors, but will cause your program to run slower.
+# clobberfree=1 causes the garbage collector to clobber the memory content of an object with bad content when it frees the object.
+# gcstoptheworld=1 disables concurrent garbage collection, making every garbage collection a stop-the-world event.
+# Setting gcstoptheworld=2 also disables concurrent sweeping after the garbage collection finishes.
+# Setting allocfreetrace=1 causes every allocation to be profiled and a stack trace printed on each object's allocation and free.
+export GODEBUG=cgocheck=2,clobberfree=1,gcstoptheworld=2,allocfreetrace=0
+export RIC_ID="bbbccc-abcd0e/20"
+# Static route table is provided in git repo
+export RMR_SEED_RT=$(pwd)/router_test.txt
+# writes to coverage.txt by default
+# SonarCloud accepts the text format
+go-acc $(go list ./... | grep -vE '(/mocks|/tests|/e2managererrors|/enums)' )
+
+# rewrite the module name to a directory name in the coverage report
+# https://jira.sonarsource.com/browse/SONARSLANG-450
+sed -i -e 's/^e2mgr/E2Manager/' coverage.txt
+
+echo "--> e2mgr-build-ubuntu.sh ends"