Update building process 79/64079/2
authorShashank Kumar Shankar <shashank.kumar.shankar@intel.com>
Fri, 31 Aug 2018 22:06:02 +0000 (15:06 -0700)
committerVictor Morales <victor.morales@intel.com>
Fri, 31 Aug 2018 16:33:25 +0000 (09:33 -0700)
The building process differed from the build.sh script and Makefile.
In other words, the docker images were created with different
instructions than development process. This patch centralizes these
instructions in a single source for building binaries.

Change-Id: Ib214d335b0e696be6a1a09d3cb8126a75bdf2da4
Issue-ID: MULTICLOUD-301
Signed-off-by: Shashank Kumar Shankar <shashank.kumar.shankar@intel.com>
Signed-off-by: Victor Morales <victor.morales@intel.com>
deployments/build.sh
deployments/docker-compose.yml
src/k8splugin/Makefile

index 7c2d737..a88ebbc 100755 (executable)
 
 set -o nounset
 set -o pipefail
-set -o xtrace
 
-function generate_binary {
-    export GOPATH="$(pwd)/../"
-    rm -f k8plugin
-    rm -f *.so
-    pushd ../src/k8splugin/
-    dep ensure -v
-    popd
-    for plugin in deployment namespace service; do
-        CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -buildmode=plugin -a -tags netgo -o ./$plugin.so ../src/k8splugin/plugins/$plugin/plugin.go
-    done
-    CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -tags netgo -o ./k8plugin ../src/k8splugin/cmd/main.go
-}
+k8s_path="$(git rev-parse --show-toplevel)"
 
-function build_image {
-    echo "Start build docker image."
-    docker-compose build --no-cache
-}
+echo "Compiling source code"
+pushd $k8s_path/src/k8splugin/
+make
+popd
 
-generate_binary
-build_image
+pushd $k8s_path/deployments
+for file in k8plugin *so; do
+    rm -f $file
+    mv $k8s_path/src/k8splugin/$file .
+done
+
+echo "Starting docker building process"
+docker-compose build --no-cache
+popd
index 0d347b1..6ae7b4e 100644 (file)
@@ -9,7 +9,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-version: '3'
+version: '2'
 
 services:
   multicloud-k8s:
index 586eca9..3aa8223 100644 (file)
@@ -16,11 +16,20 @@ export GOPATH ...
 
 .PHONY: plugins
 
-build: clean dep plugins tests
-deploy: clean dep plugins build_binary tests
 
-build_binary:
-       CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-w' -o ./k8plugin ./cmd/main.go
+all: clean dep
+       CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -buildmode=plugin -a -tags netgo -o ./deployment.so ./plugins/deployment/plugin.go
+       CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -buildmode=plugin -a -tags netgo -o ./namespace.so ./plugins/namespace/plugin.go
+       CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -buildmode=plugin -a -tags netgo -o ./service.so ./plugins/service/plugin.go
+
+       CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -tags netgo -o ./k8plugin ./cmd/main.go
+
+# The following is done this way as each patch on CI runs build and each merge runs deploy. So for build we don't need to build binary and hence
+# no need to create a static binary with additional flags. However, for generating binary, additional build flags are necessary. This if used with
+# mock plugin errors out for unit tests. So the seperation avoids the error.
+
+build: clean dep plugins tests
+deploy: build
 
 tests:
        go test -v ./... -cover