From 30eaad28391b79ca739a23382f7b8b858aa846ed Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Fri, 15 Feb 2019 10:25:21 +0100 Subject: [PATCH] Add a reliable version --- .drone.windows.yml | 24 ++++++++++---------- .drone.yml | 48 ++++++++++++++++++++-------------------- cmd/drone-docker/main.go | 6 +++-- pipeline.libsonnet | 4 ++-- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/.drone.windows.yml b/.drone.windows.yml index 362ff45..af03da1 100644 --- a/.drone.windows.yml +++ b/.drone.windows.yml @@ -54,7 +54,7 @@ steps: pull: always image: golang:1.11-windowsservercore-1803 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-docker.exe ./cmd/drone-docker" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/windows/amd64/drone-docker.exe ./cmd/drone-docker" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -67,7 +67,7 @@ steps: pull: always image: golang:1.11-windowsservercore-1803 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-docker.exe ./cmd/drone-docker" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/windows/amd64/drone-docker.exe ./cmd/drone-docker" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -150,7 +150,7 @@ steps: pull: always image: golang:1.11-windowsservercore-1809 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-docker.exe ./cmd/drone-docker" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/windows/amd64/drone-docker.exe ./cmd/drone-docker" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -163,7 +163,7 @@ steps: pull: always image: golang:1.11-windowsservercore-1809 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-docker.exe ./cmd/drone-docker" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/windows/amd64/drone-docker.exe ./cmd/drone-docker" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -283,7 +283,7 @@ steps: pull: always image: golang:1.11-windowsservercore-1803 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-gcr.exe ./cmd/drone-gcr" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/windows/amd64/drone-gcr.exe ./cmd/drone-gcr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -296,7 +296,7 @@ steps: pull: always image: golang:1.11-windowsservercore-1803 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-gcr.exe ./cmd/drone-gcr" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/windows/amd64/drone-gcr.exe ./cmd/drone-gcr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -373,7 +373,7 @@ steps: pull: always image: golang:1.11-windowsservercore-1809 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-gcr.exe ./cmd/drone-gcr" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/windows/amd64/drone-gcr.exe ./cmd/drone-gcr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -386,7 +386,7 @@ steps: pull: always image: golang:1.11-windowsservercore-1809 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-gcr.exe ./cmd/drone-gcr" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/windows/amd64/drone-gcr.exe ./cmd/drone-gcr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -500,7 +500,7 @@ steps: pull: always image: golang:1.11-windowsservercore-1803 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-ecr.exe ./cmd/drone-ecr" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/windows/amd64/drone-ecr.exe ./cmd/drone-ecr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -513,7 +513,7 @@ steps: pull: always image: golang:1.11-windowsservercore-1803 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-ecr.exe ./cmd/drone-ecr" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/windows/amd64/drone-ecr.exe ./cmd/drone-ecr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -590,7 +590,7 @@ steps: pull: always image: golang:1.11-windowsservercore-1809 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-ecr.exe ./cmd/drone-ecr" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/windows/amd64/drone-ecr.exe ./cmd/drone-ecr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -603,7 +603,7 @@ steps: pull: always image: golang:1.11-windowsservercore-1809 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-ecr.exe ./cmd/drone-ecr" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/windows/amd64/drone-ecr.exe ./cmd/drone-ecr" environment: CGO_ENABLED: 0 GO111MODULE: on diff --git a/.drone.yml b/.drone.yml index 683c562..0b3027c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -52,7 +52,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/amd64/drone-docker ./cmd/drone-docker" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/amd64/drone-docker ./cmd/drone-docker" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -65,7 +65,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/amd64/drone-docker ./cmd/drone-docker" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/amd64/drone-docker ./cmd/drone-docker" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -136,7 +136,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm64/drone-docker ./cmd/drone-docker" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/arm64/drone-docker ./cmd/drone-docker" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -149,7 +149,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm64/drone-docker ./cmd/drone-docker" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/arm64/drone-docker ./cmd/drone-docker" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -220,7 +220,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm/drone-docker ./cmd/drone-docker" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/arm/drone-docker ./cmd/drone-docker" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -233,7 +233,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm/drone-docker ./cmd/drone-docker" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/arm/drone-docker ./cmd/drone-docker" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -341,7 +341,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/amd64/drone-gcr ./cmd/drone-gcr" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/amd64/drone-gcr ./cmd/drone-gcr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -354,7 +354,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/amd64/drone-gcr ./cmd/drone-gcr" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/amd64/drone-gcr ./cmd/drone-gcr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -419,7 +419,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm64/drone-gcr ./cmd/drone-gcr" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/arm64/drone-gcr ./cmd/drone-gcr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -432,7 +432,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm64/drone-gcr ./cmd/drone-gcr" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/arm64/drone-gcr ./cmd/drone-gcr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -497,7 +497,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm/drone-gcr ./cmd/drone-gcr" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/arm/drone-gcr ./cmd/drone-gcr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -510,7 +510,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm/drone-gcr ./cmd/drone-gcr" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/arm/drone-gcr ./cmd/drone-gcr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -612,7 +612,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/amd64/drone-ecr ./cmd/drone-ecr" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/amd64/drone-ecr ./cmd/drone-ecr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -625,7 +625,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/amd64/drone-ecr ./cmd/drone-ecr" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/amd64/drone-ecr ./cmd/drone-ecr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -690,7 +690,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm64/drone-ecr ./cmd/drone-ecr" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/arm64/drone-ecr ./cmd/drone-ecr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -703,7 +703,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm64/drone-ecr ./cmd/drone-ecr" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/arm64/drone-ecr ./cmd/drone-ecr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -768,7 +768,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm/drone-ecr ./cmd/drone-ecr" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/arm/drone-ecr ./cmd/drone-ecr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -781,7 +781,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm/drone-ecr ./cmd/drone-ecr" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/arm/drone-ecr ./cmd/drone-ecr" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -883,7 +883,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/amd64/drone-heroku ./cmd/drone-heroku" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/amd64/drone-heroku ./cmd/drone-heroku" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -896,7 +896,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/amd64/drone-heroku ./cmd/drone-heroku" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/amd64/drone-heroku ./cmd/drone-heroku" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -961,7 +961,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm64/drone-heroku ./cmd/drone-heroku" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/arm64/drone-heroku ./cmd/drone-heroku" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -974,7 +974,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm64/drone-heroku ./cmd/drone-heroku" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/arm64/drone-heroku ./cmd/drone-heroku" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -1039,7 +1039,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm/drone-heroku ./cmd/drone-heroku" + - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/arm/drone-heroku ./cmd/drone-heroku" environment: CGO_ENABLED: 0 GO111MODULE: on @@ -1052,7 +1052,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm/drone-heroku ./cmd/drone-heroku" + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/arm/drone-heroku ./cmd/drone-heroku" environment: CGO_ENABLED: 0 GO111MODULE: on diff --git a/cmd/drone-docker/main.go b/cmd/drone-docker/main.go index 145997b..13b76e0 100644 --- a/cmd/drone-docker/main.go +++ b/cmd/drone-docker/main.go @@ -11,7 +11,9 @@ import ( "github.com/drone-plugins/drone-docker" ) -var build = "0" // build number set at compile-time +var ( + version = "unknown" +) func main() { // Load env-file if it exists first @@ -23,7 +25,7 @@ func main() { app.Name = "docker plugin" app.Usage = "docker plugin" app.Action = run - app.Version = fmt.Sprintf("1.0.%s", build) + app.Version = version app.Flags = []cli.Flag{ cli.BoolFlag{ Name: "dry-run", diff --git a/pipeline.libsonnet b/pipeline.libsonnet index 92fee9e..5f1085d 100644 --- a/pipeline.libsonnet +++ b/pipeline.libsonnet @@ -83,7 +83,7 @@ local golang_image(os, version) = GO111MODULE: 'on', }, commands: [ - 'go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/' + os + '/' + arch + '/drone-' + name + extension + ' ./cmd/drone-' + name, + 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/' + os + '/' + arch + '/drone-' + name + extension + ' ./cmd/drone-' + name, ], when: { event: { @@ -100,7 +100,7 @@ local golang_image(os, version) = GO111MODULE: 'on', }, commands: [ - 'go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/' + os + '/' + arch + '/drone-' + name + extension + ' ./cmd/drone-' + name, + 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/' + os + '/' + arch + '/drone-' + name + extension + ' ./cmd/drone-' + name, ], when: { event: ['tag'],