commit 91b8e4f44df8de69c3a4b0e11d60246bec581cb4
parent 38e743ac7b18bb48dee55f0cf05a471c9fa877d8
Author: MTRNord <mtrnord1@gmail.com>
Date: Thu, 15 Feb 2024 21:53:47 +0100
Add version to the build
Diffstat:
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/build_docker.yaml b/.github/workflows/build_docker.yaml
@@ -23,6 +23,12 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
+ # Fetch the latest Git tag and current branch
+ - name: Get Git version and branch
+ id: git_info
+ run: |
+ echo ::set-output name=VERSION::$(git describe --tags --abbrev=0)
+ echo ::set-output name=BRANCH::$(git rev-parse --abbrev-ref HEAD)
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
@@ -46,3 +52,6 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
+ build-args: |
+ VERSION=${{ steps.git_info.outputs.VERSION }}
+ BRANCH=${{ steps.git_info.outputs.BRANCH }}
diff --git a/Dockerfile b/Dockerfile
@@ -6,8 +6,12 @@ COPY go.mod go.sum ./
RUN go mod download
COPY *.go ./
-
-RUN CGO_ENABLED=0 GOOS=linux go build -o /ping-monitoring
+# Build the Go binary with version information
+ARG VERSION
+ARG BRANCH
+RUN CGO_ENABLED=0 GOOS=linux go build \
+ -ldflags "-X github.com/prometheus/common/version.Version=${VERSION} -X github.com/prometheus/common/version.Branch=${BRANCH}" \
+ -o /ping-monitoring
FROM gcr.io/distroless/base-debian12