From 047e0b553fd01adde6dfd95adf45e85493fd71d9 Mon Sep 17 00:00:00 2001 From: Matthieu Vachon Date: Wed, 11 Dec 2024 16:28:15 -0500 Subject: [PATCH] Inject version --- .github/workflows/docker.yml | 18 ++++++++++-------- Dockerfile.github | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d7924bc1..7db52ca2 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -26,11 +26,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version-file: './go.mod' - - uses: actions/cache@v4 with: path: | @@ -40,9 +35,6 @@ jobs: restore-keys: | ${{ runner.os }}-go- - - name: Build Binary - run: go build -v -o ./substreams ./cmd/substreams - - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -69,6 +61,14 @@ jobs: flavor: | latest=${{ startsWith(github.ref, 'refs/tags/') }} + - name: Set version + id: version + run: | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then + echo "VERSION=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" + else + echo "VERSION=edge" >> "$GITHUB_OUTPUT" + - name: Build and push Docker image uses: docker/build-push-action@v6 with: @@ -77,3 +77,5 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + VERSION=${{ steps.version.outputs.VERSION }} diff --git a/Dockerfile.github b/Dockerfile.github index 4b8f1c65..4bff2579 100644 --- a/Dockerfile.github +++ b/Dockerfile.github @@ -2,12 +2,12 @@ FROM --platform=$BUILDPLATFORM golang:1.23-bullseye AS build WORKDIR /src -ARG TARGETOS TARGETARCH +ARG TARGETOS TARGETARCH VERSION=dev RUN --mount=target=. \ --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg \ - GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /app/substreams ./cmd/substreams + GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags "-X main.Version=$VERSION" -o /app/substreams ./cmd/substreams FROM ubuntu:22.04