change version var
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
2
main.go
2
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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user