From 2f8e083f031f519c51aa915d641098068539bb45 Mon Sep 17 00:00:00 2001 From: Antoine Popineau Date: Wed, 26 Feb 2025 15:36:28 +0100 Subject: [PATCH] Change version extraction to GitHub Actions output. --- .github/workflows/backend_deploy_workflow.yaml | 10 ++++++++-- Dockerfile | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/backend_deploy_workflow.yaml b/.github/workflows/backend_deploy_workflow.yaml index 0f9971e0..214ecd7e 100644 --- a/.github/workflows/backend_deploy_workflow.yaml +++ b/.github/workflows/backend_deploy_workflow.yaml @@ -22,7 +22,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - + with: + fetch-depth: 0 + fetch-tags: true - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -41,13 +43,17 @@ jobs: registry: europe-west1-docker.pkg.dev username: oauth2accesstoken password: ${{ steps.auth.outputs.access_token }} + + - name: Extract version from tag + id: version + run: echo "MARBLE_VERSION=$(git describe --tags)" >> "$GITHUB_OUTPUT" - name: Build and push uses: docker/build-push-action@v5 with: push: true build-args: | - BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 + MARBLE_VERSION=${{ steps.version.outputs.MARBLE_VERSION }} tags: ${{ env.IMAGE }} - name: "Set up Cloud SDK" diff --git a/Dockerfile b/Dockerfile index 55ae461a..decac4bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,13 @@ FROM golang:1.23 as build +ARG MARBLE_VERSION=dev + WORKDIR /go/src/app COPY . . RUN go get -RUN CGO_ENABLED=0 go build -o /go/bin/app -ldflags="-X 'main.apiVersion=$(git describe --tags)'" +RUN CGO_ENABLED=0 go build -o /go/bin/app -ldflags="-X 'main.apiVersion=${MARBLE_VERSION}'" FROM alpine:3.19