From b9503685f047fa0719e321831ec0540bed790b7f Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sun, 6 Sep 2020 15:39:34 +0200 Subject: [PATCH] build: parametrized pipeline (no more approval for release build), embed exact go version info in artifacts refs #378 refs #377 --- .circleci/config.yml | 35 +++++++++++++++++++++-------------- Makefile | 8 ++++++-- build.Dockerfile | 2 +- version/version.go | 6 ++++-- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 67b0e5c..c844dbe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -127,10 +127,25 @@ commands: -d '{"context":"'"$CONTEXT"'", "state": "success", "description":"'"$DESCRIPTION"'", "target_url":"'"$TARGETURL"'"}' +parameters: + + do_ci: + type: boolean + default: true + + do_release: + type: boolean + default: false + + release_docker_baseimage_tag: + type: string + default: "latest" workflows: version: 2 - build: + + ci: + when: << pipeline.parameters.do_ci >> jobs: - quickcheck-docs - quickcheck-go: &quickcheck-go-smoketest @@ -159,18 +174,10 @@ workflows: goos: freebsd goarch: arm64 - - request-release-build: - type: approval - requires: - - quickcheck-docs - - quickcheck-go-amd64-linux-1.15 #quickcheck-go-smoketest.name - - quickcheck-go-matrix - - test-go-on-latest-go-release - - - release-build: - requires: - - request-release-build - + release: + when: << pipeline.parameters.do_release >> + jobs: + - release-build - release-deb: requires: - release-build @@ -249,7 +256,7 @@ jobs: machine: true steps: - checkout - - run: make release-docker + - run: make release-docker RELEASE_DOCKER_BASEIMAGE_TAG=<> - persist_to_workspace: root: . paths: [.] diff --git a/Makefile b/Makefile index 724c3b9..850ae80 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,8 @@ GO_BUILDFLAGS := $(GO_MOD_READONLY) $(GO_EXTRA_BUILDFLAGS) GO_BUILD := $(GO_ENV_VARS) $(GO) build $(GO_BUILDFLAGS) -ldflags $(GO_LDFLAGS) GOLANGCI_LINT := golangci-lint GOCOVMERGE := gocovmerge +RELEASE_DOCKER_BASEIMAGE_TAG ?= 1.15 +RELEASE_DOCKER_BASEIMAGE ?= golang:$(RELEASE_DOCKER_BASEIMAGE_TAG) ifneq ($(GOARM),) ZREPL_TARGET_TUPLE := $(GOOS)-$(GOARCH)v$(GOARM) @@ -57,8 +59,9 @@ ifeq (SIGN, 1) endif @echo "ZREPL RELEASE ARTIFACTS AVAILABLE IN artifacts/release" -release-docker: - docker build -t zrepl_release --pull -f build.Dockerfile . +release-docker: $(ARTIFACTDIR) + sed 's/FROM.*!SUBSTITUTED_BY_MAKEFILE/FROM $(RELEASE_DOCKER_BASEIMAGE)/' build.Dockerfile > artifacts/release-docker.Dockerfile + docker build -t zrepl_release --pull -f artifacts/release-docker.Dockerfile . docker run --rm -i -v $(CURDIR):/src -u $$(id -u):$$(id -g) \ zrepl_release \ make release GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) @@ -319,6 +322,7 @@ $(ARTIFACTDIR)/_zrepl.zsh_completion: $(ARTIFACTDIR)/go_env.txt: $(GO_ENV_VARS) $(GO) env > $@ + $(GO) version >> $@ docs: $(ARTIFACTDIR)/docs # https://www.sphinx-doc.org/en/master/man/sphinx-build.html diff --git a/build.Dockerfile b/build.Dockerfile index a05f237..81c7cdf 100644 --- a/build.Dockerfile +++ b/build.Dockerfile @@ -1,4 +1,4 @@ -FROM golang:latest +FROM !SUBSTITUTED_BY_MAKEFILE RUN apt-get update && apt-get install -y \ python3-pip \ diff --git a/version/version.go b/version/version.go index 1723179..1db908a 100644 --- a/version/version.go +++ b/version/version.go @@ -13,6 +13,7 @@ var ( type ZreplVersionInformation struct { Version string + RuntimeGo string RuntimeGOOS string RuntimeGOARCH string RUNTIMECompiler string @@ -21,6 +22,7 @@ type ZreplVersionInformation struct { func NewZreplVersionInformation() *ZreplVersionInformation { return &ZreplVersionInformation{ Version: zreplVersion, + RuntimeGo: runtime.Version(), RuntimeGOOS: runtime.GOOS, RuntimeGOARCH: runtime.GOARCH, RUNTIMECompiler: runtime.Compiler, @@ -28,8 +30,8 @@ func NewZreplVersionInformation() *ZreplVersionInformation { } func (i *ZreplVersionInformation) String() string { - return fmt.Sprintf("zrepl version=%s GOOS=%s GOARCH=%s Compiler=%s", - i.Version, i.RuntimeGOOS, i.RuntimeGOARCH, i.RUNTIMECompiler) + return fmt.Sprintf("zrepl version=%s go=%s GOOS=%s GOARCH=%s Compiler=%s", + i.Version, i.RuntimeGo, i.RuntimeGOOS, i.RuntimeGOARCH, i.RUNTIMECompiler) } var prometheusMetric = prometheus.NewUntypedFunc(