change version var

This commit is contained in:
2026-02-08 22:52:26 +01:00
parent d1e54774a7
commit 557a73a8b4
3 changed files with 6 additions and 60 deletions

View File

@@ -1,65 +1,9 @@
package constant package constant
import (
"fmt"
"strconv"
)
type (
Version struct {
patch int
minor int
major int
}
)
var ( var (
patch string = "0" version string
minor string = "0"
major string = "0"
version Version
) )
func init() { func ProgramVersion() string {
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 {
return version 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)
}

View File

@@ -1,9 +1,11 @@
FROM golang:1.25.7-alpine3.22 AS build FROM golang:1.25.7-alpine3.22 AS build
ARG VERSION="0.1.0"
ENV VERSION=$VERSION
COPY . /src COPY . /src
RUN cd /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/var/opt/dockerupdater \
&& mkdir -p ./fs/opt/dockerupdater \ && mkdir -p ./fs/opt/dockerupdater \
&& cp dockerupdater ./fs/opt/dockerupdater/dockerupdater && cp dockerupdater ./fs/opt/dockerupdater/dockerupdater

View File

@@ -53,7 +53,7 @@ func main() {
debug.SetTraceback("none") 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)) os.Exit(run(ctx, false))
} }