From d4a550bb4c0f6e7044f696640333279d752f642a Mon Sep 17 00:00:00 2001 From: Leon Lenzen Date: Sat, 18 Jun 2022 11:36:09 +0200 Subject: [PATCH 1/3] chore: add version to binary in containers --- .github/workflows/release.yml | 6 ++++++ Dockerfile | 3 ++- Dockerfile.alpine | 3 ++- Dockerfile.debug | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 140ea0b0..d8aee0f7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -89,6 +89,8 @@ jobs: platforms: linux/amd64,linux/arm64 cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new + build-args: | + VERSION=${{ github.ref_name }} - name: Prepare cache for next build run: | rm -rf /tmp/.buildx-cache @@ -153,6 +155,8 @@ jobs: platforms: linux/amd64,linux/arm64 cache-from: type=local,src=/tmp/.buildx-cache-debug cache-to: type=local,dest=/tmp/.buildx-cache-debug-new + build-args: | + VERSION=${{ github.ref_name }} - name: Prepare cache for next build run: | rm -rf /tmp/.buildx-cache-debug @@ -217,6 +221,8 @@ jobs: platforms: linux/amd64,linux/arm64 cache-from: type=local,src=/tmp/.buildx-cache-alpine cache-to: type=local,dest=/tmp/.buildx-cache-alpine-new + build-args: | + VERSION=${{ github.ref_name }} - name: Prepare cache for next build run: | rm -rf /tmp/.buildx-cache-alpine diff --git a/Dockerfile b/Dockerfile index ac807794..b9139f09 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ # Builder image FROM docker.io/golang:1.18.0-bullseye AS build +ARG VERSION=dev ENV GOPATH /go WORKDIR /go/src/headscale @@ -8,7 +9,7 @@ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go install -a ./cmd/headscale +RUN CGO_ENABLED=0 GOOS=linux go install -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale RUN strip /go/bin/headscale RUN test -e /go/bin/headscale diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 24d4e6f8..de683f2d 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,5 +1,6 @@ # Builder image FROM docker.io/golang:1.18.0-alpine AS build +ARG VERSION=dev ENV GOPATH /go WORKDIR /go/src/headscale @@ -9,7 +10,7 @@ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go install -a ./cmd/headscale +RUN CGO_ENABLED=0 GOOS=linux go install -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale RUN strip /go/bin/headscale RUN test -e /go/bin/headscale diff --git a/Dockerfile.debug b/Dockerfile.debug index f053d720..9b1b7c6b 100644 --- a/Dockerfile.debug +++ b/Dockerfile.debug @@ -1,5 +1,6 @@ # Builder image FROM docker.io/golang:1.18.0-bullseye AS build +ARG VERSION=dev ENV GOPATH /go WORKDIR /go/src/headscale @@ -8,7 +9,7 @@ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go install -a ./cmd/headscale +RUN CGO_ENABLED=0 GOOS=linux go install -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale RUN test -e /go/bin/headscale # Debug image From 89b7fa6b06d0b8cd159acec176c2716d37135d20 Mon Sep 17 00:00:00 2001 From: Leon Lenzen Date: Sat, 18 Jun 2022 11:39:27 +0200 Subject: [PATCH 2/3] chore: fix lint --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d8aee0f7..0aca91bb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -89,7 +89,7 @@ jobs: platforms: linux/amd64,linux/arm64 cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new - build-args: | + build-args: | VERSION=${{ github.ref_name }} - name: Prepare cache for next build run: | @@ -155,7 +155,7 @@ jobs: platforms: linux/amd64,linux/arm64 cache-from: type=local,src=/tmp/.buildx-cache-debug cache-to: type=local,dest=/tmp/.buildx-cache-debug-new - build-args: | + build-args: | VERSION=${{ github.ref_name }} - name: Prepare cache for next build run: | @@ -221,7 +221,7 @@ jobs: platforms: linux/amd64,linux/arm64 cache-from: type=local,src=/tmp/.buildx-cache-alpine cache-to: type=local,dest=/tmp/.buildx-cache-alpine-new - build-args: | + build-args: | VERSION=${{ github.ref_name }} - name: Prepare cache for next build run: | From 8d9462147c6149ff9bdd23238d8b134cb06f6a1d Mon Sep 17 00:00:00 2001 From: Leon Lenzen Date: Sat, 18 Jun 2022 12:00:02 +0200 Subject: [PATCH 3/3] chore: use docker-meta version --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0aca91bb..e17721db 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -90,7 +90,7 @@ jobs: cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new build-args: | - VERSION=${{ github.ref_name }} + VERSION=${{ steps.meta.outputs.version }} - name: Prepare cache for next build run: | rm -rf /tmp/.buildx-cache @@ -156,7 +156,7 @@ jobs: cache-from: type=local,src=/tmp/.buildx-cache-debug cache-to: type=local,dest=/tmp/.buildx-cache-debug-new build-args: | - VERSION=${{ github.ref_name }} + VERSION=${{ steps.meta-debug.outputs.version }} - name: Prepare cache for next build run: | rm -rf /tmp/.buildx-cache-debug @@ -222,7 +222,7 @@ jobs: cache-from: type=local,src=/tmp/.buildx-cache-alpine cache-to: type=local,dest=/tmp/.buildx-cache-alpine-new build-args: | - VERSION=${{ github.ref_name }} + VERSION=${{ steps.meta-alpine.outputs.version }} - name: Prepare cache for next build run: | rm -rf /tmp/.buildx-cache-alpine