Browse Source

embedd version info into docker image binary

Matthew R. Kasun 3 years ago
parent
commit
6cd0858556
2 changed files with 5 additions and 3 deletions
  1. 3 0
      .github/workflows/publish-docker.yml
  2. 2 3
      Dockerfile

+ 3 - 0
.github/workflows/publish-docker.yml

@@ -47,6 +47,7 @@ jobs:
           load: true
           load: true
           platforms: linux/amd64
           platforms: linux/amd64
           tags: ${{ env.TAG }}
           tags: ${{ env.TAG }}
+          build-args: version=${{ env.TAG }}
       -
       -
         name: Test x86
         name: Test x86
         run: |
         run: |
@@ -61,6 +62,7 @@ jobs:
           load: true
           load: true
           platforms: linux/arm64
           platforms: linux/arm64
           tags: ${{ env.TAG }}
           tags: ${{ env.TAG }}
+          build-args: version=${{ env.TAG }}
       -
       -
         name: Test arm
         name: Test arm
         run: |
         run: |
@@ -75,3 +77,4 @@ jobs:
           platforms: linux/amd64, linux/arm64
           platforms: linux/amd64, linux/arm64
           push: true
           push: true
           tags: ${{ github.repository }}:${{ env.TAG }}
           tags: ${{ github.repository }}:${{ env.TAG }}
+          build-args: version=${{ env.TAG }}

+ 2 - 3
Dockerfile

@@ -1,13 +1,12 @@
 #first stage - builder
 #first stage - builder
 FROM golang:1.17-alpine as builder
 FROM golang:1.17-alpine as builder
-ARG version
+ARG VERSION
 RUN apk add build-base
 RUN apk add build-base
 WORKDIR /app
 WORKDIR /app
 COPY . .
 COPY . .
 ENV GO111MODULE=auto
 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
 FROM alpine:3.14.3
 
 
 # add a c lib
 # add a c lib