fix: show version.

This commit is contained in:
Daniel Ding
2025-11-26 10:26:23 +08:00
parent b1b886beb5
commit 431169034f
5 changed files with 17 additions and 7 deletions

View File

@@ -19,8 +19,9 @@ MAC_DIR ?= "openceci-darwin-$(VER).$(ARCH)"
## declare flags
MOD = github.com/luscis/openlan/pkg/libol
LDFLAGS += -X $(MOD).Date=$(shell date +%FT%T%z)
LDFLAGS += -X $(MOD).Date=$(shell date +%F)
LDFLAGS += -X $(MOD).Version=$(VER)
LDFLAGS += -X $(MOD).Commit=$(shell git rev-parse --short HEAD)
build: test pkg
@@ -95,6 +96,9 @@ docker-deb: docker-bin ## build image for debian
docker-bin:
docker exec openlan_builder bash -c "cd /opt/openlan && make linux-bin"
docker-tar:
docker exec openlan_builder bash -c "cd /opt/openlan && make linux-tar"
docker: docker-deb ## build docker images
docker-builder: builder ## create a builder
@@ -124,13 +128,13 @@ linux-ceci:
linux-proxy:
GOOS=linux GOARCH=$(ARCH) go build -mod=vendor -ldflags "$(LDFLAGS)" -o $(BD)/openlan-proxy ./cmd/proxy
linux-gzip: install ## build linux packages
linux-tar: install ## build linux packages
@rm -rf $(LIN_DIR).tar.gz
tar -cf $(LIN_DIR).tar $(LIN_DIR) && mv $(LIN_DIR).tar $(BD)
@rm -rf $(LIN_DIR)
gzip -f $(BD)/$(LIN_DIR).tar
linux-bin: linux-gzip ## build linux install binary
linux-bin: update linux-tar ## build linux install binary
@cat $(SD)/dist/rootfs/var/openlan/script/install.sh > $(BD)/$(LIN_DIR).bin && \
echo "__ARCHIVE_BELOW__:" >> $(BD)/$(LIN_DIR).bin && \
cat $(BD)/$(LIN_DIR).tar.gz >> $(BD)/$(LIN_DIR).bin && \

View File

@@ -22,7 +22,8 @@ func (v Version) Url(prefix, name string) string {
func (v Version) Tmpl() string {
return `Version : {{ .Version }}
Build at : {{ .Date}}
Build at : {{ .Date }}
Commit id: {{ .Commit }}
Expire at: {{ .Expire }}
`
}

View File

@@ -12,6 +12,8 @@ func main() {
config.Update(c)
libol.SetLogger(c.Log.File, c.Log.Verbose)
libol.ShowVersion()
cache.Init(&c.Perf)
s := cswitch.NewSwitch(c)
libol.PreNotify()

View File

@@ -6,7 +6,8 @@ var (
Commit string
)
func init() {
Debug("version is %s", Version)
Debug("built on %s", Date)
func ShowVersion() {
Info("Version is %s", Version)
Info("Built on %s", Date)
Info("Commit id %s", Commit)
}

View File

@@ -5,6 +5,7 @@ import "github.com/luscis/openlan/pkg/libol"
type Version struct {
Version string `json:"version"`
Date string `json:"date"`
Commit string `json:"commit"`
Expire string `json:"expire"`
}
@@ -12,6 +13,7 @@ func NewVersionSchema() Version {
return Version{
Version: libol.Version,
Date: libol.Date,
Commit: libol.Commit,
}
}