[SEBA-853] Building BBR and BBSim as part of the scale test pipeline

Change-Id: I007fc7d0d18f039ccf6e3ba059641497404b3d88
diff --git a/.dockerignore b/.dockerignore
index 7beaa60..a1c8f21 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,2 +1,8 @@
 build/*
-deployments/*
\ No newline at end of file
+deployments/*
+release/*
+tests/*
+docs/*
+bbr
+bbsim
+bbsimctl
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 6c2287e..77dd818 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,5 @@
 /bbsim
 /bbsimctl
 logs/*
-release
\ No newline at end of file
+release
+.DS_Store
\ No newline at end of file
diff --git a/Dockerfile.builder.dockerignore b/Dockerfile.builder.dockerignore
new file mode 100644
index 0000000..b9c9f04
--- /dev/null
+++ b/Dockerfile.builder.dockerignore
@@ -0,0 +1,9 @@
+build/*
+deployments/*
+vendor/*
+release/*
+tests/*
+docs/*
+bbr
+bbsim
+bbsimctl
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 20d2723..cbceb9e 100644
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,11 @@
 dep: # @HELP Download the dependencies to the vendor folder
 	GO111MODULE=on go mod vendor
 
-build: dep protos fmt build-bbsim build-bbsimctl build-bbr # @HELP Build the binary
+_build: dep protos fmt build-bbsim build-bbsimctl build-bbr
+
+build: # @HELP Build the binaries (it runs inside a docker container and output the built code on your local file system)
+	docker build -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim-builder:${DOCKER_TAG} -f build/ci/Dockerfile.builder .
+	docker run --rm -v $(shell pwd):/bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim-builder:${DOCKER_TAG} /bin/sh -c "cd /bbsim; make build"
 
 test: dep protos fmt # @HELP Execute unit tests
 	GO111MODULE=on go test -v -mod vendor ./... -covermode count -coverprofile ./tests/results/go-test-coverage.out 2>&1 | tee ./tests/results/go-test-results.out
@@ -41,10 +45,10 @@
 fmt:
 	go fmt ./...
 
-docker-build: # @HELP Build a docker container
+docker-build: # @HELP Build the BBSim docker container (contains BBSimCtl too)
 	docker build -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} -f build/package/Dockerfile .
 
-docker-push: # @HELP Push a docker container to a registry
+docker-push: # @HELP Push the docker container to a registry
 	docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG}
 
 docker-run: # @HELP Runs the container locally (available options: DOCKER_RUN_ARGS="-pon 2 -onu 2" make docker-run)
@@ -90,7 +94,7 @@
         	-o "$@" ./cmd/bbsim
 
 .PHONY: release $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS)
-release: dep protos $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS) # @HELP Release BBSimctl and BBR artifacts
+release: dep protos $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS) # @HELP Creates release ready bynaries for BBSimctl and BBR artifacts
 
 help: # @HELP Print the command options
 	@echo
diff --git a/build/ci/.keep b/build/ci/.keep
deleted file mode 100644
index 9e9aafc..0000000
--- a/build/ci/.keep
+++ /dev/null
@@ -1,13 +0,0 @@
-Copyright 2018-present Open Networking Foundation
-
-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.
diff --git a/build/ci/Dockerfile.builder b/build/ci/Dockerfile.builder
new file mode 100644
index 0000000..0acc2b3
--- /dev/null
+++ b/build/ci/Dockerfile.builder
@@ -0,0 +1,32 @@
+# Copyright 2018-present Open Networking Foundation
+#
+# 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.
+
+# this container is used to provide a build environment so that we don't need
+# the prereqs installed on a CI machine
+
+FROM golang:1.12-stretch
+
+# install prereqs
+ENV PROTOC_VERSION 3.6.1
+ENV PROTOC_SHA256SUM 6003de742ea3fcf703cfec1cd4a3380fd143081a2eb0e559065563496af27807
+
+RUN apt-get update \
+ && apt-get install -y unzip libpcap-dev \
+ && curl -L -o /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip \
+ && echo "$PROTOC_SHA256SUM  /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip" | sha256sum -c - \
+ && unzip /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /tmp/protoc3 \
+ && mv /tmp/protoc3/bin/* /usr/local/bin/ \
+ && mv /tmp/protoc3/include/* /usr/local/include/ \
+ && go get -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
+ && go get -v github.com/golang/protobuf/protoc-gen-go
\ No newline at end of file
diff --git a/tests/bbr.groovy b/tests/bbr.groovy
index a80f64b..9a8137c 100644
--- a/tests/bbr.groovy
+++ b/tests/bbr.groovy
@@ -22,19 +22,18 @@
   }
 
   stages {
-    stage('Download BBR') {
+    stage('Build BBR') {
       steps {
         sh """
-          wget https://github.com/opencord/bbsim/releases/download/v0.0.2/bbr-linux-amd64
-          mv bbr-linux-amd64 bbr
-          chmod a+x bbr
+          make build-in-docker
         """
       }
     }
-    stage('Pull BBSim image from DockerHub') {
+    stage('Build BBSim') {
       steps {
         sh """
           docker pull voltha/bbsim:master
+          DOCKER_REPOSITORY=voltha/ DOCKER_TAG=candidate make docker-build
         """
       }
     }
@@ -43,9 +42,9 @@
         timeout(1) {
           sh """
             docker rm -f bbsim || true
-            DOCKER_REPOSITORY=voltha/ DOCKER_TAG=master DOCKER_RUN_ARGS="-pon 4 -onu 16" make docker-run
+            DOCKER_REPOSITORY=voltha/ DOCKER_TAG=candidate DOCKER_RUN_ARGS="-pon 4 -onu 16" make docker-run
             sleep 5
-            ./bbr -pon 4 -onu 16 2>&1 | tee bbr_16_4.logs
+            ./bbr -pon 4 -onu 16
             docker logs bbsim 2>&1 | tee bbsim_16_4.logs
           """
         }
@@ -56,9 +55,9 @@
         timeout(1) {
           sh """
             docker rm -f bbsim || true
-            DOCKER_REPOSITORY=voltha/ DOCKER_TAG=master DOCKER_RUN_ARGS="-pon 4 -onu 32" make docker-run
+            DOCKER_REPOSITORY=voltha/ DOCKER_TAG=candidate DOCKER_RUN_ARGS="-pon 4 -onu 32" make docker-run
             sleep 5
-            ./bbr -pon 4 -onu 32 2>&1 | tee bbr_32_4.logs
+            ./bbr -pon 4 -onu 32
             docker logs bbsim 2>&1 | tee bbsim_32_4.logs
           """
         }
@@ -69,9 +68,9 @@
         timeout(1) {
           sh """
             docker rm -f bbsim || true
-            DOCKER_REPOSITORY=voltha/ DOCKER_TAG=master DOCKER_RUN_ARGS="-pon 8 -onu 32" make docker-run
+            DOCKER_REPOSITORY=voltha/ DOCKER_TAG=candidate DOCKER_RUN_ARGS="-pon 8 -onu 32" make docker-run
             sleep 5
-            ./bbr -pon 8 -onu 32 2>&1 | tee bbr_32_8.logs
+            ./bbr -pon 8 -onu 32
             docker logs bbsim 2>&1 | tee bbsim_32_8.logs
           """
         }