testing JJB : added golang installation cmds in Makefile 99/139599/15
authormuraliparthatechm <muraliparthasarathy.k@techmahindra.com>
Fri, 29 Nov 2024 11:19:58 +0000 (12:19 +0100)
committermuraliparthatechm <muraliparthasarathy.k@techmahindra.com>
Fri, 13 Dec 2024 16:37:13 +0000 (17:37 +0100)
Issue-ID: POLICY-5167
Change-Id: I72b3d94f8688670f5e66e78455db4786b4d84545
Signed-off-by: muraliparthatechm <muraliparthasarathy.k@techmahindra.com>
Makefile
build/Makefile [deleted file]
build_image.sh [moved from build/build_image.sh with 60% similarity]

index 7883b7f..c556faa 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,31 +1,42 @@
 PWD := $(shell pwd)
 PLATFORM := linux
 BINARY := opa-pdp
+GO_TEST_CLEAN ?= go clean -cache -testcache -modcache -i -r
+RETRY_COUNT ?= 3
+SLEEP_BETWEEN_RETRIES ?= 5
 
 
 all: test build
-deploy: test build
 
-build: build_image
+build: install clean go_build test cover
 
-deploy: build
+deploy: install clean build_image
 
 .PHONY: test
-test: clean
+test:
        @go test -v ./...
 
 format:
        @go fmt ./...
 
 clean:
+       @echo "Cleaning up..."
+       rm -f go.tar.gz
        @rm -f $(BINARY)
+       @echo "Done."
 
 .PHONY: cover
 cover:
        @go test -p 2 ./... -coverprofile=coverage.out
-       @go tool cover -html=coverage.out -o coverage.html
+       @go tool cover -func=coverage.out -o coverage.html
+
+.PHONY: install clean
+
+install:
+       ./build_image.sh install
 
 build_image:
-       docker build -f  Dockerfile  -t policy-opa-pdp:1.0.0 .
-       docker tag policy-opa-pdp:1.0.0 nexus3.onap.org:10003/onap/policy-opa-pdp:latest
-       docker tag nexus3.onap.org:10003/onap/policy-opa-pdp:latest nexus3.onap.org:10003/onap/policy-opa-pdp:1.0.0
+       ./build_image.sh build
+
+go_build:
+       CGO_ENABED=0 GOOS=$(PLATFORM) GOARCH=amd64 go build -ldflags "-w -s" -o $(PWD)/$(BINARY) cmd/opa-pdp/opa-pdp.go
diff --git a/build/Makefile b/build/Makefile
deleted file mode 100644 (file)
index d459215..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-SHELL := /bin/bash
-
-build:
-       ./build_image.sh
similarity index 60%
rename from build/build_image.sh
rename to build_image.sh
index 9b44a47..fb3b19b 100755 (executable)
 #
 
 export IMAGE_NAME="nexus3.onap.org:10003/onap/policy-opa-pdp"
-VERSION_FILE="../version"
+VERSION_FILE="version"
+GO_VERSION="1.23.3"
+INSTALL_DIR="/usr/local"
+GO_URL="https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz"
 
 
 # Check for the version file
 # If it exists, load the version from that file
 # If not found, then use the current version as 1.1.0 for docker images
 if [ -f "$VERSION_FILE" ]; then
-    VERSION=`cat ../version|xargs echo`;
+    VERSION=`cat version|xargs echo`;
 else
     VERSION=1.0.0;
 fi
@@ -33,8 +36,8 @@ fi
 
 function  _build_docker_and_push_image {
     local tag_name=${IMAGE_NAME}:${VERSION}
-    
-    docker build -f  Dockerfile  -t policy-opa-pdp:${VERSION} ../.
+
+    docker build -f  Dockerfile  -t policy-opa-pdp:${VERSION} .
     echo "Start push {$tag_name}"
     docker tag policy-opa-pdp:${VERSION} ${IMAGE_NAME}:latest
     docker push ${IMAGE_NAME}:latest
@@ -42,4 +45,24 @@ function  _build_docker_and_push_image {
     docker push ${tag_name}
 }
 
-_build_docker_and_push_image
+function _install_golang_latest {
+
+     echo "Downloading Go ${GO_VERSION}..."
+     curl -fsSL ${GO_URL} -o go.tar.gz
+     echo "Extracting Go ${GO_VERSION}..."
+     sudo rm -rf ${INSTALL_DIR}/go
+     sudo tar -C ${INSTALL_DIR} -xzf go.tar.gz
+     echo "Adding Go to PATH..."
+     echo "export PATH=${INSTALL_DIR}/go/bin:$PATH" >> ~/.profile
+     echo "Reloading PATH for verification..."
+     export PATH=${INSTALL_DIR}/go/bin:$PATH; ${INSTALL_DIR}/go/bin/go version
+     echo "Go ${GO_VERSION} installed successfully. Run 'source ~/.profile' to update PATH."
+
+}
+
+
+if [ $1 == "build" ] ; then
+   _build_docker_and_push_image
+else
+   _install_golang_latest
+fi