VOL-4883 - Publish a new bbsim release
https://github.com/opencord/bbsim/releases/tag/untagged-6d947de2a6078a1fe175
----------------------------------------------------------------------------
o Draft bbsim release v2.96.8572 created by this patch set.
o All 6cross-compile binaries are now included.
o Change ID + commit message document the release.
o Binaries downloaded/tested using {bbr,bbsim,bbsimctl} --help
Makefile
--------
o Makefile release target is now able to cross compile all binaries:
- bbsimctl cross compiled to arm, darwin, linux and windows.
- release-{bbr, bbsim} only built *-linux-amd64
o Refactor targets into a more modular and hierarchial setup.
o Be sure to create RELEASE_DIR early on localhost so docker
container can create a volume (NFS mount) for building into.
o Display banners when building targets to improve log readability.
o Clean targets updated to remove everything generated.
o Help targets added to document indvidual target logic.
o Makefile logic heavily commented.
makefiles/release/bbr.mk
makefiles/release/bbsim.mk
makefiles/release/bbsimctl.mk
-----------------------------
o Relocate build-* and release-* target logic into named makefiles.
o Update SHELL to set -euo pipefail to detect uninit shell vars.
o Replaced shell/looping logic with true makefile target dependencies:
- shell/loop replaced with a target rule that builds one platform binary.
- Derive a list of targets release/{bbr,bbsim,bbsimctl}-{os}-{arch}
- release: depends on all buildable targets
- release rule can extract arch= and os= from target path being built.
- To simplify logic construct env vars separately into a response file.
- passed as "docker --env-file [x]" VS appending to an ever growing command line.
o Marked more targets as .PHONY so they will always build.
o Added helper target 'onf-publish' for exercising changes in the github-release script.
makefiles/include.mk
--------------------
o Single include for importing all library makefiles.
makefiles/consts.mk
-------------------
o Include fixed values, esp $(quote-single) which is now used to document
o Refactor duplication in GO_* macros into named/reused values to shorten lines.
makefiles/lint
--------------
o Moved lint::docker (hadolint target) into makefiles/lint/docker/*.mk.
o Added makefiles/lint library targets for ability to lint more sources.
makefiles/tools.mk
------------------
o Refactor DOCKER_* and GO_* macros into a named includable makefile.q
Change-Id: I8791317ba0c3f01d047f363e69f8885a03f1a1a1
diff --git a/Makefile b/Makefile
index 68e2183..fdd1d01 100644
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,8 @@
# limitations under the License.
# -----------------------------------------------------------------------
+$(if $(DEBUG),$(warning ENTER))
+
.DEFAULT_GOAL := help
MAKECMDGOALS ?= help
@@ -24,6 +26,12 @@
##--------------------##
##---] INCLUDES [---##
##--------------------##
+include $(MAKEDIR)/include.mk
+include $(MAKEDIR)/release/include.mk
+
+##--------------------##
+##---] INCLUDES [---##
+##--------------------##
help-targets := help-all help HELP
$(if $(filter $(help-targets),$(MAKECMDGOALS))\
,$(eval include $(MAKEDIR)/help.mk))
@@ -31,29 +39,11 @@
##-------------------##
##---] GLOBALS [---##
##-------------------##
-SHELL = bash -e -o pipefail
VERSION ?= $(shell cat ./VERSION)
DIFF ?= $(git diff --shortstat 2> /dev/null | tail -n1)
GIT_STATUS ?= $(shell [ -z "$DIFF" ] && echo "Dirty" || echo "Clean")
-## Docker related -- are these ${shell vars} or $(make macros) ?
-DOCKER_TAG ?= ${VERSION}
-DOCKER_REPOSITORY ?=
-DOCKER_REGISTRY ?=
-DOCKER_RUN_ARGS ?=
-DOCKER_PORTS ?= -p 50070:50070 -p 50060:50060 -p 50071:50071 -p 50072:50072 -p 50073:50073 -p 50074:50074 -p 50075:50075
-TYPE ?= minimal
-
-# tool containers
-VOLTHA_TOOLS_VERSION ?= 2.3.1
-
-GO = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golang go
-GO_SH = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golang sh -c '# fix-editor-colorization-quote(')
-GO_JUNIT_REPORT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app -i voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-go-junit-report go-junit-report
-GOCOVER_COBERTURA = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app/src/github.com/opencord/bbsim -i voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-gocover-cobertura gocover-cobertura
-GOLANGCI_LINT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golangci-lint golangci-lint
-HADOLINT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-hadolint hadolint
-PROTOC = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-protoc protoc
+include $(MAKEDIR)/tools.mk # Command macros for DOCKER_*, GO_*
## use local vars to shorten paths
bbsim-tag = ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG}
@@ -66,16 +56,37 @@
protos: api/bbsim/bbsim.pb.go api/bbsim/bbsim.pb.gw.go api/legacy/bbsim.pb.go api/legacy/bbsim.pb.gw.go api/bbsim/bbsim_dmi.pb.go # @HELP Build proto files
-.PHONY: build
-build: protos build-bbsim build-bbsimctl build-bbr
+## -----------------------------------------------------------------------
+## Intent: Build tools for use on localhost
+## -----------------------------------------------------------------------
+build-target-deps += build-bbsim
+build-target-deps += build-bbsimctl
+build-target-deps += build-bbr
+
+.PHONY: build $(build-target-deps)
+build: protos $(build-target-deps)
+
+## -----------------------------------------------------------------------
+## Intent: Cross-compile binaries for release
+## -----------------------------------------------------------------------
+release-target-deps += release-bbr
+release-target-deps += release-bbsim
+release-target-deps += release-bbsimctl
+
+.PHONY: release $(release-target-deps)
+release: $(release-target-deps)
## lint and unit tests
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
lint-dockerfile:
@echo "Running Dockerfile lint check..."
@${HADOLINT} $$(find ./build -name "Dockerfile*")
@echo "Dockerfile lint check OK"
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
lint-mod:
@echo "Running dependency check..."
@${GO} mod verify
@@ -90,8 +101,12 @@
@[[ `git ls-files --exclude-standard --others go.mod go.sum vendor` == "" ]] || (echo "ERROR: Untracked files detected after running go mod tidy / go mod vendor" && git status -- go.mod go.sum vendor && git checkout -- go.mod go.sum vendor && exit 1)
@echo "Vendor check OK."
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
lint: lint-mod lint-dockerfile
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
sca:
@$(RM) -r ./sca-report
@mkdir -p ./sca-report
@@ -100,8 +115,12 @@
@echo ""
@echo "Static code analysis OK"
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
test: docs-lint test-unit test-bbr
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
test-unit: clean local-omci-lib-go # @HELP Execute unit tests
@echo "Running unit tests..."
@mkdir -p ./tests/results
@@ -111,23 +130,34 @@
${GOCOVER_COBERTURA} < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
exit $$RETURN
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
test-bbr: release-bbr docker-build # @HELP Validate that BBSim and BBR are working together
DOCKER_RUN_ARGS="-pon 2 -onu 2" $(MAKE) docker-run
sleep 5
./$(RELEASE_DIR)/$(RELEASE_BBR_NAME)-linux-amd64 -pon 2 -onu 2 -logfile tmp.logs
docker $(RM) -f bbsim
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
mod-update: # @HELP Download the dependencies to the vendor folder
${GO} mod tidy
${GO} mod vendor
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
docker-build: local-omci-lib-go local-protos# @HELP Build the BBSim docker container (contains BBSimCtl too)
docker build \
-t "$(bbsim-tag)" \
-f build/package/Dockerfile .
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
docker-push: # @HELP Push the docker container to a registry
docker push "$(bbsim-tag)"
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
docker-kind-load:
@if [ "`kind get clusters | grep voltha-$(TYPE)`" = '' ]; then echo "no voltha-$(TYPE) cluster found" && exit 1; fi
kind load docker-image "$(bbsim-tag)" --name=voltha-$(TYPE) --nodes $(shell kubectl get nodes --template='{{range .items}}{{.metadata.name}},{{end}}' | sed 's/,$$//')
@@ -149,10 +179,14 @@
docker-run-cmd += "$(bbsim-tag)" /app/bbsim
docker-run-cmd += ${DOCKER_RUN_ARGS}
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
docker-run: # @HELP Runs the container locally (available options: DOCKER_RUN_ARGS="-pon 2 -onu 2" make docker-run)
docker ps
$(docker-run-cmd)
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
docker-run-dev: # @HELP Runs the container locally (intended for development purposes, not in detached mode)
$(docker-run-cmd)
@@ -164,68 +198,11 @@
$(MAKE) -C docs html
@echo -e "\nBBSim documentation generated in file://${PWD}/docs/build/html/index.html"
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
docs-lint:
$(MAKE) -C docs lint
-# Release related items
-# Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH
-# Inspired by: https://github.com/kubernetes/minikube/releases
-RELEASE_DIR ?= release
-RELEASE_OS_ARCH ?= linux-amd64 linux-arm64 windows-amd64 darwin-amd64
-
-RELEASE_BBR_NAME ?= bbr
-RELEASE_BBSIM_NAME ?= bbsim
-RELEASE_BBSIMCTL_NAME ?= bbsimctl
-
-release-bbr:
- @echo "$(RELEASE_BBR_NAME)-linux-amd64"
- ${GO} build -mod vendor \
- -ldflags "-w -X main.buildTime=$(shell date +%Y/%m/%d-%H:%M:%S) \
- -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
- -X main.gitStatus=${GIT_STATUS} \
- -X main.version=${VERSION}" \
- -o "$(RELEASE_DIR)/$(RELEASE_BBR_NAME)-linux-amd64" ./cmd/bbr
-
-release-bbsim:
- @echo "$(RELEASE_BBSIM_NAME)-linux-amd64"
- ${GO} build -mod vendor \
- -ldflags "-w -X main.buildTime=$(shell date +%Y/%m/%d-%H:%M:%S) \
- -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
- -X main.gitStatus=${GIT_STATUS} \
- -X main.version=${VERSION}" \
- -o "$(RELEASE_DIR)/$(RELEASE_BBSIM_NAME)-linux-amd64" ./cmd/bbsim
-
-release-bbsimctl:
- @echo "** $(MAKE): processing target [$@]"
- ${GO_SH} set -eo pipefail; \
- for os_arch in ${RELEASE_OS_ARCH}; do \
- echo "$(RELEASE_BBSIMCTL_NAME)-$$os_arch"; \
- GOOS="$${os_arch%-*}" GOARCH="$${os_arch#*-}" go build -mod vendor \
- -ldflags "-w -X github.com/opencord/bbsim/internal/bbsimctl/config.BuildTime=$(shell date +%Y/%m/%d-%H:%M:%S) \
- -X github.com/opencord/bbsim/internal/bbsimctl/config.CommitHash=$(shell git log --pretty=format:%H -n 1) \
- -X github.com/opencord/bbsim/internal/bbsimctl/config.GitStatus=${GIT_STATUS} \
- -X github.com/opencord/bbsim/internal/bbsimctl/config.Version=${VERSION}" \
- -o "$(RELEASE_DIR)/$(RELEASE_BBSIMCTL_NAME)-$$os_arch" ./cmd/bbsimctl; \
- done'
-# fix-editor-colorization-quote(')
-
-## -----------------------------------------------------------------------
-## -----------------------------------------------------------------------
-release-deps += release-bbr
-release-deps += release-bbsim
-release-deps += release-bbsimctl
-.PHONY: release $(release-deps)
-release: release-init $(release-deps) # @HELP Creates release ready bynaries for BBSimctl and BBR artifacts
-
-$(release-deps) : release-init
-
-release-init:
- @echo "** $(MAKE): processing target [$@]"
- ${GO_SH} set -eo pipefail\
-; echo "PWD: $$(/bin/pwd)"\
-; mkdir -p $(RELEASE_DIR)'
-# fix-editor-colorization-quote(')
-
## -----------------------------------------------------------------------
## -----------------------------------------------------------------------
swagger-deps += docs/swagger/bbsim/bbsim.swagger.json
@@ -242,6 +219,8 @@
cp -r ${LOCAL_OMCI_LIB_GO}/* vendor/github.com/opencord/omci-lib-go
endif
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
local-protos: ## Copies a local version of the voltha-protos dependency into the vendor directory
ifdef LOCAL_PROTOS
$(RM) -r vendor/github.com/opencord/voltha-protos/v5/go
@@ -250,44 +229,26 @@
$(RM) -r vendor/github.com/opencord/voltha-protos/v5/go/vendor
endif
-# Internals
-
-clean:
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+clean ::
@$(RM) -f bbsim
@$(RM) -f bbsimctl
@$(RM) -f bbr
@$(RM) -r tools/bin
- @$(RM) -r release/*
+ @$(RM) -r release
-build-bbr: local-omci-lib-go local-protos
- @go build -mod vendor \
- -ldflags "-w -X main.buildTime=$(shell date +%Y/%m/%d-%H:%M:%S) \
- -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
- -X main.gitStatus=${GIT_STATUS} \
- -X main.version=${VERSION}" \
- ./cmd/bbr
+sterile :: clean
-build-bbsim:
- @go build -mod vendor \
- -ldflags "-w -X main.buildTime=$(shell date +%Y/%m/%d-%H:%M:%S) \
- -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
- -X main.gitStatus=${GIT_STATUS} \
- -X main.version=${VERSION}" \
- ./cmd/bbsim
-
-build-bbsimctl:
- @go build -mod vendor \
- -ldflags "-w -X github.com/opencord/bbsim/internal/bbsimctl/config.BuildTime=$(shell date +%Y/%m/%d-%H:%M:%S) \
- -X github.com/opencord/bbsim/internal/bbsimctl/config.CommitHash=$(shell git log --pretty=format:%H -n 1) \
- -X github.com/opencord/bbsim/internal/bbsimctl/config.GitStatus=${GIT_STATUS} \
- -X github.com/opencord/bbsim/internal/bbsimctl/config.Version=${VERSION}" \
- ./cmd/bbsimctl
-
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
setup_tools:
@echo "Downloading dependencies..."
@${GO} mod download github.com/grpc-ecosystem/grpc-gateway github.com/opencord/voltha-protos/v5
@echo "Dependencies downloaded OK"
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
VOLTHA_PROTOS ?= $(shell ${GO} list -f '{{ .Dir }}' -m github.com/opencord/voltha-protos/v5)
GOOGLEAPI ?= $(shell ${GO} list -f '{{ .Dir }}' -m github.com/grpc-ecosystem/grpc-gateway)
@@ -299,6 +260,8 @@
--go_out=plugins=grpc:./ --go_opt=paths=source_relative \
$<
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
api/bbsim/bbsim_dmi.pb.go: api/bbsim/bbsim_dmi.proto setup_tools
@echo $@
@${PROTOC} -I. \
@@ -306,6 +269,8 @@
--go_out=plugins=grpc:./ --go_opt=paths=source_relative \
$<
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
api/bbsim/bbsim.pb.go api/bbsim/bbsim.pb.gw.go: api/bbsim/bbsim.proto api/bbsim/bbsim.yaml setup_tools
@echo $@
@${PROTOC} -I. \
@@ -315,6 +280,8 @@
--grpc-gateway_out=logtostderr=true,paths=source_relative,grpc_api_configuration=api/bbsim/bbsim.yaml,allow_delete_body=true:./ \
$<
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
api/legacy/bbsim.pb.go api/legacy/bbsim.pb.gw.go: api/legacy/bbsim.proto setup_tools
@echo $@
@${PROTOC} -I. \
@@ -325,6 +292,8 @@
--grpc-gateway_out=logtostderr=true,paths=source_relative,allow_delete_body=true:./ \
$<
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
docs/swagger/bbsim/bbsim.swagger.json: api/bbsim/bbsim.yaml setup_tools
@echo $@
@${PROTOC} -I ./api \
@@ -333,6 +302,8 @@
--swagger_out=logtostderr=true,allow_delete_body=true,disable_default_errors=true,grpc_api_configuration=$<:docs/swagger/ \
api/bbsim/bbsim.proto
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
docs/swagger/leagacy/bbsim.swagger.json: api/legacy/bbsim.proto setup_tools
@echo $@
@${PROTOC} -I ./api \
@@ -341,4 +312,20 @@
--swagger_out=logtostderr=true,allow_delete_body=true,disable_default_errors=true:docs/swagger/ \
$<
+## -----------------------------------------------------------------------
+## Intent: Helper target used to exercise release script changes
+## -----------------------------------------------------------------------
+onf-publish-args := $(null)
+onf-publish-args += --draft
+onf-publish-args += --gen-version
+onf-publish-args += --repo-org opencord
+onf-publish-args += --repo-name bbsim
+onf-publish-args += --git-hostname github.com
+onf-publish-args += --pac $(HOME)/.ssh/github.com/pacs/onf-voltha
+# onf-publish-args += --notes-file "$(PWD)/release-notes"
+onf-publish:
+ ../ci-management/jjb/shell/github-release.sh $(onf-publish-args) 2>&1 | tee $@.log
+
+$(if $(DEBUG),$(warning LEAVE))
+
# [EOF]