From 2e1f2914a9497bfbc4a581bdbb926c719ac3b9fe Mon Sep 17 00:00:00 2001 From: Alexis Couvreur Date: Fri, 11 Nov 2022 15:17:36 +0000 Subject: [PATCH] fix: inject release version inside docker image --- .github/workflows/docker.yaml | 10 ++++++---- Dockerfile | 5 ++++- Makefile | 8 +++++--- release.config.js | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index f155205..fa3e5dc 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -18,7 +18,7 @@ jobs: uses: actions/checkout@v3 - name: Docker meta id: meta - uses: docker/metadata-action@v3 + uses: docker/metadata-action@v4 with: # list of Docker images to use as base name for tags images: | @@ -26,12 +26,10 @@ jobs: acouvreur/sablier # generate Docker tags based on the following events/attributes tags: | - type=schedule type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - name: Set up QEMU uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx @@ -58,4 +56,8 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} platforms: linux/amd64,linux/arm64,linux/arm/v7 - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + labels: ${{ steps.meta.outputs.labels }} + build-args: | + BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} + VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} + REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2078579..0323a4e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,9 +10,12 @@ RUN go mod download COPY . /go/src/sablier +ARG BUILDTIME +ARG VERSION +ARG REVISION ARG TARGETOS ARG TARGETARCH -RUN make ${TARGETOS}/${TARGETARCH} +RUN make BUILDTIME=${BUILDTIME} VERSION=${VERSION} GIT_REVISION=${REVISION} ${TARGETOS}/${TARGETARCH} FROM alpine diff --git a/Makefile b/Makefile index a766716..7e03a3f 100644 --- a/Makefile +++ b/Makefile @@ -3,17 +3,19 @@ PLATFORMS := linux/amd64 linux/arm64 linux/arm/v7 linux/arm temp = $(subst /, ,$@) os = $(word 1, $(temp)) arch = $(word 2, $(temp)) -version = draft +VERSION = draft # Version info for binaries GIT_REVISION := $(shell git rev-parse --short HEAD) GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD) +BUILDTIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") +BUILDUSER := $(shell whoami)@$(shell hostname) VPREFIX := github.com/acouvreur/sablier/version -GO_LDFLAGS := -X $(VPREFIX).Branch=$(GIT_BRANCH) -X $(VPREFIX).Version=$(version) -X $(VPREFIX).Revision=$(GIT_REVISION) -X $(VPREFIX).BuildUser=$(shell whoami)@$(shell hostname) -X $(VPREFIX).BuildDate=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") +GO_LDFLAGS := -X $(VPREFIX).Branch=$(GIT_BRANCH) -X $(VPREFIX).Version=$(VERSION) -X $(VPREFIX).Revision=$(GIT_REVISION) -X $(VPREFIX).BuildUser=$(BUILDUSER) -X $(VPREFIX).BuildDate=$(BUILDTIME) $(PLATFORMS): - CGO_ENABLED=0 GOOS=$(os) GOARCH=$(arch) go build -tags=nomsgpack -v -ldflags="${GO_LDFLAGS}" -o 'sablier_$(version)_$(os)-$(arch)' . + CGO_ENABLED=0 GOOS=$(os) GOARCH=$(arch) go build -tags=nomsgpack -v -ldflags="${GO_LDFLAGS}" -o 'sablier_$(VERSION)_$(os)-$(arch)' . release: $(PLATFORMS) .PHONY: release $(PLATFORMS) \ No newline at end of file diff --git a/release.config.js b/release.config.js index 7c9a147..78a22e7 100644 --- a/release.config.js +++ b/release.config.js @@ -7,7 +7,7 @@ module.exports = { "@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", ["@semantic-release/exec", { - "publishCmd": "make version=${nextRelease.version} release -j 3" + "publishCmd": "make VERSION=${nextRelease.version} release -j 3" }], ["@semantic-release/github", { "assets": [