From 6cd085855650796687bbc0b1f869843d519f724a Mon Sep 17 00:00:00 2001 From: "Matthew R. Kasun" Date: Sat, 12 Feb 2022 11:55:54 -0500 Subject: [PATCH] embedd version info into docker image binary --- .github/workflows/publish-docker.yml | 3 +++ Dockerfile | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index 090df5a2..8df0055b 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -47,6 +47,7 @@ jobs: load: true platforms: linux/amd64 tags: ${{ env.TAG }} + build-args: version=${{ env.TAG }} - name: Test x86 run: | @@ -61,6 +62,7 @@ jobs: load: true platforms: linux/arm64 tags: ${{ env.TAG }} + build-args: version=${{ env.TAG }} - name: Test arm run: | @@ -75,3 +77,4 @@ jobs: platforms: linux/amd64, linux/arm64 push: true tags: ${{ github.repository }}:${{ env.TAG }} + build-args: version=${{ env.TAG }} diff --git a/Dockerfile b/Dockerfile index 81c87747..87b73fca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,12 @@ #first stage - builder FROM golang:1.17-alpine as builder -ARG version +ARG VERSION RUN apk add build-base WORKDIR /app COPY . . ENV GO111MODULE=auto -# RUN GOOS=linux CGO_ENABLED=1 go build -tags debug -ldflags="-s -X 'main.version=$version'" -o netmaker main.go -RUN GOOS=linux CGO_ENABLED=1 go build -ldflags="-s -X 'main.version=$VERSION'" -o netmaker main.go +RUN GOOS=linux CGO_ENABLED=1 go build -ldflags="-s -X 'main.version=${VERSION}'" -o netmaker main.go FROM alpine:3.14.3 # add a c lib