Improve compilation process 95/65095/1
authorVictor Morales <victor.morales@intel.com>
Thu, 6 Sep 2018 15:11:19 +0000 (08:11 -0700)
committerVictor Morales <victor.morales@intel.com>
Thu, 6 Sep 2018 15:11:19 +0000 (08:11 -0700)
The current architecture offers the possibility to add more plugins
and extend the its functionality. This flexibility has to be supported
during the compilation process. This change modify the Makefile to find
plugins and compile them.

It also adds a start.sh script which allows to run MultiCloud services
without the need of packaging their binaries in a container.

Change-Id: I9271c51daa4fd9156717e37f1818886c72e36c27
Signed-off-by: Victor Morales <victor.morales@intel.com>
Issue-ID: MULTICLOUD-301

deployments/build.sh
deployments/start.sh [new file with mode: 0755]
src/k8splugin/Makefile
vagrant/tests/plugin.sh

index a88ebbc..3a6ea85 100755 (executable)
@@ -18,12 +18,15 @@ pushd $k8s_path/src/k8splugin/
 make
 popd
 
-pushd $k8s_path/deployments
-for file in k8plugin *so; do
-    rm -f $file
-    mv $k8s_path/src/k8splugin/$file .
-done
+rm -f k8plugin *so
+mv $k8s_path/src/k8splugin/k8plugin .
+mv $k8s_path/src/k8splugin/plugins/*.so .
+
+echo "Cleaning previous execution"
+docker-compose kill
+image=$(grep "image.*k8plugin" docker-compose.yml)
+docker images ${image#*:} -q | xargs docker rmi -f
+docker ps -a --filter "status=exited" -q | xargs docker rm
 
 echo "Starting docker building process"
 docker-compose build --no-cache
-popd
diff --git a/deployments/start.sh b/deployments/start.sh
new file mode 100755 (executable)
index 0000000..0a14fc3
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/bash
+# SPDX-license-identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2018 Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+set -o nounset
+set -o pipefail
+
+k8s_path="$(git rev-parse --show-toplevel)"
+export GOPATH=$k8s_path
+
+export CSAR_DIR=/opt/csar
+export KUBE_CONFIG_DIR=/opt/kubeconfig
+export DATABASE_TYPE=consul
+export DATABASE_IP=consul-svr
+export PLUGINS_DIR=$k8s_path/src/k8splugin/plugins
+
+echo "Starting consul services"
+docker-compose kill
+docker-compose up -d consul
+echo "Compiling source code"
+
+pushd $k8s_path/src/k8splugin/
+make clean
+make plugins
+go run cmd/main.go
+popd
index 542de95..6171d8c 100644 (file)
@@ -16,10 +16,9 @@ export GOPATH ...
 
 
 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
+       CGO_ENABLED=1 GOOS=linux GOARCH=amd64
+       @find plugins -type d -not -path plugins -exec sh -c "ls {}/plugin.go | xargs go build -buildmode=plugin -a -tags netgo -o $(basename {}).so" \;
+       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
@@ -36,9 +35,7 @@ format:
        go fmt ./...
 
 plugins:
-       go build -buildmode=plugin -o ./plugins/deployment/deployment.so ./plugins/deployment/plugin.go
-       go build -buildmode=plugin -o ./plugins/namespace/namespace.so ./plugins/namespace/plugin.go
-       go build -buildmode=plugin -o ./plugins/service/service.so ./plugins/service/plugin.go
+       @find plugins -type d -not -path plugins -exec sh -c "ls {}/plugin.go | xargs go build -buildmode=plugin -o $(basename {}).so" \;
 
 dep:
        go get -u $(DEPENDENCIES)
index a40cb60..3ff3a54 100755 (executable)
@@ -33,7 +33,7 @@ fi
 if [[ $(docker ps -q --all --filter "name=aai") ]]; then
     docker rm aai -f
 fi
-docker run --name aai -v $(pwd)/output:/tmp/generic_sim/ -v $(pwd)/generic_simulator/aai/:/etc/generic_sim/ -p 8443:8080 -d generic_sim
+docker run --name aai -v $(mktemp):/tmp/generic_sim/ -v $(pwd)/generic_simulator/aai/:/etc/generic_sim/ -p 8443:8080 -d generic_sim
 
 vnf_id_list=$(curl -s "${base_url}${cloud_region_id}/${namespace}" | jq -r '.vnf_id_list')
 
@@ -94,4 +94,4 @@ payload_raw="
 }
 "
 payload=$(echo $payload_raw | tr '\n' ' ')
-curl -v -X POST -d "$payload" "${base_url}"
+curl -v -d "$payload" "${base_url}"