From b23d04b0a9b31a525ecb3a55dacb6c22008339e1 Mon Sep 17 00:00:00 2001 From: "Lott, Christopher (cl778h)" Date: Thu, 13 Feb 2020 09:41:21 -0500 Subject: [PATCH] Split build steps out of Dockerfile to script 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) Change-Id: I1e5e3e2880c39b49105949635a1ef5389efbe91b --- E2Manager/Dockerfile | 25 ++--------- E2Manager/build-e2mgr-ubuntu.sh | 95 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 22 deletions(-) mode change 100644 => 100755 E2Manager/Dockerfile create mode 100755 E2Manager/build-e2mgr-ubuntu.sh diff --git a/E2Manager/Dockerfile b/E2Manager/Dockerfile old mode 100644 new mode 100755 index 25a972a..99dfc35 --- a/E2Manager/Dockerfile +++ b/E2Manager/Dockerfile @@ -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 index 0000000..693ca84 --- /dev/null +++ b/E2Manager/build-e2mgr-ubuntu.sh @@ -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" -- 2.16.6