Repository: amir20/dozzle (language: go)

Issue:
Dozzle not self reporting version correctly
Describe the bug:
The self reported version since v8.0.2 just says 'head'. This doesn't seem to have any adverse effects other than whilst being on the latest version the update announcement button says I've got a lot of catching up to do :-).

Steps to reproduce the behavior:
Run any version since v8.0.2 and check Dozzle's logs at just the info level, the message for the self reported version is just:
`msg=Dozzle version head`

Expected behavior:
The version is reported correctly, like v8.0.2.
`msg=Dozzle version v8.0.2`

Screenshots:
![image](https://github.com/amir20/dozzle/assets/65852870/c380e59b-f07a-4106-adfc-72da7a04e274)


- OS: Debian 12
- Docker version: 27.0.3
- Browser & version: Chrome 126.0.6478.127
- Version: v8.0.3 (latest)


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index b69407cebd56..d25502759166 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -88,11 +88,6 @@ jobs:
     name: Release
     runs-on: ubuntu-latest
     steps:
-      - name: Docker meta
-        id: meta
-        uses: docker/metadata-action@v5
-        with:
-          images: amir20/dozzle
       - name: Set up Docker Buildx
         uses: docker/setup-buildx-action@4fd812986e6c8c2a69e18311145f9371337f27d4 # v3.4.0
       - name: Login to DockerHub
@@ -102,6 +97,11 @@ jobs:
           password: ${{ secrets.DOCKER_PASSWORD }}
       - name: Checkout
         uses: actions/checkout@v4
+      - name: Docker meta
+        id: meta
+        uses: docker/metadata-action@v5
+        with:
+          images: amir20/dozzle
       - name: Writing certs to file
         run: |
           echo "${{ secrets.TTL_KEY }}" > shared_key.pem
diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml
index b1ee0980d1eb..aaf2ab8c7084 100644
--- a/.github/workflows/dev.yml
+++ b/.github/workflows/dev.yml
@@ -12,11 +12,6 @@ jobs:
     runs-on: ubuntu-latest
     if: ${{ !github.event.repository.fork && !github.event.pull_request.head.repo.fork && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == 'amir20/dozzle') }}
     steps:
-      - name: Docker meta
-        id: meta
-        uses: docker/metadata-action@v5
-        with:
-          images: amir20/dozzle
       - name: Set up Docker Buildx
         uses: docker/setup-buildx-action@4fd812986e6c8c2a69e18311145f9371337f27d4 # v3.4.0
       - name: Login to DockerHub
@@ -26,6 +21,11 @@ jobs:
           password: ${{ secrets.DOCKER_PASSWORD }}
       - name: Checkout
         uses: actions/checkout@v4
+      - name: Docker meta
+        id: meta
+        uses: docker/metadata-action@v5
+        with:
+          images: amir20/dozzle
       - name: Writing certs to file
         run: |
           echo "${{ secrets.TTL_KEY }}" > shared_key.pem
diff --git a/Dockerfile b/Dockerfile
index 58608877ebe7..4ddabee6a4aa 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -53,7 +53,7 @@ ARG TARGETOS TARGETARCH
 RUN go generate
 
 # Build binary
-RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -ldflags "-s -w -X cli.version=$TAG"  -o dozzle
+RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -ldflags "-s -w -X github.com/amir20/dozzle/internal/support/cli.Version=$TAG" -o dozzle
 
 RUN mkdir /data
 
diff --git a/Makefile b/Makefile
index fe38512d0fc7..d463522f659b 100644
--- a/Makefile
+++ b/Makefile
@@ -26,11 +26,11 @@ test: fake_assets generate
 
 .PHONY: build
 build: dist generate
-	CGO_ENABLED=0 go build -ldflags "-s -w"
+	CGO_ENABLED=0 go build -ldflags "-s -w -X github.com/amir20/dozzle/internal/support/cli.Version=local"
 
 .PHONY: docker
 docker: shared_key.pem shared_cert.pem
-	@docker build -t amir20/dozzle .
+	@docker build  --build-arg TAG=local -t amir20/dozzle .
 
 generate: shared_key.pem shared_cert.pem $(GEN_FILES)
 
diff --git a/internal/support/cli/args.go b/internal/support/cli/args.go
index d34150eacf3d..9b1c4cf1f137 100644
--- a/internal/support/cli/args.go
+++ b/internal/support/cli/args.go
@@ -6,9 +6,7 @@ import (
 	"github.com/alexflint/go-arg"
 )
 
-var (
-	version = "head"
-)
+var Version = "head"
 
 type Args struct {
 	Addr            string              `arg:"env:DOZZLE_ADDR" default:":8080" help:"sets host:port to bind for server. This is rarely needed inside a docker container."`
@@ -46,7 +44,7 @@ type GenerateCmd struct {
 }
 
 func (Args) Version() string {
-	return version
+	return Version
 }
 
 func ParseArgs() (Args, interface{}) {
diff --git a/internal/support/cli/clients.go b/internal/support/cli/clients.go
index effdc54e953b..32e9e6832e56 100644
--- a/internal/support/cli/clients.go
+++ b/internal/support/cli/clients.go
@@ -52,12 +52,12 @@ func CreateMultiHostService(embededCerts embed.FS, args Args) *docker_support.Mu
 		if err != nil {
 			log.Debugf("could not connect to local Docker Engine: %s", err)
 			if !args.NoAnalytics {
-				go StartEvent(version, args.Mode, args.RemoteAgent, args.RemoteHost, nil, "")
+				go StartEvent(args.Version(), args.Mode, args.RemoteAgent, args.RemoteHost, nil, "")
 			}
 		} else {
 			log.Debugf("connected to local Docker Engine")
 			if !args.NoAnalytics {
-				go StartEvent(version, args.Mode, args.RemoteAgent, args.RemoteHost, localClient, "")
+				go StartEvent(args.Version(), args.Mode, args.RemoteAgent, args.RemoteHost, localClient, "")
 			}
 			clients = append(clients, docker_support.NewDockerClientService(localClient))
 		}


Test patch: