aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile27
-rw-r--r--build/Makefile4
-rwxr-xr-xbuild_image.sh (renamed from build/build_image.sh)33
3 files changed, 47 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 7883b7f..c556faa 100644
--- 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
index d459215..0000000
--- a/build/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-SHELL := /bin/bash
-
-build:
- ./build_image.sh
diff --git a/build/build_image.sh b/build_image.sh
index 9b44a47..fb3b19b 100755
--- a/build/build_image.sh
+++ b/build_image.sh
@@ -18,14 +18,17 @@
#
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