From 75c508c18f671ab4c72aa77a4bce64ba1e73a76d Mon Sep 17 00:00:00 2001 From: Kevin O'Donnell Date: Wed, 7 Jul 2021 16:35:44 -0400 Subject: [PATCH] ci: update build pattern Signed-off-by: Kevin O'Donnell --- Dockerfile | 13 +- Jenkinsfile | 9 +- Makefile | 30 ++-- scripts/build | 2 +- standard_defs.mk | 381 +++++++++++++++++++++++++++-------------------- 5 files changed, 244 insertions(+), 191 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1103308..f543cdb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,5 @@ -FROM golang:1.16-alpine as builder -RUN apk update && \ - apk upgrade && \ - apk add \ - bash \ - gcc -COPY . /tmp/catenasys/sxtctl -WORKDIR /tmp/catenasys/sxtctl -RUN bash ./scripts/build - FROM scratch WORKDIR / -COPY --from=builder /tmp/catenasys/sxtctl/target /target + +COPY ./target /target ENTRYPOINT ["/target/sxtctl-linux-amd64"] diff --git a/Jenkinsfile b/Jenkinsfile index f08df54..f9414c1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -87,9 +87,12 @@ pipeline { expression { env.BRANCH_NAME == "master" } } steps { - sh ''' - make clean publish - ''' + withCredentials([string(credentialsId: 'btp-build-github-pat', + variable: 'GITHUB_TOKEN')]) { + sh ''' + make clean publish + ''' + } } } } diff --git a/Makefile b/Makefile index ed63297..6e6d115 100644 --- a/Makefile +++ b/Makefile @@ -1,29 +1,29 @@ MAKEFILE_DIR := $(dir $(lastword $(MAKEFILE_LIST))) include $(MAKEFILE_DIR)/standard_defs.mk -clean: clean_go +clean: clean_build_go distclean: clean_docker -build: $(MARKERS)/build_docker +build: $(MARKERS)/build_go $(MARKERS)/build_docker -analyze: analyze_fossa +test: $(MARKERS)/test_go -.PHONY: build_dev -build_dev: - (cd ./cmd/sxtctl && go build .) +analyze: analyze_go analyze_fossa -$(MARKERS)/build_go: $(MARKERS)/build_toolchain_docker - $(TOOL) -w /project/cmd/sxtctl $(TOOLCHAIN_IMAGE) go build +publish: gh-create-draft-release + if [ "$(RELEASABLE)" = "yes" ]; then \ + $(GH_RELEASE) upload $(VERSION) target/* ; \ + fi -.PHONY: clean_go -clean_go: $(MARKERS)/build_toolchain_docker - $(TOOL) $(TOOLCHAIN_IMAGE) go clean +.PHONY: clean_docker +clean_docker: clean_toolchain_docker + docker rmi -f sxtctl:$(ISOLATION_ID) -$(MARKERS)/build_docker: +$(MARKERS)/build_docker: $(MARKERS)/build_go docker build -t sxtctl:$(ISOLATION_ID) . touch $@ -.PHONY: clean_docker -clean_docker: clean_toolchain_docker - docker rmi -f sxtctl:$(ISOLATION_ID) +.PHONY: analyze_dive +analyze_dive: + $(DIVE_ANALYZE) sxtctl:$(ISOLATION_ID) diff --git a/scripts/build b/scripts/build index e29ebad..e040548 100755 --- a/scripts/build +++ b/scripts/build @@ -9,7 +9,7 @@ export CGO_ENABLED=0 export GO111MODULE=on rm -rf "$TARGETDIR" mkdir -p "$TARGETDIR" -for ARCH in "darwin-amd64" "darwin-arm64" "linux-amd64" "windows-amd64"; do +for ARCH in "darwin-amd64" "linux-arm64" "darwin-arm64" "linux-amd64" "windows-amd64"; do echo "building sxtctl-$ARCH" IFS='-' read -r -a arArch <<<$ARCH export GOOS=${arArch[0]} diff --git a/standard_defs.mk b/standard_defs.mk index 8ea23e7..15d1b62 100644 --- a/standard_defs.mk +++ b/standard_defs.mk @@ -4,33 +4,30 @@ PWD = $(shell pwd) export MAKE_BIN ?= $(PWD)/bin ORGANIZATION ?= $(shell git remote show -n origin | grep Fetch | \ - awk '{print $$NF}' | sed -e 's/git@github.com://' | \ - sed -e 's@https://github.com/@@' | \ - awk -F'[/.]' '{print $$1}' ) + awk '{print $$NF}' | sed -e 's/git@github.com://' | \ + sed -e 's@https://github.com/@@' | awk -F'[/.]' '{print $$1}' ) REPO ?= $(shell git remote show -n origin | grep Fetch | awk '{print $$NF}' | \ - sed -e 's/git@github.com://' | \ - sed -e 's@https://github.com/@@' | \ - awk -F'[/.]' '{print $$2}' ) -BRANCH_NAME ?= $(shell git symbolic-ref -q HEAD |sed -e \ - 's@refs/heads/@@') -SAFE_BRANCH_NAME ?= $(shell if [ -n "$$BRANCH_NAME" ]; then\ - echo $$BRANCH_NAME; \ - else \ - git symbolic-ref -q HEAD|sed -e \ - 's@refs/heads/@@'|sed -e 's@/@_@g'; \ - fi) + sed -e 's/git@github.com://' | sed -e 's@https://github.com/@@' | \ + awk -F'[/.]' '{print $$2}' ) +BRANCH_NAME ?= $(shell git symbolic-ref -q HEAD |sed -e 's@refs/heads/@@') +SAFE_BRANCH_NAME ?= $(shell if [ -n "$$BRANCH_NAME" ]; then echo $$BRANCH_NAME;\ + else git symbolic-ref -q HEAD|sed -e 's@refs/heads/@@'|sed -e 's@/@_@g'; fi) PR_KEY=$(shell echo $(BRANCH_NAME) | cut -c4-) VERSION ?= $(shell git describe | cut -c2- ) LONG_VERSION ?= $(shell git describe --long --dirty |cut -c2- ) UID := $(shell id -u) GID := $(shell id -g) +RELEASABLE != if [ "$(LONG_VERSION)" = "$(VERSION)" ] || \ + (echo "$(LONG_VERSION)" | grep -q dirty); then \ + echo "no"; else echo "yes"; fi + MARKERS = markers ## # SonarQube0 ## -SONAR_HOST_URL ?= https://sonarqube.dev.catenasys.com +SONAR_HOST_URL ?= https://sonarcloud.io SONAR_AUTH_TOKEN ?= ## @@ -40,34 +37,69 @@ MAVEN_SETTINGS ?= $(shell if [ -r $(HOME)/.m2/settings.xml ]; then \ echo $(HOME)/.m2/settings.xml; else echo ""; fi) MAVEN_REVISION != if [ "$(LONG_VERSION)" = "$(VERSION)" ] || \ - (echo "$(LONG_VERSION)" | grep -q dirty); then \ - bump_ver=$(VERSION); \ - if [ -x bin/semver ]; then \ - bump_ver=$$(bin/semver bump patch $(VERSION))-SNAPSHOT; \ - elif command -v semver >/dev/null; then \ - bump_ver=$$(command semver bump patch $(VERSION))-SNAPSHOT; \ - fi; \ - echo $$bump_ver ; fi - -cmd_test: - if [ -r $(HOME)/.m2/settings.xml ]; then echo $(HOME)/.m2/settings.xml; else echo ""; fi + (echo "$(LONG_VERSION)" | grep -q dirty); then \ + bump_ver=$(VERSION); \ + if [ -x bin/semver ]; then \ + bump_ver=$$(bin/semver bump patch $(VERSION))-SNAPSHOT; \ + elif command -v semver >/dev/null; then \ + bump_ver=$$(command semver bump patch $(VERSION))-SNAPSHOT; \ + fi; \ + echo $$bump_ver ; \ + else \ + echo $(VERSION); \ + fi MAVEN_REPO_BASE ?= https://dev.catenasys.com/repository/catenasys-maven MAVEN_REPO_TARGET != if [ "$(LONG_VERSION)" = "$(VERSION)" ] || \ - (echo "$(LONG_VERSION)" | grep -q dirty); then \ - echo snapshots; \ + (echo "$(LONG_VERSION)" | grep -q dirty); then echo snapshots; \ else \ - echo releases; \ + echo releases;\ fi MAVEN_UPDATE_RELEASE_INFO != if [ "$(LONG_VERSION)" = "$(VERSION)" ] || \ (echo "$(LONG_VERSION)" | grep -q dirty); then \ - echo false; \ + echo false; \ else \ - echo true; \ + echo true; \ fi MAVEN_DEPLOY_TARGET = \ $(MAVEN_REPO_TARGET)::default::$(MAVEN_REPO_BASE)-$(MAVEN_REPO_TARGET) +## +# Docker based toolchain +## +DOCKER_RUN = docker run --rm +DOCKER_RUN_USER = $(DOCKER_RUN) --user $(UID):$(GID) +DOCKER_RUN_ROOT = $(DOCKER_RUN) --user 0:0 +DOCKER_RUN_DEFAULT = $(DOCKER_RUN) +DOCKER_SOCK ?= /var/run/docker.sock + +#TOOLCHAIN_IMAGE = toolchain:$(ISOLATION_ID) +TOOLCHAIN_IMAGE := blockchaintp/toolchain:latest +TOOLCHAIN_HOME := /home/toolchain + +TOOL_VOLS = -v toolchain-home-$(ISOLATION_ID):/home/toolchain \ + -v $(PWD):/project + +TOOL = $(DOCKER_RUN_USER) -e GITHUB_TOKEN -e MAVEN_HOME=/home/toolchain/.m2 $(TOOL_VOLS) \ + -w $${WORKDIR:-/project} +TOOL_DEFAULT = $(DOCKER_RUN_DEFAULT) -e GITHUB_TOKEN \ + -e MAVEN_HOME=/home/toolchain/.m2 $(TOOL_VOLS) -w $${WORKDIR:-/project} + +TOOLCHAIN := $(TOOL) \ + $(shell if [ -n "$(MAVEN_SETTINGS)" ]; then echo -v \ + $(MAVEN_SETTINGS):$(TOOLCHAIN_HOME)/.m2/settings.xml; fi) $(TOOLCHAIN_IMAGE) +DOCKER_MVN := $(TOOLCHAIN) mvn -Drevision=$(MAVEN_REVISION) -B +BUSYBOX := $(DOCKER_RUN_USER) $(TOOL_VOLS) \ + $(shell if [ -n "$(MAVEN_SETTINGS)" ]; then echo -v \ + $(MAVEN_SETTINGS):$(TOOLCHAIN_HOME)/.m2/settings.xml; fi) busybox:latest +BUSYBOX_ROOT := $(DOCKER_RUN_ROOT) $(TOOL_VOLS) \ + $(shell if [ -n "$(MAVEN_SETTINGS)" ]; then echo -v \ + $(MAVEN_SETTINGS):$(TOOLCHAIN_HOME)/.m2/settings.xml; fi) busybox:latest + +DIVE_ANALYZE = $(TOOL) -v $(DOCKER_SOCK):/var/run/docker.sock \ + --user toolchain:$(shell getent group docker|awk -F: '{print $$3}') \ + $(TOOLCHAIN_IMAGE) dive --ci + ## # BEGIN Standardized directives ## @@ -114,12 +146,17 @@ archive: $(MARKERS) archive_git .PHONY: publish publish: package +# Run up a useful local environment of this build +.PHONY: run +run: package + .PHONY: acquire_project acquire_project: mkdir -p project if [ -n "$(PROJECT_GIT_URL)" ]; then \ - git clone $(PROJECT_GIT_URL) project ; \ - cd project; git checkout $(PROJECT_BRANCH) ; \ + git clone $(PROJECT_GIT_URL) project ; \ + cd project; \ + git checkout $(PROJECT_BRANCH) ; \ fi .PHONY: clean_project @@ -132,164 +169,154 @@ project_%: .PHONY: analyze_fossa analyze_fossa: - if [ -z "$(CHANGE_BRANCH)" ]; then \ - $(TOOL) -e FOSSA_API_KEY blockchaintp/fossa:latest fossa analyze \ - --verbose --no-ansi -b ${BRANCH_NAME}; \ - $(TOOL) -e FOSSA_API_KEY blockchaintp/fossa:latest fossa test \ - --verbose --no-ansi -b ${BRANCH_NAME}; \ - else \ - $(TOOL) -e FOSSA_API_KEY blockchaintp/fossa:latest fossa analyze \ - --verbose --no-ansi -b ${CHANGE_BRANCH}; \ - $(TOOL) -e FOSSA_API_KEY blockchaintp/fossa:latest fossa test \ - --verbose --no-ansi -b ${CHANGE_BRANCH}; \ - fi + if [ -z "$(CHANGE_BRANCH)" ]; then \ + $(TOOL_DEFAULT) -e FOSSA_API_KEY blockchaintp/fossa:latest fossa analyze --verbose \ + --no-ansi -b ${BRANCH_NAME}; \ + $(TOOL_DEFAULT) -e FOSSA_API_KEY blockchaintp/fossa:latest fossa test --verbose \ + --no-ansi -b ${BRANCH_NAME}; \ + else \ + $(TOOL_DEFAULT) -e FOSSA_API_KEY blockchaintp/fossa:latest fossa analyze --verbose \ + --no-ansi -b ${CHANGE_BRANCH}; \ + $(TOOL_DEFAULT) -e FOSSA_API_KEY blockchaintp/fossa:latest fossa test --verbose \ + --no-ansi -b ${CHANGE_BRANCH}; \ + fi + +.PHONY: analyze_go +analyze_go: $(MARKERS)/build_toolchain_docker + $(TOOLCHAIN) bash -c "go vet ./..." # Maven Version of Sonar Analysis .PHONY: analyze_sonar_mvn analyze_sonar_mvn: $(MARKERS)/build_toolchain_docker [ -z "$(SONAR_AUTH_TOKEN)" ] || \ - if [ -z "$(CHANGE_BRANCH)" ]; then \ - $(DOCKER_MVN) package sonar:sonar \ - -Dsonar.organization=$(ORGANIZATION) \ - -Dsonar.projectKey=$(ORGANIZATION)_$(REPO) \ - -Dsonar.projectName="$(ORGANIZATION)/$(REPO)" \ - -Dsonar.branch.name=$(BRANCH_NAME) \ - -Dsonar.projectVersion=$(VERSION) \ - -Dsonar.host.url=$(SONAR_HOST_URL) \ - -Dsonar.login=$(SONAR_AUTH_TOKEN) ; \ - else \ - $(DOCKER_MVN) package sonar:sonar \ - -Dsonar.organization=$(ORGANIZATION) \ - -Dsonar.projectKey=$(ORGANIZATION)_$(REPO) \ - -Dsonar.projectName="$(ORGANIZATION)/$(REPO)" \ - -Dsonar.pullrequest.key=$(PR_KEY) \ - -Dsonar.pullrequest.branch=$(CHANGE_BRANCH) \ - -Dsonar.pullrequest.base=$(CHANGE_TARGET) \ - -Dsonar.projectVersion=$(VERSION) \ - -Dsonar.host.url=$(SONAR_HOST_URL) \ - -Dsonar.login=$(SONAR_AUTH_TOKEN) ; \ - fi + if [ -z "$(CHANGE_BRANCH)" ]; then \ + $(DOCKER_MVN) package sonar:sonar \ + -Dsonar.organization=$(ORGANIZATION) \ + -Dsonar.projectKey=$(ORGANIZATION)_$(REPO) \ + -Dsonar.projectName="$(ORGANIZATION)/$(REPO)" \ + -Dsonar.branch.name=$(BRANCH_NAME) \ + -Dsonar.projectVersion=$(VERSION) \ + -Dsonar.host.url=$(SONAR_HOST_URL) \ + -Dsonar.login=$(SONAR_AUTH_TOKEN) ; \ + else \ + $(DOCKER_MVN) package sonar:sonar \ + -Dsonar.organization=$(ORGANIZATION) \ + -Dsonar.projectKey=$(ORGANIZATION)_$(REPO) \ + -Dsonar.projectName="$(ORGANIZATION)/$(REPO)" \ + -Dsonar.pullrequest.key=$(PR_KEY) \ + -Dsonar.pullrequest.branch=$(CHANGE_BRANCH) \ + -Dsonar.pullrequest.base=$(CHANGE_TARGET) \ + -Dsonar.projectVersion=$(VERSION) \ + -Dsonar.host.url=$(SONAR_HOST_URL) \ + -Dsonar.login=$(SONAR_AUTH_TOKEN) ; \ + fi .PHONY: analyze_sonar_generic analyze_sonar_generic: [ -z "$(SONAR_AUTH_TOKEN)" ] || \ - if [ -z "$(CHANGE_BRANCH)" ]; then \ - docker run \ - --rm \ - -v $$(pwd):/usr/src \ - sonarsource/sonar-scanner-cli \ - -Dsonar.organization=$(ORGANIZATION) \ - -Dsonar.projectKey=$(ORGANIZATION)_$(REPO) \ - -Dsonar.projectName="$(ORGANIZATION)/$(REPO)" \ - -Dsonar.branch.name=$(BRANCH_NAME) \ - -Dsonar.projectVersion=$(VERSION) \ - -Dsonar.host.url=$(SONAR_HOST_URL) \ - -Dsonar.login=$(SONAR_AUTH_TOKEN) \ - -Dsonar.junit.reportPaths=**/target/surefire-reports; \ - else \ - docker run \ - --rm \ - -v $$(pwd):/usr/src \ - sonarsource/sonar-scanner-cli \ - -Dsonar.organization=$(ORGANIZATION) \ - -Dsonar.projectKey=$(ORGANIZATION)_$(REPO) \ - -Dsonar.projectName="$(ORGANIZATION)/$(REPO)" \ - -Dsonar.pullrequest.key=$(PR_KEY) \ - -Dsonar.pullrequest.branch=$(CHANGE_BRANCH) \ - -Dsonar.pullrequest.base=$(CHANGE_TARGET) \ - -Dsonar.projectVersion=$(VERSION) \ - -Dsonar.host.url=$(SONAR_HOST_URL) \ - -Dsonar.login=$(SONAR_AUTH_TOKEN) \ - -Dsonar.junit.reportPaths=**/target/surefire-reports; \ - fi + if [ -z "$(CHANGE_BRANCH)" ]; then \ + $(DOCKER_RUN_USER) \ + -v $$(pwd):/usr/src \ + sonarsource/sonar-scanner-cli \ + -Dsonar.organization=$(ORGANIZATION) \ + -Dsonar.projectKey=$(ORGANIZATION)_$(REPO) \ + -Dsonar.projectName="$(ORGANIZATION)/$(REPO)" \ + -Dsonar.branch.name=$(BRANCH_NAME) \ + -Dsonar.projectVersion=$(VERSION) \ + -Dsonar.host.url=$(SONAR_HOST_URL) \ + -Dsonar.login=$(SONAR_AUTH_TOKEN) \ + -Dsonar.junit.reportPaths=**/target/surefire-reports; \ + else \ + $(DOCKER_RUN_USER) \ + -v $$(pwd):/usr/src \ + sonarsource/sonar-scanner-cli \ + -Dsonar.organization=$(ORGANIZATION) \ + -Dsonar.projectKey=$(ORGANIZATION)_$(REPO) \ + -Dsonar.projectName="$(ORGANIZATION)/$(REPO)" \ + -Dsonar.pullrequest.key=$(PR_KEY) \ + -Dsonar.pullrequest.branch=$(CHANGE_BRANCH) \ + -Dsonar.pullrequest.base=$(CHANGE_TARGET) \ + -Dsonar.projectVersion=$(VERSION) \ + -Dsonar.host.url=$(SONAR_HOST_URL) \ + -Dsonar.login=$(SONAR_AUTH_TOKEN) \ + -Dsonar.junit.reportPaths=**/target/surefire-reports; \ + fi .PHONY: analyze_sonar_js analyze_sonar_js: [ -z "$(SONAR_AUTH_TOKEN)" ] || \ - if [ -z "$(CHANGE_BRANCH)" ]; then \ - docker run \ - --rm \ - -v $$(pwd):/usr/src \ - sonarsource/sonar-scanner-cli \ - -Dsonar.organization=$(ORGANIZATION) \ - -Dsonar.projectKey=$(ORGANIZATION)_$(REPO) \ - -Dsonar.projectName="$(ORGANIZATION)/$(REPO)" \ - -Dsonar.branch.name=$(BRANCH_NAME) \ - -Dsonar.projectVersion=$(LONG_VERSION) \ - -Dsonar.host.url=$(SONAR_HOST_URL) \ - -Dsonar.login=$(SONAR_AUTH_TOKEN) \ - -Dsonar.sources=src \ - -Dsonar.tests=test \ - -Dsonar.junit.reportPaths=build/junit.xml \ - -Dsonar.javascript.lcov.reportPaths=build/lcov.info; \ - else \ - docker run \ - --rm \ - -v $$(pwd):/usr/src \ - sonarsource/sonar-scanner-cli \ - -Dsonar.organization=$(ORGANIZATION) \ - -Dsonar.projectKey=$(ORGANIZATION)_$(REPO) \ - -Dsonar.projectName="$(ORGANIZATION)/$(REPO)" \ - -Dsonar.pullrequest.key=$(PR_KEY) \ - -Dsonar.pullrequest.branch=$(CHANGE_BRANCH) \ - -Dsonar.pullrequest.base=$(CHANGE_TARGET) \ - -Dsonar.projectVersion=$(LONG_VERSION) \ - -Dsonar.host.url=$(SONAR_HOST_URL) \ - -Dsonar.login=$(SONAR_AUTH_TOKEN) \ - -Dsonar.sources=src \ - -Dsonar.tests=test \ - -Dsonar.junit.reportPaths=build/junit.xml \ - -Dsonar.javascript.lcov.reportPaths=build/lcov.info; \ - fi + if [ -z "$(CHANGE_BRANCH)" ]; then \ + $(DOCKER_RUN_USER) \ + -v $$(pwd):/usr/src \ + sonarsource/sonar-scanner-cli \ + -Dsonar.organization=$(ORGANIZATION) \ + -Dsonar.projectKey=$(ORGANIZATION)_$(REPO) \ + -Dsonar.projectName="$(ORGANIZATION)/$(REPO)" \ + -Dsonar.branch.name=$(BRANCH_NAME) \ + -Dsonar.projectVersion=$(LONG_VERSION) \ + -Dsonar.host.url=$(SONAR_HOST_URL) \ + -Dsonar.login=$(SONAR_AUTH_TOKEN) \ + -Dsonar.sources=src \ + -Dsonar.tests=test \ + -Dsonar.junit.reportPaths=build/junit.xml \ + -Dsonar.javascript.lcov.reportPaths=build/lcov.info; \ + else \ + $(DOCKER_RUN_USER) \ + -v $$(pwd):/usr/src \ + sonarsource/sonar-scanner-cli \ + -Dsonar.organization=$(ORGANIZATION) \ + -Dsonar.projectKey=$(ORGANIZATION)_$(REPO) \ + -Dsonar.projectName="$(ORGANIZATION)/$(REPO)" \ + -Dsonar.pullrequest.key=$(PR_KEY) \ + -Dsonar.pullrequest.branch=$(CHANGE_BRANCH) \ + -Dsonar.pullrequest.base=$(CHANGE_TARGET) \ + -Dsonar.projectVersion=$(LONG_VERSION) \ + -Dsonar.host.url=$(SONAR_HOST_URL) \ + -Dsonar.login=$(SONAR_AUTH_TOKEN) \ + -Dsonar.sources=src \ + -Dsonar.tests=test \ + -Dsonar.junit.reportPaths=build/junit.xml \ + -Dsonar.javascript.lcov.reportPaths=build/lcov.info; \ + fi .PHONY: archive_git archive_git: build/$(REPO)-$(VERSION).zip build/$(REPO)-$(VERSION).tgz build/$(REPO)-$(VERSION).zip: if [ -d .git ]; then \ - git archive HEAD --format=zip -9 --output=build/$(REPO)-$(VERSION).zip; \ + git archive HEAD --format=zip -9 --output=build/$(REPO)-$(VERSION).zip; \ fi build/$(REPO)-$(VERSION).tgz: if [ -d .git ]; then \ - git archive HEAD --format=zip -9 --output=build/$(REPO)-$(VERSION).tgz; \ + git archive HEAD --format=zip -9 --output=build/$(REPO)-$(VERSION).tgz; \ fi -## -# Docker based toolchain -## -TOOLCHAIN_IMAGE=toolchain:$(ISOLATION_ID) -TOOL = docker run --rm -v $(PWD):/project -w /project \ - -v mvn_$(ISOLATION_ID):/root/.m2/repository \ - -v go_$(ISOLATION_ID):/go +$(MARKERS)/toolchain_vols: + docker volume create toolchain-home-$(ISOLATION_ID) + $(BUSYBOX_ROOT) chown -R $(UID):$(GID) $(TOOLCHAIN_HOME) + touch $@ -TOOLCHAIN := $(TOOL) \ - $(shell if [ -n "$(MAVEN_SETTINGS)" ]; then echo -v $(MAVEN_SETTINGS):/root/.m2/settings.xml; fi) \ - $(TOOLCHAIN_IMAGE) -DOCKER_MVN := $(TOOLCHAIN) mvn -Drevision=$(MAVEN_REVISION) -B -BUSYBOX := docker run --rm -v $(HOME)/.m2/repository:/root/.m2/repository \ - $(shell if [ -n "$(MAVEN_SETTINGS)" ]; then echo -v $(MAVEN_SETTINGS):/root/.m2/settings.xml; fi) \ - -v $(PWD):/project \ - busybox:latest - -$(MARKERS)/build_toolchain_docker: $(MARKERS) - if [ -r docker/toolchain.docker ]; then \ - docker build -f docker/toolchain.docker -t toolchain:$(ISOLATION_ID) . ; \ - docker volume create go_$(ISOLATION_ID); \ - docker volume create mvn_$(ISOLATION_ID); \ +$(MARKERS)/build_toolchain_docker: $(MARKERS) $(MARKERS)/toolchain_vols + if ! docker image ls -qq $(TOOLCHAIN_IMAGE) > /dev/null; then \ + echo "Pulling toolchain $(TOOLCHAIN_IMAGE)"; \ + docker pull -qq $(TOOLCHAIN_IMAGE); \ + else \ + echo "Toolchain $(TOOLCHAIN_IMAGE) already available"; \ fi touch $@ .PHONY: clean_toolchain_docker clean_toolchain_docker: - docker rmi -f toolchain:$(ISOLATION_ID) - docker volume rm -f go_$(ISOLATION_ID) - docker volume rm -f mvn_$(ISOLATION_ID) + docker rmi -f $(TOOLCHAIN_IMAGE) + docker volume rm -f toolchain-home-$(ISOLATION_ID) + rm -f $(MARKERS)/toolchain_vols + rm -f $(MARKERS)/build_toolchain_docker .PHONY: fix_permissions fix_permissions: - $(BUSYBOX) chown -R $(UID):$(GID) /root/.m2/repository - $(BUSYBOX) chown -R $(UID):$(GID) /project + $(BUSYBOX_ROOT) chown -R $(UID):$(GID) $(TOOLCHAIN_HOME)/.m2/repository || true + $(BUSYBOX_ROOT) chown -R $(UID):$(GID) /project || true # This will reset the build status possible causing steps to rerun .PHONY: clean_markers @@ -297,6 +324,15 @@ clean_markers: rm -rf $(MARKERS) rm -rf build +$(MARKERS)/build_go: $(MARKERS)/build_toolchain_docker + $(TOOLCHAIN) bash -c "if [ -r scripts/build ]; then scripts/build; else go build ./...; fi" + touch $@ + +.PHONY: clean_build_go +clean_build_go: $(MARKERS)/build_toolchain_docker + $(TOOLCHAIN) go clean ./... + rm -f $(MARKERS)/build_go + $(MARKERS)/build_mvn: $(MARKERS)/build_toolchain_docker $(DOCKER_MVN) compile touch $@ @@ -312,10 +348,20 @@ $(MARKERS)/test_mvn: $(MARKERS)/build_toolchain_docker $(DOCKER_MVN) test touch $@ +$(MARKERS)/test_go: $(MARKERS)/build_toolchain_docker + $(TOOLCHAIN) go test ./... + touch $@ + $(MARKERS)/publish_mvn: $(MARKERS)/build_toolchain_docker + echo $(DOCKER_MVN) clean deploy -DupdateReleaseInfo=$(MAVEN_UPDATE_RELEASE_INFO) \ + -DaltDeploymentRepository=$(MAVEN_DEPLOY_TARGET) $(DOCKER_MVN) -Drevision=0.0.0 versions:set -DnewVersion=$(MAVEN_REVISION) $(DOCKER_MVN) clean deploy -DupdateReleaseInfo=$(MAVEN_UPDATE_RELEASE_INFO) \ - -DaltDeploymentRepository=$(MAVEN_DEPLOY_TARGET) + -DaltDeploymentRepository=$(MAVEN_DEPLOY_TARGET) + +.PHONY: effective-pom +effective-pom: $(MARKERS)/build_toolchain_docker + $(DOCKER_MVN) help:effective-pom # Any prerequisite directories, which should also be gitignored $(MARKERS): @@ -334,12 +380,25 @@ $(MARKERS)/check_ignores: git check-ignore build git check-ignore $(MARKERS) touch $@ -## -# END Standardized directives -## .PHONY: what_version what_version: @echo VERSION=$(VERSION) @echo LONG_VERSION=$(LONG_VERSION) @echo MAVEN_REVISION=$(MAVEN_REVISION) + +## +# END Standardized directives +## + +## +# GitHub release directives +## +GH := $(TOOLCHAIN) gh +GH_RELEASE = $(GH) release + +.PHONY: gh-create-draft-release +gh-create-draft-release: + if [ "$(RELEASABLE)" = "yes" ];then \ + $(GH_RELEASE) create $(VERSION) -t "$(VERSION)" -F CHANGELOG.md; \ + fi