From 557a73a8b46dd4c5795bedb177d0caad0fe5e52f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lie=20DELHAIE?= Date: Sun, 8 Feb 2026 22:52:26 +0100 Subject: [PATCH] change version var --- constant/constant.go | 60 ++------------------------------------------ dockerfile | 4 ++- main.go | 2 +- 3 files changed, 6 insertions(+), 60 deletions(-) diff --git a/constant/constant.go b/constant/constant.go index 17dd808..9ab3956 100644 --- a/constant/constant.go +++ b/constant/constant.go @@ -1,65 +1,9 @@ package constant -import ( - "fmt" - "strconv" -) - -type ( - Version struct { - patch int - minor int - major int - } -) - var ( - patch string = "0" - minor string = "0" - major string = "0" - - version Version + version string ) -func init() { - patchInt, err := strconv.Atoi(patch) - if err != nil { - panic(fmt.Errorf("failed to parse version number, this is a compilation error, try recompile the program")) - } - - minorInt, err := strconv.Atoi(minor) - if err != nil { - panic(fmt.Errorf("failed to parse version number, this is a compilation error, try recompile the program")) - } - - majorInt, err := strconv.Atoi(major) - if err != nil { - panic(fmt.Errorf("failed to parse version number, this is a compilation error, try recompile the program")) - } - - version = Version{ - patch: patchInt, - minor: minorInt, - major: majorInt, - } -} - -func ProgramVersion() Version { +func ProgramVersion() string { return version } - -func (v Version) Patch() int { - return v.patch -} - -func (v Version) Minor() int { - return v.minor -} - -func (v Version) Major() int { - return v.major -} - -func (v Version) String() string { - return fmt.Sprintf("%d.%d.%d", v.major, v.minor, v.patch) -} diff --git a/dockerfile b/dockerfile index 8b852fa..e2f0f71 100644 --- a/dockerfile +++ b/dockerfile @@ -1,9 +1,11 @@ FROM golang:1.25.7-alpine3.22 AS build +ARG VERSION="0.1.0" +ENV VERSION=$VERSION COPY . /src RUN cd /src \ - && go build -o dockerupdater \ + && CGO_ENABLED=0 GORISCV64=rva22u64 GOAMD64=v3 GOARM64=v8.2 go build -ldflags="-s -w -X docker-updater/constant.version=$VERSION" -o dockerupdater \ && mkdir -p ./fs/var/opt/dockerupdater \ && mkdir -p ./fs/opt/dockerupdater \ && cp dockerupdater ./fs/opt/dockerupdater/dockerupdater diff --git a/main.go b/main.go index e21fd12..6ab540b 100644 --- a/main.go +++ b/main.go @@ -53,7 +53,7 @@ func main() { debug.SetTraceback("none") - slog.Info("docker-updater", "version", constant.ProgramVersion().String(), "os", runtime.GOOS, "arch", runtime.GOARCH) + slog.Info("docker-updater", "version", constant.ProgramVersion(), "os", runtime.GOOS, "arch", runtime.GOARCH) os.Exit(run(ctx, false)) }