From 2d5741e5f242cab2377f2c986a9db48136ca6f8b Mon Sep 17 00:00:00 2001 From: Vikramarjuna Malapati Date: Thu, 29 Jan 2026 08:52:38 +0000 Subject: [PATCH 1/4] added support versioning the binaries --- .github/workflows/release.yml | 92 +++++++++++++++++ Makefile | 116 +++++++++++++++++++-- cmd/ami-publisher/main.go | 3 + cmd/builder-tool/main.go | 3 + cmd/disruption-manager/main.go | 3 + cmd/dominator/main.go | 3 + cmd/domtool/main.go | 3 + cmd/filegen-client/main.go | 3 + cmd/filegen-server/main.go | 3 + cmd/fleet-manager/main.go | 3 + cmd/fs2objectcache/main.go | 3 + cmd/fsbench/main.go | 9 +- cmd/fsreadslow/main.go | 9 +- cmd/hyper-control/main.go | 3 + cmd/hypervisor/main.go | 3 + cmd/image-unpacker/main.go | 4 + cmd/imageserver/main.go | 3 + cmd/imagetool/main.go | 3 + cmd/imaginator/main.go | 3 + cmd/installer/main.go | 3 + cmd/installer/make-tarball | 5 +- cmd/logtool/main.go | 3 + cmd/mdb-relayd/main.go | 3 + cmd/mdbd/main.go | 3 + cmd/objecttool/main.go | 3 + cmd/scan/main.go | 3 + cmd/show-cert/main.go | 3 + cmd/srpc-test/main.go | 3 + cmd/subd/main.go | 3 + cmd/subtool/main.go | 3 + cmd/unpacker-tool/main.go | 3 + cmd/vm-control/main.go | 3 + lib/version/version.go | 182 +++++++++++++++++++++++++++++++++ scripts/make-tarball | 5 +- scripts/version.lib | 41 ++++++++ 35 files changed, 527 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 lib/version/version.go create mode 100644 scripts/version.lib diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..141409cb3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,92 @@ +name: Release + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - goos: linux + goarch: amd64 + target: build-linux + - goos: linux + goarch: arm64 + target: build-linux-arm + - goos: darwin + goarch: amd64 + target: build-darwin + - goos: darwin + goarch: arm64 + target: build-darwin-arm + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + + - name: Get version from tag + id: version + run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + + - name: Build + run: make ${{ matrix.target }} + env: + VERSION: ${{ steps.version.outputs.version }} + + - name: Create tarball + run: | + tar -czvf dominator-${{ steps.version.outputs.version }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz -C dist . + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: dominator-${{ matrix.goos }}-${{ matrix.goarch }} + path: dominator-*.tar.gz + retention-days: 1 + + release: + needs: build + runs-on: ubuntu-latest + steps: + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + merge-multiple: true + + - name: Generate checksums + run: | + cd artifacts + sha256sum dominator-*.tar.gz > checksums.txt + cat checksums.txt + + - name: Get version from tag + id: version + run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + files: | + artifacts/dominator-*.tar.gz + artifacts/checksums.txt + generate_release_notes: true + draft: false + prerelease: ${{ contains(steps.version.outputs.version, '-') }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/Makefile b/Makefile index 3d3ab6b1e..a77de09f0 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,128 @@ +# Version variables - calculated from git tags +# Produces SemVer compliant versions: +# v1.2.3 - tagged release (clean) +# v1.2.3-dirty - tagged release with uncommitted changes +# v1.2.3-dev.5+abc1234 - 5 commits after tag on main/master +# v1.2.3-feature-api.5+abc1234 - 5 commits after tag on feature branch +# v1.2.3-feature-api.5+abc1234-dirty - feature branch with uncommitted changes +GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") +GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown") +BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) +GIT_DIRTY := $(shell git diff --quiet 2>/dev/null || echo "-dirty") + +# Calculate SemVer compliant version from git tags +GIT_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null) +COMMITS_SINCE_TAG := $(shell git rev-list $(GIT_TAG)..HEAD --count 2>/dev/null || echo "0") + +# Determine if on main/master branch +IS_MAIN_BRANCH := $(filter $(GIT_BRANCH),main master) + +# Sanitize branch name for SemVer (replace / and _ with -) +BRANCH_SANITIZED := $(subst /,-,$(subst _,-,$(GIT_BRANCH))) + +ifeq ($(GIT_TAG),) + # No tags exist - use dev + VERSION ?= dev+$(GIT_COMMIT)$(GIT_DIRTY) +else ifeq ($(COMMITS_SINCE_TAG),0) + # Exactly on a tag + VERSION ?= $(GIT_TAG)$(GIT_DIRTY) +else ifneq ($(IS_MAIN_BRANCH),) + # On main/master, commits after tag: v1.2.3-dev.N+commit + VERSION ?= $(GIT_TAG)-dev.$(COMMITS_SINCE_TAG)+$(GIT_COMMIT)$(GIT_DIRTY) +else + # On feature branch: v1.2.3-branch-name.N+commit + VERSION ?= $(GIT_TAG)-$(BRANCH_SANITIZED).$(COMMITS_SINCE_TAG)+$(GIT_COMMIT)$(GIT_DIRTY) +endif + +# Package path for version injection +VERSION_PKG := github.com/Cloud-Foundations/Dominator/lib/version + +# Build flags for version injection +LDFLAGS := -X $(VERSION_PKG).Version=$(VERSION) +LDFLAGS += -X $(VERSION_PKG).GitCommit=$(GIT_COMMIT) +LDFLAGS += -X $(VERSION_PKG).GitBranch=$(GIT_BRANCH) +LDFLAGS += -X $(VERSION_PKG).BuildDate=$(BUILD_DATE) + +# Output directory for builds +DIST_DIR := dist + +# Auto-detect OS for build target +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) + BUILD_OS := linux +else ifeq ($(UNAME_S),Darwin) + BUILD_OS := darwin +else + BUILD_OS := linux +endif + +# Auto-detect architecture for build target +UNAME_M := $(shell uname -m) +ifeq ($(UNAME_M),x86_64) + BUILD_ARCH_SUFFIX := +else ifeq ($(UNAME_M),aarch64) + BUILD_ARCH_SUFFIX := -arm +else ifeq ($(UNAME_M),arm64) + BUILD_ARCH_SUFFIX := -arm +else + BUILD_ARCH_SUFFIX := +endif + all: - CGO_ENABLED=0 go install ./cmd/* + CGO_ENABLED=0 go install -ldflags "$(LDFLAGS)" ./cmd/* @cd c; make go vet -composites=false ./cmd/* +build: build-$(BUILD_OS)$(BUILD_ARCH_SUFFIX) + +# Darwin builds exclude Linux-only commands +DARWIN_CMDS := $(filter-out ./cmd/installer ./cmd/subd ./cmd/image-unpacker ./cmd/imaginator,$(wildcard ./cmd/*)) + build-darwin: - (CGO_ENABLED=0 GOOS=darwin go build ./cmd/*) + @mkdir -p $(DIST_DIR) + CGO_ENABLED=0 GOOS=darwin go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/ $(DARWIN_CMDS) + +build-darwin-arm: + @mkdir -p $(DIST_DIR) + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/ $(DARWIN_CMDS) build-linux: - (CGO_ENABLED=0 GOOS=linux go build ./cmd/*) + @mkdir -p $(DIST_DIR) + CGO_ENABLED=0 GOOS=linux go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/ ./cmd/* + +build-linux-arm: + @mkdir -p $(DIST_DIR) + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/ ./cmd/* build-windows: - (CGO_ENABLED=0 GOOS=windows go build ./cmd/*) + @mkdir -p $(DIST_DIR) + CGO_ENABLED=0 GOOS=windows go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/ ./cmd/* + +clean: + rm -rf $(DIST_DIR) install-darwin: - (CGO_ENABLED=0 GOOS=darwin go install ./cmd/*) + CGO_ENABLED=0 GOOS=darwin go install -ldflags "$(LDFLAGS)" ./cmd/* + +install-darwin-arm: + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go install -ldflags "$(LDFLAGS)" ./cmd/* install-linux: - (CGO_ENABLED=0 GOOS=linux go install ./cmd/*) + CGO_ENABLED=0 GOOS=linux go install -ldflags "$(LDFLAGS)" ./cmd/* install-linux-arm: - (CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go install ./cmd/*) + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go install -ldflags "$(LDFLAGS)" ./cmd/* install-windows: - (CGO_ENABLED=0 GOOS=windows go install ./cmd/*) + CGO_ENABLED=0 GOOS=windows go install -ldflags "$(LDFLAGS)" ./cmd/* + +# Print version info (useful for debugging) +.PHONY: version-info +version-info: + @echo "VERSION: $(VERSION)" + @echo "GIT_COMMIT: $(GIT_COMMIT)" + @echo "GIT_BRANCH: $(GIT_BRANCH)" + @echo "BUILD_DATE: $(BUILD_DATE)" disruption-manager.tarball: @./scripts/make-tarball disruption-manager -C $(ETCDIR) ssl diff --git a/cmd/ami-publisher/main.go b/cmd/ami-publisher/main.go index 222192f55..86229ccc8 100644 --- a/cmd/ami-publisher/main.go +++ b/cmd/ami-publisher/main.go @@ -14,6 +14,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" libtags "github.com/Cloud-Foundations/Dominator/lib/tags" + "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -126,6 +127,7 @@ var subcommands = []commands.Command{ } func doMain() int { + checkVersion := version.AddFlags("ami-publisher") if err := loadflags.LoadForCli("ami-publisher"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 @@ -133,6 +135,7 @@ func doMain() int { cmdlogger.SetDatestampsDefault(true) flag.Usage = printUsage flag.Parse() + checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/builder-tool/main.go b/cmd/builder-tool/main.go index 8d26f975e..f78803df5 100644 --- a/cmd/builder-tool/main.go +++ b/cmd/builder-tool/main.go @@ -13,6 +13,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/cmdlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" + "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -125,12 +126,14 @@ func getImageServerClient() *srpc.Client { } func doMain() int { + checkVersion := version.AddFlags("builder-tool") if err := loadflags.LoadForCli("builder-tool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() + checkVersion() if flag.NArg() < 1 { printUsage() return 3 diff --git a/cmd/disruption-manager/main.go b/cmd/disruption-manager/main.go index f448d1ab1..ea5293f95 100644 --- a/cmd/disruption-manager/main.go +++ b/cmd/disruption-manager/main.go @@ -11,6 +11,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/flags/loadflags" "github.com/Cloud-Foundations/Dominator/lib/log/serverlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" + "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -30,6 +31,7 @@ func showErrorAndDie(err error) { } func main() { + checkVersion := version.AddFlags("disruption-manager") if os.Geteuid() == 0 { fmt.Fprintln(os.Stderr, "Do not run the Disruption Manager as root") os.Exit(1) @@ -39,6 +41,7 @@ func main() { os.Exit(1) } flag.Parse() + checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") dm, err := newDisruptionManager(filepath.Join(*stateDir, "state.json"), diff --git a/cmd/dominator/main.go b/cmd/dominator/main.go index 6ba398ffe..dac305753 100644 --- a/cmd/dominator/main.go +++ b/cmd/dominator/main.go @@ -20,6 +20,7 @@ import ( objectserver "github.com/Cloud-Foundations/Dominator/lib/objectserver/filesystem" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" + "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/Dominator/lib/wsyscall" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -87,6 +88,7 @@ func newObjectServer(objectsDir string, logger log.DebugLogger) ( } func main() { + checkVersion := version.AddFlags("dominator") if os.Geteuid() == 0 { fmt.Fprintln(os.Stderr, "Do not run the Dominator as root") os.Exit(1) @@ -96,6 +98,7 @@ func main() { os.Exit(1) } flag.Parse() + checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") srpc.SetDefaultLogger(logger) diff --git a/cmd/domtool/main.go b/cmd/domtool/main.go index 67282d56c..60ef6a5d7 100644 --- a/cmd/domtool/main.go +++ b/cmd/domtool/main.go @@ -14,6 +14,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" "github.com/Cloud-Foundations/Dominator/lib/tags" + "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -123,12 +124,14 @@ func getClient() *srpc.Client { } func doMain() int { + checkVersion := version.AddFlags("domtool") if err := loadflags.LoadForCli("domtool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() + checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/filegen-client/main.go b/cmd/filegen-client/main.go index f6dc70d87..b07cb52c9 100644 --- a/cmd/filegen-client/main.go +++ b/cmd/filegen-client/main.go @@ -17,6 +17,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" "github.com/Cloud-Foundations/Dominator/lib/stringutil" + "github.com/Cloud-Foundations/Dominator/lib/version" proto "github.com/Cloud-Foundations/Dominator/proto/filegenerator" ) @@ -105,12 +106,14 @@ func handleUpdates(hostname string, updateChannel <-chan []proto.FileInfo, } func main() { + checkVersion := version.AddFlags("filegen-client") if err := loadflags.LoadForCli("filegen-client"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Usage = printUsage flag.Parse() + checkVersion() if flag.NArg() != 2 { printUsage() os.Exit(2) diff --git a/cmd/filegen-server/main.go b/cmd/filegen-server/main.go index 88bf5a965..4ff127bda 100644 --- a/cmd/filegen-server/main.go +++ b/cmd/filegen-server/main.go @@ -15,6 +15,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/serverlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" + "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -35,6 +36,7 @@ func printUsage() { } func main() { + checkVersion := version.AddFlags("filegen-server") if os.Geteuid() == 0 { fmt.Fprintln(os.Stderr, "Do not run the filegen server as root") os.Exit(1) @@ -45,6 +47,7 @@ func main() { } flag.Usage = printUsage flag.Parse() + checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") srpc.SetDefaultLogger(logger) diff --git a/cmd/fleet-manager/main.go b/cmd/fleet-manager/main.go index 877f7e687..82d481d7d 100644 --- a/cmd/fleet-manager/main.go +++ b/cmd/fleet-manager/main.go @@ -21,6 +21,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/proxy" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" + "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -63,11 +64,13 @@ func doCheck(logger log.DebugLogger) { } func main() { + checkVersion := version.AddFlags("fleet-manager") if err := loadflags.LoadForDaemon("fleet-manager"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() + checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") srpc.SetDefaultLogger(logger) diff --git a/cmd/fs2objectcache/main.go b/cmd/fs2objectcache/main.go index d5db87a41..45e936c2e 100644 --- a/cmd/fs2objectcache/main.go +++ b/cmd/fs2objectcache/main.go @@ -7,6 +7,7 @@ import ( "path" "github.com/Cloud-Foundations/Dominator/lib/flags/loadflags" + "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -31,11 +32,13 @@ func init() { } func main() { + checkVersion := version.AddFlags("fs2objectcache") if err := loadflags.LoadForCli("fs2objectcache"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() + checkVersion() if *rootDir == "" { fmt.Fprintln(os.Stderr, "rootDir unspecified") os.Exit(1) diff --git a/cmd/fsbench/main.go b/cmd/fsbench/main.go index 5111f5f5f..8cdd80c32 100644 --- a/cmd/fsbench/main.go +++ b/cmd/fsbench/main.go @@ -1,17 +1,22 @@ package main import ( + "flag" "fmt" "os" "github.com/Cloud-Foundations/Dominator/lib/fsbench" + "github.com/Cloud-Foundations/Dominator/lib/version" ) // Benchmark the read speed of the underlying block device for a given file. func main() { + checkVersion := version.AddFlags("fsbench") + flag.Parse() + checkVersion() pathname := "/" - if len(os.Args) == 2 { - pathname = os.Args[1] + if flag.NArg() == 1 { + pathname = flag.Arg(0) } bytesPerSecond, blocksPerSecond, err := fsbench.GetReadSpeed(pathname) if err != nil { diff --git a/cmd/fsreadslow/main.go b/cmd/fsreadslow/main.go index fb4900766..bde4036ec 100644 --- a/cmd/fsreadslow/main.go +++ b/cmd/fsreadslow/main.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "flag" "fmt" "io" "os" @@ -10,13 +11,17 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/format" "github.com/Cloud-Foundations/Dominator/lib/fsbench" "github.com/Cloud-Foundations/Dominator/lib/fsrateio" + "github.com/Cloud-Foundations/Dominator/lib/version" ) // Benchmark the read speed of the underlying block device for a given file. func main() { + checkVersion := version.AddFlags("fsreadslow") + flag.Parse() + checkVersion() pathname := "/" - if len(os.Args) == 2 { - pathname = os.Args[1] + if flag.NArg() == 1 { + pathname = flag.Arg(0) } bytesPerSecond, blocksPerSecond, err := fsbench.GetReadSpeed(pathname) if err != nil { diff --git a/cmd/hyper-control/main.go b/cmd/hyper-control/main.go index d06f46fa0..6e6d2a8b8 100644 --- a/cmd/hyper-control/main.go +++ b/cmd/hyper-control/main.go @@ -17,6 +17,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" "github.com/Cloud-Foundations/Dominator/lib/tags" + "github.com/Cloud-Foundations/Dominator/lib/version" proto "github.com/Cloud-Foundations/Dominator/proto/hypervisor" ) @@ -182,12 +183,14 @@ func loadCerts() error { } func doMain() int { + checkVersion := version.AddFlags("hyper-control") if err := loadflags.LoadForCli("hyper-control"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() + checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/hypervisor/main.go b/cmd/hypervisor/main.go index d2757c86b..4698d78b3 100644 --- a/cmd/hypervisor/main.go +++ b/cmd/hypervisor/main.go @@ -25,6 +25,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/net" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" + "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -109,12 +110,14 @@ func processCommand(args []string) { } func main() { + checkVersion := version.AddFlags("hypervisor") if err := loadflags.LoadForDaemon("hypervisor"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Usage = printUsage flag.Parse() + checkVersion() processCommand(flag.Args()) } diff --git a/cmd/image-unpacker/main.go b/cmd/image-unpacker/main.go index 30996770a..f8d13f3da 100644 --- a/cmd/image-unpacker/main.go +++ b/cmd/image-unpacker/main.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package main @@ -16,6 +17,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/serverlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" + "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -37,11 +39,13 @@ var ( ) func main() { + checkVersion := version.AddFlags("image-unpacker") if err := loadflags.LoadForDaemon("image-unpacker"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() + checkVersion() tricorder.RegisterFlags() if os.Geteuid() != 0 { fmt.Fprintln(os.Stderr, "Must run the Image Unpacker as root") diff --git a/cmd/imageserver/main.go b/cmd/imageserver/main.go index 4912780d3..e606ed85c 100644 --- a/cmd/imageserver/main.go +++ b/cmd/imageserver/main.go @@ -15,6 +15,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/objectserver/filesystem" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" + "github.com/Cloud-Foundations/Dominator/lib/version" objectserverRpcd "github.com/Cloud-Foundations/Dominator/objectserver/rpcd" "github.com/Cloud-Foundations/tricorder/go/healthserver" "github.com/Cloud-Foundations/tricorder/go/tricorder" @@ -57,6 +58,7 @@ var ( ) func main() { + checkVersion := version.AddFlags("imageserver") if os.Geteuid() == 0 { fmt.Fprintln(os.Stderr, "Do not run the Image Server as root") os.Exit(1) @@ -66,6 +68,7 @@ func main() { os.Exit(1) } flag.Parse() + checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") srpc.SetDefaultLogger(logger) diff --git a/cmd/imagetool/main.go b/cmd/imagetool/main.go index 71116ff7b..d72998d2a 100644 --- a/cmd/imagetool/main.go +++ b/cmd/imagetool/main.go @@ -23,6 +23,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" "github.com/Cloud-Foundations/Dominator/lib/tags" + "github.com/Cloud-Foundations/Dominator/lib/version" ) type objectsFlushGetter interface { @@ -323,12 +324,14 @@ func makeListSelector(arg string) filesystem.ListSelector { var listFilter *filter.Filter func doMain() int { + checkVersion := version.AddFlags("imagetool") if err := loadflags.LoadForCli("imagetool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() + checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/imaginator/main.go b/cmd/imaginator/main.go index 02c43e392..ff97f5b97 100644 --- a/cmd/imaginator/main.go +++ b/cmd/imaginator/main.go @@ -19,6 +19,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/serverlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" + "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -69,11 +70,13 @@ func init() { } func main() { + checkVersion := version.AddFlags("imaginator") if err := loadflags.LoadForDaemon("imaginator"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() + checkVersion() tricorder.RegisterFlags() if os.Geteuid() != 0 { fmt.Fprintln(os.Stderr, "Must run the Image Builder as root") diff --git a/cmd/installer/main.go b/cmd/installer/main.go index 345211e24..360edaf5d 100644 --- a/cmd/installer/main.go +++ b/cmd/installer/main.go @@ -27,6 +27,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/logbuf" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" + "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -338,12 +339,14 @@ func processCommand(args []string) { } func main() { + checkVersion := version.AddFlags("installer") if err := loadflags.LoadForDaemon("installer"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Usage = printUsage flag.Parse() + checkVersion() processCommand(flag.Args()) } diff --git a/cmd/installer/make-tarball b/cmd/installer/make-tarball index 03e89c38b..9375ff0c8 100755 --- a/cmd/installer/make-tarball +++ b/cmd/installer/make-tarball @@ -8,7 +8,10 @@ shift readonly bin="$GOPATH/bin/$command" readonly target="/tmp/$LOGNAME/$command.tar.gz" -CGO_ENABLED=0 go install ./cmd/$command +# Source version library for LDFLAGS +. ./scripts/version.lib + +CGO_ENABLED=0 go install -ldflags "$LDFLAGS" ./cmd/$command strip -o "$bin~" "$bin" if cmp -s "$bin~" "$bin"; then diff --git a/cmd/logtool/main.go b/cmd/logtool/main.go index f67cd2944..47137b813 100644 --- a/cmd/logtool/main.go +++ b/cmd/logtool/main.go @@ -11,6 +11,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/cmdlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" + "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -69,12 +70,14 @@ func dialAll(addrs []string) ([]*srpc.Client, error) { } func doMain() int { + checkVersion := version.AddFlags("logtool") if err := loadflags.LoadForCli("logtool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() + checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/mdb-relayd/main.go b/cmd/mdb-relayd/main.go index b15546fd9..7cae36f6d 100644 --- a/cmd/mdb-relayd/main.go +++ b/cmd/mdb-relayd/main.go @@ -11,6 +11,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/mdb" "github.com/Cloud-Foundations/Dominator/lib/mdb/mdbd" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" + "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -35,12 +36,14 @@ func showMdb(mdb *mdb.Mdb) { } func main() { + checkVersion := version.AddFlags("mdb-relayd") if err := loadflags.LoadForDaemon("mdb-relayd"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Usage = printUsage flag.Parse() + checkVersion() if flag.NArg() != 0 { printUsage() os.Exit(2) diff --git a/cmd/mdbd/main.go b/cmd/mdbd/main.go index 3e2ad981b..72fb4c73a 100644 --- a/cmd/mdbd/main.go +++ b/cmd/mdbd/main.go @@ -18,6 +18,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/mdb" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" + "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -216,6 +217,7 @@ func showErrorAndDie(err error) { } func main() { + checkVersion := version.AddFlags("mdbd") if os.Geteuid() == 0 { fmt.Fprintln(os.Stderr, "Do not run the MDB daemon as root") os.Exit(1) @@ -226,6 +228,7 @@ func main() { } flag.Usage = printUsage flag.Parse() + checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") if *debug { // Backwards compatibility. diff --git a/cmd/objecttool/main.go b/cmd/objecttool/main.go index be2ba9a9f..855565236 100644 --- a/cmd/objecttool/main.go +++ b/cmd/objecttool/main.go @@ -14,6 +14,7 @@ import ( objectclient "github.com/Cloud-Foundations/Dominator/lib/objectserver/client" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" + "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -56,12 +57,14 @@ func getObjectServer() objectserver.ObjectServer { } func doMain() int { + checkVersion := version.AddFlags("objecttool") if err := loadflags.LoadForCli("objecttool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() + checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/scan/main.go b/cmd/scan/main.go index 588391d15..7e31ab33f 100644 --- a/cmd/scan/main.go +++ b/cmd/scan/main.go @@ -19,6 +19,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/fsrateio" "github.com/Cloud-Foundations/Dominator/lib/json" "github.com/Cloud-Foundations/Dominator/lib/memstats" + "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/Dominator/sub/scanner" ) @@ -41,11 +42,13 @@ var ( ) func main() { + checkVersion := version.AddFlags("scan") if err := loadflags.LoadForCli("scan"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() + checkVersion() var err error var configuration scanner.Configuration configuration.ScanFilter, err = filter.New(nil) diff --git a/cmd/show-cert/main.go b/cmd/show-cert/main.go index 60efdc0f1..a4a2bb7a7 100644 --- a/cmd/show-cert/main.go +++ b/cmd/show-cert/main.go @@ -22,6 +22,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/cmdlogger" "github.com/Cloud-Foundations/Dominator/lib/sshutil" "github.com/Cloud-Foundations/Dominator/lib/stringutil" + "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/Dominator/lib/x509util" ) @@ -297,12 +298,14 @@ func showX509Cert(data []byte, logger log.DebugLogger) { } func doMain() int { + checkVersion := version.AddFlags("show-cert") err := loadflags.LoadForCli("show-cert") if err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Parse() + checkVersion() logger := cmdlogger.New() if err := loadX509CAs(*caFile, x509CaPoolMap); err != nil { fmt.Fprintln(os.Stderr, err) diff --git a/cmd/srpc-test/main.go b/cmd/srpc-test/main.go index 20109ec79..72c7a684b 100644 --- a/cmd/srpc-test/main.go +++ b/cmd/srpc-test/main.go @@ -12,6 +12,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/serverlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" + "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/Dominator/proto/test" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -42,11 +43,13 @@ func doMain(logger log.DebugLogger) error { } func main() { + checkVersion := version.AddFlags("srpc-test") if err := loadflags.LoadForDaemon("srpc-test"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() + checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") srpc.SetDefaultLogger(logger) diff --git a/cmd/subd/main.go b/cmd/subd/main.go index 576b1bd87..07f4ce632 100644 --- a/cmd/subd/main.go +++ b/cmd/subd/main.go @@ -28,6 +28,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/rateio" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" + "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/Dominator/lib/wsyscall" "github.com/Cloud-Foundations/Dominator/proto/sub" "github.com/Cloud-Foundations/Dominator/sub/httpd" @@ -243,11 +244,13 @@ func writePidfile() { func main() { // Ensure the startup thread is reserved for the main function. runtime.LockOSThread() + checkVersion := version.AddFlags("subd") if err := loadflags.LoadForDaemon("subd"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() + checkVersion() if *testExternallyPatchable { runTestAndExit(checkExternallyPatchable) } diff --git a/cmd/subtool/main.go b/cmd/subtool/main.go index 7c1eefdb6..1d1042312 100644 --- a/cmd/subtool/main.go +++ b/cmd/subtool/main.go @@ -15,6 +15,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/debuglogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" + "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -149,12 +150,14 @@ var subcommands = []commands.Command{ } func doMain() int { + checkVersion := version.AddFlags("subtool") if err := loadflags.LoadForCli("subtool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() + checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/unpacker-tool/main.go b/cmd/unpacker-tool/main.go index 94901655b..fe74269bb 100644 --- a/cmd/unpacker-tool/main.go +++ b/cmd/unpacker-tool/main.go @@ -11,6 +11,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/cmdlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" + "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -58,12 +59,14 @@ func getClient() *srpc.Client { } func doMain() int { + checkVersion := version.AddFlags("unpacker-tool") if err := loadflags.LoadForCli("unpacker-tool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() + checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/vm-control/main.go b/cmd/vm-control/main.go index b2347c51b..caad08d8d 100644 --- a/cmd/vm-control/main.go +++ b/cmd/vm-control/main.go @@ -17,6 +17,7 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" "github.com/Cloud-Foundations/Dominator/lib/tags" + "github.com/Cloud-Foundations/Dominator/lib/version" hyper_proto "github.com/Cloud-Foundations/Dominator/proto/hypervisor" ) @@ -292,12 +293,14 @@ var subcommands = []commands.Command{ } func doMain() int { + checkVersion := version.AddFlags("vm-control") if err := loadflags.LoadForCli("vm-control"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() + checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/lib/version/version.go b/lib/version/version.go new file mode 100644 index 000000000..e3762fb59 --- /dev/null +++ b/lib/version/version.go @@ -0,0 +1,182 @@ +// Package version provides build version information for all binaries. +// +// Version information is set via ldflags at build time (from git tags). +// Falls back to debug.ReadBuildInfo for dev builds. +package version + +import ( + "flag" + "fmt" + "os" + "runtime" + "runtime/debug" + "strings" +) + +// Set via ldflags at build time: +// +// go build -ldflags "-X github.com/Cloud-Foundations/Dominator/lib/version.Version=v1.2.3" +var ( + Version = "" + GitCommit = "" + GitBranch = "" + BuildDate = "" +) + +// Info contains version information +type Info struct { + Version string `json:"version"` + GitCommit string `json:"gitCommit"` + GitBranch string `json:"gitBranch"` + BuildDate string `json:"buildDate"` + GoVersion string `json:"goVersion"` + Dirty bool `json:"dirty"` +} + +// Get returns version information, with fallbacks for dev builds +func Get() Info { + // Get VCS info once for commit, dirty, and build time + vcs := getVCSInfo() + + commit := GitCommit + dirty := false + if commit == "" { + commit = vcs.revision + dirty = vcs.dirty + } else { + dirty = strings.HasSuffix(commit, "-dirty") || + strings.HasSuffix(Version, "-dirty") + } + + branch := GitBranch + if branch == "" { + branch = "unknown" + } + + buildDate := BuildDate + if buildDate == "" { + buildDate = vcs.buildTime + } + + // Build version string + version := Version + if version == "" { + // No ldflags provided - build dev version from VCS info + version = "dev" + if vcs.revision != "unknown" { + version += "+" + vcs.revision + } + if vcs.dirty { + version += "-dirty" + } + } + + // Build commit display string (without -dirty suffix, that's in version) + commitDisplay := commit + if idx := strings.Index(commitDisplay, "-dirty"); idx != -1 { + commitDisplay = commitDisplay[:idx] + } + + return Info{ + Version: version, + GitCommit: commitDisplay, + GitBranch: branch, + BuildDate: buildDate, + GoVersion: runtime.Version(), + Dirty: dirty, + } +} + +// String returns a single-line version string +func (i Info) String() string { + return fmt.Sprintf("%s (commit: %s, branch: %s, built: %s)", + i.Version, i.GitCommit, i.GitBranch, i.BuildDate) +} + +// Short returns just the version number +func (i Info) Short() string { + return i.Version +} + +// Full returns multi-line detailed version info +func (i Info) Full(binaryName string) string { + return fmt.Sprintf(`%s %s + Commit: %s + Branch: %s + Built: %s + Go: %s`, + binaryName, i.Version, i.GitCommit, + i.GitBranch, i.BuildDate, i.GoVersion) +} + +// vcsInfo holds version control information from Go build info +type vcsInfo struct { + revision string + buildTime string + dirty bool +} + +// getVCSInfo extracts all VCS info from Go build info in a single pass +func getVCSInfo() vcsInfo { + info := vcsInfo{ + revision: "unknown", + buildTime: "unknown", + } + + buildInfo, ok := debug.ReadBuildInfo() + if !ok { + return info + } + + for _, s := range buildInfo.Settings { + switch s.Key { + case "vcs.revision": + if len(s.Value) > 8 { + info.revision = s.Value[:8] + } else { + info.revision = s.Value + } + case "vcs.time": + info.buildTime = s.Value + case "vcs.modified": + info.dirty = s.Value == "true" + } + } + + return info +} + +// Flag variables for version command-line handling +var ( + showVersion *bool + showShort *bool +) + +// AddFlags registers -version and -short flags. Call this before flag.Parse(). +// Returns a function that should be called after flag.Parse() to handle +// the version flags (prints version and exits if -version was passed). +// +// Usage: +// +// func main() { +// checkVersion := version.AddFlags("myapp") +// // ... other flag setup ... +// flag.Parse() +// checkVersion() +// // ... rest of main ... +// } +func AddFlags(binaryName string) func() { + showVersion = flag.Bool("version", false, "Print version information and exit") + showShort = flag.Bool("short", false, "Print short version (use with -version)") + + return func() { + if *showVersion { + if *showShort { + fmt.Println(Get().Short()) + } else { + fmt.Println(Get().Full(binaryName)) + } + os.Exit(0) + } + } +} diff --git a/scripts/make-tarball b/scripts/make-tarball index ddfd96f9f..bf0d59022 100755 --- a/scripts/make-tarball +++ b/scripts/make-tarball @@ -8,7 +8,10 @@ shift readonly bin="$GOPATH/bin/$command" readonly target="/tmp/$LOGNAME/$command.tar.gz" -CGO_ENABLED=0 go install ./cmd/$command +# Source version library for LDFLAGS +. ./scripts/version.lib + +CGO_ENABLED=0 go install -ldflags "$LDFLAGS" ./cmd/$command strip -o "$bin~" "$bin" if cmp -s "$bin~" "$bin"; then diff --git a/scripts/version.lib b/scripts/version.lib new file mode 100644 index 000000000..02d76806f --- /dev/null +++ b/scripts/version.lib @@ -0,0 +1,41 @@ +# Version calculation library +# Source this file to get VERSION and LDFLAGS variables +# +# Usage: +# . ./scripts/version.lib +# go build -ldflags "$LDFLAGS" ./cmd/... + +# Get version info from git +GO_MODULE=$(head -1 go.mod | awk '{print $2}') +VERSION_PKG="${GO_MODULE}/lib/version" +GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") +GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown") +BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) + +# Calculate version from git tags +GIT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") +COMMITS_SINCE=$(git rev-list "${GIT_TAG}..HEAD" --count 2>/dev/null || echo "0") + +if [ "$COMMITS_SINCE" = "0" ]; then + # On a tag - check for dirty + if git diff --quiet 2>/dev/null; then + VERSION="$GIT_TAG" + else + VERSION="${GIT_TAG}-dirty" + fi +else + # After a tag - add prerelease info + if [ "$GIT_BRANCH" = "main" ] || [ "$GIT_BRANCH" = "master" ]; then + PRERELEASE="dev" + else + # Sanitize branch name for semver + PRERELEASE=$(echo "$GIT_BRANCH" | sed 's/[^a-zA-Z0-9]/-/g' | cut -c1-20) + fi + VERSION="${GIT_TAG}-${PRERELEASE}.${COMMITS_SINCE}+${GIT_COMMIT}" + if ! git diff --quiet 2>/dev/null; then + VERSION="${VERSION}-dirty" + fi +fi + +LDFLAGS="-X ${VERSION_PKG}.Version=${VERSION} -X ${VERSION_PKG}.GitCommit=${GIT_COMMIT} -X ${VERSION_PKG}.GitBranch=${GIT_BRANCH} -X ${VERSION_PKG}.BuildDate=${BUILD_DATE}" + From 00ccacb8e699037b4dbcabe86eca5b0610dc0e00 Mon Sep 17 00:00:00 2001 From: Vikramarjuna Malapati Date: Wed, 18 Feb 2026 14:47:13 +0000 Subject: [PATCH 2/4] added versioning support for the binaries --- .github/workflows/release.yml | 92 -------------------------- Makefile | 117 +++------------------------------ cmd/ami-publisher/main.go | 3 - cmd/builder-tool/main.go | 3 - cmd/disruption-manager/main.go | 3 - cmd/dominator/main.go | 3 - cmd/domtool/main.go | 3 - cmd/filegen-client/main.go | 3 - cmd/filegen-server/main.go | 3 - cmd/fleet-manager/main.go | 3 - cmd/fs2objectcache/main.go | 3 - cmd/fsbench/main.go | 9 +-- cmd/fsreadslow/main.go | 9 +-- cmd/hyper-control/main.go | 3 - cmd/hypervisor/main.go | 3 - cmd/image-unpacker/main.go | 4 -- cmd/imageserver/main.go | 3 - cmd/imagetool/main.go | 3 - cmd/imaginator/main.go | 3 - cmd/installer/main.go | 3 - cmd/installer/make-tarball | 2 +- cmd/logtool/main.go | 3 - cmd/mdb-relayd/main.go | 3 - cmd/mdbd/main.go | 3 - cmd/objecttool/main.go | 3 - cmd/scan/main.go | 3 - cmd/show-cert/main.go | 3 - cmd/srpc-test/main.go | 3 - cmd/subd/main.go | 3 - cmd/subtool/main.go | 3 - cmd/unpacker-tool/main.go | 3 - cmd/vm-control/main.go | 3 - lib/flags/loadflags/api.go | 2 + lib/flags/loadflags/impl.go | 10 +++ scripts/make-tarball | 2 +- 35 files changed, 28 insertions(+), 297 deletions(-) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 141409cb3..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,92 +0,0 @@ -name: Release - -on: - push: - tags: - - 'v*' - -permissions: - contents: write - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - include: - - goos: linux - goarch: amd64 - target: build-linux - - goos: linux - goarch: arm64 - target: build-linux-arm - - goos: darwin - goarch: amd64 - target: build-darwin - - goos: darwin - goarch: arm64 - target: build-darwin-arm - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - cache: true - - - name: Get version from tag - id: version - run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT - - - name: Build - run: make ${{ matrix.target }} - env: - VERSION: ${{ steps.version.outputs.version }} - - - name: Create tarball - run: | - tar -czvf dominator-${{ steps.version.outputs.version }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz -C dist . - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: dominator-${{ matrix.goos }}-${{ matrix.goarch }} - path: dominator-*.tar.gz - retention-days: 1 - - release: - needs: build - runs-on: ubuntu-latest - steps: - - name: Download all artifacts - uses: actions/download-artifact@v4 - with: - path: artifacts - merge-multiple: true - - - name: Generate checksums - run: | - cd artifacts - sha256sum dominator-*.tar.gz > checksums.txt - cat checksums.txt - - - name: Get version from tag - id: version - run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT - - - name: Create GitHub Release - uses: softprops/action-gh-release@v2 - with: - files: | - artifacts/dominator-*.tar.gz - artifacts/checksums.txt - generate_release_notes: true - draft: false - prerelease: ${{ contains(steps.version.outputs.version, '-') }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - diff --git a/Makefile b/Makefile index a77de09f0..522242fd0 100644 --- a/Makefile +++ b/Makefile @@ -1,128 +1,31 @@ -# Version variables - calculated from git tags -# Produces SemVer compliant versions: -# v1.2.3 - tagged release (clean) -# v1.2.3-dirty - tagged release with uncommitted changes -# v1.2.3-dev.5+abc1234 - 5 commits after tag on main/master -# v1.2.3-feature-api.5+abc1234 - 5 commits after tag on feature branch -# v1.2.3-feature-api.5+abc1234-dirty - feature branch with uncommitted changes -GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") -GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown") -BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) -GIT_DIRTY := $(shell git diff --quiet 2>/dev/null || echo "-dirty") - -# Calculate SemVer compliant version from git tags -GIT_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null) -COMMITS_SINCE_TAG := $(shell git rev-list $(GIT_TAG)..HEAD --count 2>/dev/null || echo "0") - -# Determine if on main/master branch -IS_MAIN_BRANCH := $(filter $(GIT_BRANCH),main master) - -# Sanitize branch name for SemVer (replace / and _ with -) -BRANCH_SANITIZED := $(subst /,-,$(subst _,-,$(GIT_BRANCH))) - -ifeq ($(GIT_TAG),) - # No tags exist - use dev - VERSION ?= dev+$(GIT_COMMIT)$(GIT_DIRTY) -else ifeq ($(COMMITS_SINCE_TAG),0) - # Exactly on a tag - VERSION ?= $(GIT_TAG)$(GIT_DIRTY) -else ifneq ($(IS_MAIN_BRANCH),) - # On main/master, commits after tag: v1.2.3-dev.N+commit - VERSION ?= $(GIT_TAG)-dev.$(COMMITS_SINCE_TAG)+$(GIT_COMMIT)$(GIT_DIRTY) -else - # On feature branch: v1.2.3-branch-name.N+commit - VERSION ?= $(GIT_TAG)-$(BRANCH_SANITIZED).$(COMMITS_SINCE_TAG)+$(GIT_COMMIT)$(GIT_DIRTY) -endif - -# Package path for version injection -VERSION_PKG := github.com/Cloud-Foundations/Dominator/lib/version - -# Build flags for version injection -LDFLAGS := -X $(VERSION_PKG).Version=$(VERSION) -LDFLAGS += -X $(VERSION_PKG).GitCommit=$(GIT_COMMIT) -LDFLAGS += -X $(VERSION_PKG).GitBranch=$(GIT_BRANCH) -LDFLAGS += -X $(VERSION_PKG).BuildDate=$(BUILD_DATE) - -# Output directory for builds -DIST_DIR := dist - -# Auto-detect OS for build target -UNAME_S := $(shell uname -s) -ifeq ($(UNAME_S),Linux) - BUILD_OS := linux -else ifeq ($(UNAME_S),Darwin) - BUILD_OS := darwin -else - BUILD_OS := linux -endif - -# Auto-detect architecture for build target -UNAME_M := $(shell uname -m) -ifeq ($(UNAME_M),x86_64) - BUILD_ARCH_SUFFIX := -else ifeq ($(UNAME_M),aarch64) - BUILD_ARCH_SUFFIX := -arm -else ifeq ($(UNAME_M),arm64) - BUILD_ARCH_SUFFIX := -arm -else - BUILD_ARCH_SUFFIX := -endif +# Get version LDFLAGS from scripts/version.lib +LDFLAGS := $(shell . ./scripts/version.lib && echo "$$LDFLAGS") all: - CGO_ENABLED=0 go install -ldflags "$(LDFLAGS)" ./cmd/* + CGO_ENABLED=0 go install -ldflags '$(LDFLAGS)' ./cmd/* @cd c; make go vet -composites=false ./cmd/* -build: build-$(BUILD_OS)$(BUILD_ARCH_SUFFIX) - -# Darwin builds exclude Linux-only commands -DARWIN_CMDS := $(filter-out ./cmd/installer ./cmd/subd ./cmd/image-unpacker ./cmd/imaginator,$(wildcard ./cmd/*)) - build-darwin: - @mkdir -p $(DIST_DIR) - CGO_ENABLED=0 GOOS=darwin go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/ $(DARWIN_CMDS) - -build-darwin-arm: - @mkdir -p $(DIST_DIR) - CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/ $(DARWIN_CMDS) + CGO_ENABLED=0 GOOS=darwin go build -ldflags '$(LDFLAGS)' ./cmd/* build-linux: - @mkdir -p $(DIST_DIR) - CGO_ENABLED=0 GOOS=linux go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/ ./cmd/* - -build-linux-arm: - @mkdir -p $(DIST_DIR) - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/ ./cmd/* + CGO_ENABLED=0 GOOS=linux go build -ldflags '$(LDFLAGS)' ./cmd/* build-windows: - @mkdir -p $(DIST_DIR) - CGO_ENABLED=0 GOOS=windows go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/ ./cmd/* - -clean: - rm -rf $(DIST_DIR) + CGO_ENABLED=0 GOOS=windows go build -ldflags '$(LDFLAGS)' ./cmd/* install-darwin: - CGO_ENABLED=0 GOOS=darwin go install -ldflags "$(LDFLAGS)" ./cmd/* - -install-darwin-arm: - CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go install -ldflags "$(LDFLAGS)" ./cmd/* + CGO_ENABLED=0 GOOS=darwin go install -ldflags '$(LDFLAGS)' ./cmd/* install-linux: - CGO_ENABLED=0 GOOS=linux go install -ldflags "$(LDFLAGS)" ./cmd/* + CGO_ENABLED=0 GOOS=linux go install -ldflags '$(LDFLAGS)' ./cmd/* install-linux-arm: - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go install -ldflags "$(LDFLAGS)" ./cmd/* + CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go install -ldflags '$(LDFLAGS)' ./cmd/* install-windows: - CGO_ENABLED=0 GOOS=windows go install -ldflags "$(LDFLAGS)" ./cmd/* - -# Print version info (useful for debugging) -.PHONY: version-info -version-info: - @echo "VERSION: $(VERSION)" - @echo "GIT_COMMIT: $(GIT_COMMIT)" - @echo "GIT_BRANCH: $(GIT_BRANCH)" - @echo "BUILD_DATE: $(BUILD_DATE)" + CGO_ENABLED=0 GOOS=windows go install -ldflags '$(LDFLAGS)' ./cmd/* disruption-manager.tarball: @./scripts/make-tarball disruption-manager -C $(ETCDIR) ssl diff --git a/cmd/ami-publisher/main.go b/cmd/ami-publisher/main.go index 86229ccc8..222192f55 100644 --- a/cmd/ami-publisher/main.go +++ b/cmd/ami-publisher/main.go @@ -14,7 +14,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" libtags "github.com/Cloud-Foundations/Dominator/lib/tags" - "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -127,7 +126,6 @@ var subcommands = []commands.Command{ } func doMain() int { - checkVersion := version.AddFlags("ami-publisher") if err := loadflags.LoadForCli("ami-publisher"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 @@ -135,7 +133,6 @@ func doMain() int { cmdlogger.SetDatestampsDefault(true) flag.Usage = printUsage flag.Parse() - checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/builder-tool/main.go b/cmd/builder-tool/main.go index f78803df5..8d26f975e 100644 --- a/cmd/builder-tool/main.go +++ b/cmd/builder-tool/main.go @@ -13,7 +13,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/cmdlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" - "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -126,14 +125,12 @@ func getImageServerClient() *srpc.Client { } func doMain() int { - checkVersion := version.AddFlags("builder-tool") if err := loadflags.LoadForCli("builder-tool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() - checkVersion() if flag.NArg() < 1 { printUsage() return 3 diff --git a/cmd/disruption-manager/main.go b/cmd/disruption-manager/main.go index ea5293f95..f448d1ab1 100644 --- a/cmd/disruption-manager/main.go +++ b/cmd/disruption-manager/main.go @@ -11,7 +11,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/flags/loadflags" "github.com/Cloud-Foundations/Dominator/lib/log/serverlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" - "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -31,7 +30,6 @@ func showErrorAndDie(err error) { } func main() { - checkVersion := version.AddFlags("disruption-manager") if os.Geteuid() == 0 { fmt.Fprintln(os.Stderr, "Do not run the Disruption Manager as root") os.Exit(1) @@ -41,7 +39,6 @@ func main() { os.Exit(1) } flag.Parse() - checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") dm, err := newDisruptionManager(filepath.Join(*stateDir, "state.json"), diff --git a/cmd/dominator/main.go b/cmd/dominator/main.go index dac305753..6ba398ffe 100644 --- a/cmd/dominator/main.go +++ b/cmd/dominator/main.go @@ -20,7 +20,6 @@ import ( objectserver "github.com/Cloud-Foundations/Dominator/lib/objectserver/filesystem" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" - "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/Dominator/lib/wsyscall" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -88,7 +87,6 @@ func newObjectServer(objectsDir string, logger log.DebugLogger) ( } func main() { - checkVersion := version.AddFlags("dominator") if os.Geteuid() == 0 { fmt.Fprintln(os.Stderr, "Do not run the Dominator as root") os.Exit(1) @@ -98,7 +96,6 @@ func main() { os.Exit(1) } flag.Parse() - checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") srpc.SetDefaultLogger(logger) diff --git a/cmd/domtool/main.go b/cmd/domtool/main.go index 60ef6a5d7..67282d56c 100644 --- a/cmd/domtool/main.go +++ b/cmd/domtool/main.go @@ -14,7 +14,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" "github.com/Cloud-Foundations/Dominator/lib/tags" - "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -124,14 +123,12 @@ func getClient() *srpc.Client { } func doMain() int { - checkVersion := version.AddFlags("domtool") if err := loadflags.LoadForCli("domtool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() - checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/filegen-client/main.go b/cmd/filegen-client/main.go index b07cb52c9..f6dc70d87 100644 --- a/cmd/filegen-client/main.go +++ b/cmd/filegen-client/main.go @@ -17,7 +17,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" "github.com/Cloud-Foundations/Dominator/lib/stringutil" - "github.com/Cloud-Foundations/Dominator/lib/version" proto "github.com/Cloud-Foundations/Dominator/proto/filegenerator" ) @@ -106,14 +105,12 @@ func handleUpdates(hostname string, updateChannel <-chan []proto.FileInfo, } func main() { - checkVersion := version.AddFlags("filegen-client") if err := loadflags.LoadForCli("filegen-client"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Usage = printUsage flag.Parse() - checkVersion() if flag.NArg() != 2 { printUsage() os.Exit(2) diff --git a/cmd/filegen-server/main.go b/cmd/filegen-server/main.go index 4ff127bda..88bf5a965 100644 --- a/cmd/filegen-server/main.go +++ b/cmd/filegen-server/main.go @@ -15,7 +15,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/serverlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" - "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -36,7 +35,6 @@ func printUsage() { } func main() { - checkVersion := version.AddFlags("filegen-server") if os.Geteuid() == 0 { fmt.Fprintln(os.Stderr, "Do not run the filegen server as root") os.Exit(1) @@ -47,7 +45,6 @@ func main() { } flag.Usage = printUsage flag.Parse() - checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") srpc.SetDefaultLogger(logger) diff --git a/cmd/fleet-manager/main.go b/cmd/fleet-manager/main.go index f231c0b48..1176fc69e 100644 --- a/cmd/fleet-manager/main.go +++ b/cmd/fleet-manager/main.go @@ -21,7 +21,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/proxy" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" - "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -64,13 +63,11 @@ func doCheck(logger log.DebugLogger) { } func main() { - checkVersion := version.AddFlags("fleet-manager") if err := loadflags.LoadForDaemon("fleet-manager"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() - checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") srpc.SetDefaultLogger(logger) diff --git a/cmd/fs2objectcache/main.go b/cmd/fs2objectcache/main.go index 45e936c2e..d5db87a41 100644 --- a/cmd/fs2objectcache/main.go +++ b/cmd/fs2objectcache/main.go @@ -7,7 +7,6 @@ import ( "path" "github.com/Cloud-Foundations/Dominator/lib/flags/loadflags" - "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -32,13 +31,11 @@ func init() { } func main() { - checkVersion := version.AddFlags("fs2objectcache") if err := loadflags.LoadForCli("fs2objectcache"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() - checkVersion() if *rootDir == "" { fmt.Fprintln(os.Stderr, "rootDir unspecified") os.Exit(1) diff --git a/cmd/fsbench/main.go b/cmd/fsbench/main.go index 8cdd80c32..5111f5f5f 100644 --- a/cmd/fsbench/main.go +++ b/cmd/fsbench/main.go @@ -1,22 +1,17 @@ package main import ( - "flag" "fmt" "os" "github.com/Cloud-Foundations/Dominator/lib/fsbench" - "github.com/Cloud-Foundations/Dominator/lib/version" ) // Benchmark the read speed of the underlying block device for a given file. func main() { - checkVersion := version.AddFlags("fsbench") - flag.Parse() - checkVersion() pathname := "/" - if flag.NArg() == 1 { - pathname = flag.Arg(0) + if len(os.Args) == 2 { + pathname = os.Args[1] } bytesPerSecond, blocksPerSecond, err := fsbench.GetReadSpeed(pathname) if err != nil { diff --git a/cmd/fsreadslow/main.go b/cmd/fsreadslow/main.go index bde4036ec..fb4900766 100644 --- a/cmd/fsreadslow/main.go +++ b/cmd/fsreadslow/main.go @@ -2,7 +2,6 @@ package main import ( "bufio" - "flag" "fmt" "io" "os" @@ -11,17 +10,13 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/format" "github.com/Cloud-Foundations/Dominator/lib/fsbench" "github.com/Cloud-Foundations/Dominator/lib/fsrateio" - "github.com/Cloud-Foundations/Dominator/lib/version" ) // Benchmark the read speed of the underlying block device for a given file. func main() { - checkVersion := version.AddFlags("fsreadslow") - flag.Parse() - checkVersion() pathname := "/" - if flag.NArg() == 1 { - pathname = flag.Arg(0) + if len(os.Args) == 2 { + pathname = os.Args[1] } bytesPerSecond, blocksPerSecond, err := fsbench.GetReadSpeed(pathname) if err != nil { diff --git a/cmd/hyper-control/main.go b/cmd/hyper-control/main.go index 6e6d2a8b8..d06f46fa0 100644 --- a/cmd/hyper-control/main.go +++ b/cmd/hyper-control/main.go @@ -17,7 +17,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" "github.com/Cloud-Foundations/Dominator/lib/tags" - "github.com/Cloud-Foundations/Dominator/lib/version" proto "github.com/Cloud-Foundations/Dominator/proto/hypervisor" ) @@ -183,14 +182,12 @@ func loadCerts() error { } func doMain() int { - checkVersion := version.AddFlags("hyper-control") if err := loadflags.LoadForCli("hyper-control"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() - checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/hypervisor/main.go b/cmd/hypervisor/main.go index 4698d78b3..d2757c86b 100644 --- a/cmd/hypervisor/main.go +++ b/cmd/hypervisor/main.go @@ -25,7 +25,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/net" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" - "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -110,14 +109,12 @@ func processCommand(args []string) { } func main() { - checkVersion := version.AddFlags("hypervisor") if err := loadflags.LoadForDaemon("hypervisor"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Usage = printUsage flag.Parse() - checkVersion() processCommand(flag.Args()) } diff --git a/cmd/image-unpacker/main.go b/cmd/image-unpacker/main.go index f8d13f3da..30996770a 100644 --- a/cmd/image-unpacker/main.go +++ b/cmd/image-unpacker/main.go @@ -1,4 +1,3 @@ -//go:build linux // +build linux package main @@ -17,7 +16,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/serverlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" - "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -39,13 +37,11 @@ var ( ) func main() { - checkVersion := version.AddFlags("image-unpacker") if err := loadflags.LoadForDaemon("image-unpacker"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() - checkVersion() tricorder.RegisterFlags() if os.Geteuid() != 0 { fmt.Fprintln(os.Stderr, "Must run the Image Unpacker as root") diff --git a/cmd/imageserver/main.go b/cmd/imageserver/main.go index e606ed85c..4912780d3 100644 --- a/cmd/imageserver/main.go +++ b/cmd/imageserver/main.go @@ -15,7 +15,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/objectserver/filesystem" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" - "github.com/Cloud-Foundations/Dominator/lib/version" objectserverRpcd "github.com/Cloud-Foundations/Dominator/objectserver/rpcd" "github.com/Cloud-Foundations/tricorder/go/healthserver" "github.com/Cloud-Foundations/tricorder/go/tricorder" @@ -58,7 +57,6 @@ var ( ) func main() { - checkVersion := version.AddFlags("imageserver") if os.Geteuid() == 0 { fmt.Fprintln(os.Stderr, "Do not run the Image Server as root") os.Exit(1) @@ -68,7 +66,6 @@ func main() { os.Exit(1) } flag.Parse() - checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") srpc.SetDefaultLogger(logger) diff --git a/cmd/imagetool/main.go b/cmd/imagetool/main.go index d72998d2a..71116ff7b 100644 --- a/cmd/imagetool/main.go +++ b/cmd/imagetool/main.go @@ -23,7 +23,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" "github.com/Cloud-Foundations/Dominator/lib/tags" - "github.com/Cloud-Foundations/Dominator/lib/version" ) type objectsFlushGetter interface { @@ -324,14 +323,12 @@ func makeListSelector(arg string) filesystem.ListSelector { var listFilter *filter.Filter func doMain() int { - checkVersion := version.AddFlags("imagetool") if err := loadflags.LoadForCli("imagetool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() - checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/imaginator/main.go b/cmd/imaginator/main.go index ff97f5b97..02c43e392 100644 --- a/cmd/imaginator/main.go +++ b/cmd/imaginator/main.go @@ -19,7 +19,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/serverlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" - "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -70,13 +69,11 @@ func init() { } func main() { - checkVersion := version.AddFlags("imaginator") if err := loadflags.LoadForDaemon("imaginator"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() - checkVersion() tricorder.RegisterFlags() if os.Geteuid() != 0 { fmt.Fprintln(os.Stderr, "Must run the Image Builder as root") diff --git a/cmd/installer/main.go b/cmd/installer/main.go index 360edaf5d..345211e24 100644 --- a/cmd/installer/main.go +++ b/cmd/installer/main.go @@ -27,7 +27,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/logbuf" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" - "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -339,14 +338,12 @@ func processCommand(args []string) { } func main() { - checkVersion := version.AddFlags("installer") if err := loadflags.LoadForDaemon("installer"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Usage = printUsage flag.Parse() - checkVersion() processCommand(flag.Args()) } diff --git a/cmd/installer/make-tarball b/cmd/installer/make-tarball index 9375ff0c8..10bbb6c3d 100755 --- a/cmd/installer/make-tarball +++ b/cmd/installer/make-tarball @@ -8,7 +8,7 @@ shift readonly bin="$GOPATH/bin/$command" readonly target="/tmp/$LOGNAME/$command.tar.gz" -# Source version library for LDFLAGS +# Source version info for LDFLAGS . ./scripts/version.lib CGO_ENABLED=0 go install -ldflags "$LDFLAGS" ./cmd/$command diff --git a/cmd/logtool/main.go b/cmd/logtool/main.go index 47137b813..f67cd2944 100644 --- a/cmd/logtool/main.go +++ b/cmd/logtool/main.go @@ -11,7 +11,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/cmdlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" - "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -70,14 +69,12 @@ func dialAll(addrs []string) ([]*srpc.Client, error) { } func doMain() int { - checkVersion := version.AddFlags("logtool") if err := loadflags.LoadForCli("logtool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() - checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/mdb-relayd/main.go b/cmd/mdb-relayd/main.go index 7cae36f6d..b15546fd9 100644 --- a/cmd/mdb-relayd/main.go +++ b/cmd/mdb-relayd/main.go @@ -11,7 +11,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/mdb" "github.com/Cloud-Foundations/Dominator/lib/mdb/mdbd" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" - "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -36,14 +35,12 @@ func showMdb(mdb *mdb.Mdb) { } func main() { - checkVersion := version.AddFlags("mdb-relayd") if err := loadflags.LoadForDaemon("mdb-relayd"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Usage = printUsage flag.Parse() - checkVersion() if flag.NArg() != 0 { printUsage() os.Exit(2) diff --git a/cmd/mdbd/main.go b/cmd/mdbd/main.go index 72fb4c73a..3e2ad981b 100644 --- a/cmd/mdbd/main.go +++ b/cmd/mdbd/main.go @@ -18,7 +18,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/mdb" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" - "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -217,7 +216,6 @@ func showErrorAndDie(err error) { } func main() { - checkVersion := version.AddFlags("mdbd") if os.Geteuid() == 0 { fmt.Fprintln(os.Stderr, "Do not run the MDB daemon as root") os.Exit(1) @@ -228,7 +226,6 @@ func main() { } flag.Usage = printUsage flag.Parse() - checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") if *debug { // Backwards compatibility. diff --git a/cmd/objecttool/main.go b/cmd/objecttool/main.go index 855565236..be2ba9a9f 100644 --- a/cmd/objecttool/main.go +++ b/cmd/objecttool/main.go @@ -14,7 +14,6 @@ import ( objectclient "github.com/Cloud-Foundations/Dominator/lib/objectserver/client" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" - "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -57,14 +56,12 @@ func getObjectServer() objectserver.ObjectServer { } func doMain() int { - checkVersion := version.AddFlags("objecttool") if err := loadflags.LoadForCli("objecttool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() - checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/scan/main.go b/cmd/scan/main.go index 7e31ab33f..588391d15 100644 --- a/cmd/scan/main.go +++ b/cmd/scan/main.go @@ -19,7 +19,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/fsrateio" "github.com/Cloud-Foundations/Dominator/lib/json" "github.com/Cloud-Foundations/Dominator/lib/memstats" - "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/Dominator/sub/scanner" ) @@ -42,13 +41,11 @@ var ( ) func main() { - checkVersion := version.AddFlags("scan") if err := loadflags.LoadForCli("scan"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() - checkVersion() var err error var configuration scanner.Configuration configuration.ScanFilter, err = filter.New(nil) diff --git a/cmd/show-cert/main.go b/cmd/show-cert/main.go index a4a2bb7a7..60efdc0f1 100644 --- a/cmd/show-cert/main.go +++ b/cmd/show-cert/main.go @@ -22,7 +22,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/cmdlogger" "github.com/Cloud-Foundations/Dominator/lib/sshutil" "github.com/Cloud-Foundations/Dominator/lib/stringutil" - "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/Dominator/lib/x509util" ) @@ -298,14 +297,12 @@ func showX509Cert(data []byte, logger log.DebugLogger) { } func doMain() int { - checkVersion := version.AddFlags("show-cert") err := loadflags.LoadForCli("show-cert") if err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Parse() - checkVersion() logger := cmdlogger.New() if err := loadX509CAs(*caFile, x509CaPoolMap); err != nil { fmt.Fprintln(os.Stderr, err) diff --git a/cmd/srpc-test/main.go b/cmd/srpc-test/main.go index 72c7a684b..20109ec79 100644 --- a/cmd/srpc-test/main.go +++ b/cmd/srpc-test/main.go @@ -12,7 +12,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/serverlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" - "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/Dominator/proto/test" "github.com/Cloud-Foundations/tricorder/go/tricorder" ) @@ -43,13 +42,11 @@ func doMain(logger log.DebugLogger) error { } func main() { - checkVersion := version.AddFlags("srpc-test") if err := loadflags.LoadForDaemon("srpc-test"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() - checkVersion() tricorder.RegisterFlags() logger := serverlogger.New("") srpc.SetDefaultLogger(logger) diff --git a/cmd/subd/main.go b/cmd/subd/main.go index 07f4ce632..576b1bd87 100644 --- a/cmd/subd/main.go +++ b/cmd/subd/main.go @@ -28,7 +28,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/rateio" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupserver" - "github.com/Cloud-Foundations/Dominator/lib/version" "github.com/Cloud-Foundations/Dominator/lib/wsyscall" "github.com/Cloud-Foundations/Dominator/proto/sub" "github.com/Cloud-Foundations/Dominator/sub/httpd" @@ -244,13 +243,11 @@ func writePidfile() { func main() { // Ensure the startup thread is reserved for the main function. runtime.LockOSThread() - checkVersion := version.AddFlags("subd") if err := loadflags.LoadForDaemon("subd"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } flag.Parse() - checkVersion() if *testExternallyPatchable { runTestAndExit(checkExternallyPatchable) } diff --git a/cmd/subtool/main.go b/cmd/subtool/main.go index 1d1042312..7c1eefdb6 100644 --- a/cmd/subtool/main.go +++ b/cmd/subtool/main.go @@ -15,7 +15,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/debuglogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" - "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -150,14 +149,12 @@ var subcommands = []commands.Command{ } func doMain() int { - checkVersion := version.AddFlags("subtool") if err := loadflags.LoadForCli("subtool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() - checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/unpacker-tool/main.go b/cmd/unpacker-tool/main.go index fe74269bb..94901655b 100644 --- a/cmd/unpacker-tool/main.go +++ b/cmd/unpacker-tool/main.go @@ -11,7 +11,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/log/cmdlogger" "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" - "github.com/Cloud-Foundations/Dominator/lib/version" ) var ( @@ -59,14 +58,12 @@ func getClient() *srpc.Client { } func doMain() int { - checkVersion := version.AddFlags("unpacker-tool") if err := loadflags.LoadForCli("unpacker-tool"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() - checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/cmd/vm-control/main.go b/cmd/vm-control/main.go index 12b684cf0..595fd80c1 100644 --- a/cmd/vm-control/main.go +++ b/cmd/vm-control/main.go @@ -17,7 +17,6 @@ import ( "github.com/Cloud-Foundations/Dominator/lib/srpc" "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" "github.com/Cloud-Foundations/Dominator/lib/tags" - "github.com/Cloud-Foundations/Dominator/lib/version" hyper_proto "github.com/Cloud-Foundations/Dominator/proto/hypervisor" ) @@ -295,14 +294,12 @@ var subcommands = []commands.Command{ } func doMain() int { - checkVersion := version.AddFlags("vm-control") if err := loadflags.LoadForCli("vm-control"); err != nil { fmt.Fprintln(os.Stderr, err) return 1 } flag.Usage = printUsage flag.Parse() - checkVersion() if flag.NArg() < 1 { printUsage() return 2 diff --git a/lib/flags/loadflags/api.go b/lib/flags/loadflags/api.go index ce21c6698..c2dc6bf60 100644 --- a/lib/flags/loadflags/api.go +++ b/lib/flags/loadflags/api.go @@ -5,9 +5,11 @@ import ( ) func LoadForCli(progName string) error { + registerVersionFlag(progName) return loadForCli(progName) } func LoadForDaemon(progName string) error { + registerVersionFlag(progName) return loadFlags(filepath.Join("/etc", progName)) } diff --git a/lib/flags/loadflags/impl.go b/lib/flags/loadflags/impl.go index 6b257e186..71cbe1de4 100644 --- a/lib/flags/loadflags/impl.go +++ b/lib/flags/loadflags/impl.go @@ -8,10 +8,20 @@ import ( "os" "path/filepath" "strings" + + "github.com/Cloud-Foundations/Dominator/lib/version" ) const systemDir = "/etc/config" +func registerVersionFlag(name string) { + flag.BoolFunc("version", "Print version information and exit", func(string) error { + fmt.Println(version.Get().Full(name)) + os.Exit(0) + return nil + }) +} + func loadFlags(dirname string) error { err := loadFlagsFromFile(filepath.Join(dirname, "flags.default")) if err != nil { diff --git a/scripts/make-tarball b/scripts/make-tarball index bf0d59022..1d4b2c05c 100755 --- a/scripts/make-tarball +++ b/scripts/make-tarball @@ -8,7 +8,7 @@ shift readonly bin="$GOPATH/bin/$command" readonly target="/tmp/$LOGNAME/$command.tar.gz" -# Source version library for LDFLAGS +# Source version info for LDFLAGS . ./scripts/version.lib CGO_ENABLED=0 go install -ldflags "$LDFLAGS" ./cmd/$command From 28a3a2c61aebf266a443706c390a89428eb98aa7 Mon Sep 17 00:00:00 2001 From: Vikramarjuna Malapati Date: Wed, 18 Feb 2026 14:52:17 +0000 Subject: [PATCH 3/4] added versioning support for the binaries --- lib/version/version.go | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/lib/version/version.go b/lib/version/version.go index e3762fb59..9cb657e04 100644 --- a/lib/version/version.go +++ b/lib/version/version.go @@ -5,9 +5,7 @@ package version import ( - "flag" "fmt" - "os" "runtime" "runtime/debug" "strings" @@ -145,38 +143,3 @@ func getVCSInfo() vcsInfo { return info } - -// Flag variables for version command-line handling -var ( - showVersion *bool - showShort *bool -) - -// AddFlags registers -version and -short flags. Call this before flag.Parse(). -// Returns a function that should be called after flag.Parse() to handle -// the version flags (prints version and exits if -version was passed). -// -// Usage: -// -// func main() { -// checkVersion := version.AddFlags("myapp") -// // ... other flag setup ... -// flag.Parse() -// checkVersion() -// // ... rest of main ... -// } -func AddFlags(binaryName string) func() { - showVersion = flag.Bool("version", false, "Print version information and exit") - showShort = flag.Bool("short", false, "Print short version (use with -version)") - - return func() { - if *showVersion { - if *showShort { - fmt.Println(Get().Short()) - } else { - fmt.Println(Get().Full(binaryName)) - } - os.Exit(0) - } - } -} From b98ecd256d4b47ece662068864e298b3bec03f2e Mon Sep 17 00:00:00 2001 From: Vikramarjuna Malapati Date: Wed, 18 Feb 2026 15:44:39 +0000 Subject: [PATCH 4/4] added versioning support for the binaries --- Makefile | 19 ++++---- cmd/installer/make-tarball | 5 +- lib/flags/loadflags/impl.go | 6 ++- lib/version/VERSION | 1 + lib/version/version.go | 92 +++++-------------------------------- scripts/make-tarball | 5 +- scripts/version.lib | 41 ----------------- 7 files changed, 28 insertions(+), 141 deletions(-) create mode 100644 lib/version/VERSION delete mode 100644 scripts/version.lib diff --git a/Makefile b/Makefile index 522242fd0..3d3ab6b1e 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,28 @@ -# Get version LDFLAGS from scripts/version.lib -LDFLAGS := $(shell . ./scripts/version.lib && echo "$$LDFLAGS") - all: - CGO_ENABLED=0 go install -ldflags '$(LDFLAGS)' ./cmd/* + CGO_ENABLED=0 go install ./cmd/* @cd c; make go vet -composites=false ./cmd/* build-darwin: - CGO_ENABLED=0 GOOS=darwin go build -ldflags '$(LDFLAGS)' ./cmd/* + (CGO_ENABLED=0 GOOS=darwin go build ./cmd/*) build-linux: - CGO_ENABLED=0 GOOS=linux go build -ldflags '$(LDFLAGS)' ./cmd/* + (CGO_ENABLED=0 GOOS=linux go build ./cmd/*) build-windows: - CGO_ENABLED=0 GOOS=windows go build -ldflags '$(LDFLAGS)' ./cmd/* + (CGO_ENABLED=0 GOOS=windows go build ./cmd/*) install-darwin: - CGO_ENABLED=0 GOOS=darwin go install -ldflags '$(LDFLAGS)' ./cmd/* + (CGO_ENABLED=0 GOOS=darwin go install ./cmd/*) install-linux: - CGO_ENABLED=0 GOOS=linux go install -ldflags '$(LDFLAGS)' ./cmd/* + (CGO_ENABLED=0 GOOS=linux go install ./cmd/*) install-linux-arm: - CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go install -ldflags '$(LDFLAGS)' ./cmd/* + (CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go install ./cmd/*) install-windows: - CGO_ENABLED=0 GOOS=windows go install -ldflags '$(LDFLAGS)' ./cmd/* + (CGO_ENABLED=0 GOOS=windows go install ./cmd/*) disruption-manager.tarball: @./scripts/make-tarball disruption-manager -C $(ETCDIR) ssl diff --git a/cmd/installer/make-tarball b/cmd/installer/make-tarball index 10bbb6c3d..03e89c38b 100755 --- a/cmd/installer/make-tarball +++ b/cmd/installer/make-tarball @@ -8,10 +8,7 @@ shift readonly bin="$GOPATH/bin/$command" readonly target="/tmp/$LOGNAME/$command.tar.gz" -# Source version info for LDFLAGS -. ./scripts/version.lib - -CGO_ENABLED=0 go install -ldflags "$LDFLAGS" ./cmd/$command +CGO_ENABLED=0 go install ./cmd/$command strip -o "$bin~" "$bin" if cmp -s "$bin~" "$bin"; then diff --git a/lib/flags/loadflags/impl.go b/lib/flags/loadflags/impl.go index 71cbe1de4..e70c8e19e 100644 --- a/lib/flags/loadflags/impl.go +++ b/lib/flags/loadflags/impl.go @@ -16,7 +16,11 @@ const systemDir = "/etc/config" func registerVersionFlag(name string) { flag.BoolFunc("version", "Print version information and exit", func(string) error { - fmt.Println(version.Get().Full(name)) + info := version.Get() + fmt.Printf("%s %s\n", name, info.Version) + fmt.Printf(" Commit: %s\n", info.GitCommit) + fmt.Printf(" Built: %s\n", info.BuildDate) + fmt.Printf(" Go: %s\n", info.GoVersion) os.Exit(0) return nil }) diff --git a/lib/version/VERSION b/lib/version/VERSION new file mode 100644 index 000000000..3061e9e5a --- /dev/null +++ b/lib/version/VERSION @@ -0,0 +1 @@ +v0.12.0 \ No newline at end of file diff --git a/lib/version/version.go b/lib/version/version.go index 9cb657e04..c2e088569 100644 --- a/lib/version/version.go +++ b/lib/version/version.go @@ -1,120 +1,52 @@ -// Package version provides build version information for all binaries. -// -// Version information is set via ldflags at build time (from git tags). -// Falls back to debug.ReadBuildInfo for dev builds. package version import ( + _ "embed" "fmt" "runtime" "runtime/debug" "strings" ) -// Set via ldflags at build time: -// -// go build -ldflags "-X github.com/Cloud-Foundations/Dominator/lib/version.Version=v1.2.3" -var ( - Version = "" - GitCommit = "" - GitBranch = "" - BuildDate = "" -) +//go:embed VERSION +var baseVersion string -// Info contains version information type Info struct { Version string `json:"version"` GitCommit string `json:"gitCommit"` - GitBranch string `json:"gitBranch"` BuildDate string `json:"buildDate"` GoVersion string `json:"goVersion"` Dirty bool `json:"dirty"` } -// Get returns version information, with fallbacks for dev builds func Get() Info { - // Get VCS info once for commit, dirty, and build time vcs := getVCSInfo() - - commit := GitCommit - dirty := false - if commit == "" { - commit = vcs.revision - dirty = vcs.dirty - } else { - dirty = strings.HasSuffix(commit, "-dirty") || - strings.HasSuffix(Version, "-dirty") - } - - branch := GitBranch - if branch == "" { - branch = "unknown" - } - - buildDate := BuildDate - if buildDate == "" { - buildDate = vcs.buildTime - } - - // Build version string - version := Version - if version == "" { - // No ldflags provided - build dev version from VCS info - version = "dev" - if vcs.revision != "unknown" { - version += "+" + vcs.revision - } - if vcs.dirty { - version += "-dirty" - } + version := strings.TrimSpace(baseVersion) + if vcs.revision != "unknown" { + version += "+" + vcs.revision } - - // Build commit display string (without -dirty suffix, that's in version) - commitDisplay := commit - if idx := strings.Index(commitDisplay, "-dirty"); idx != -1 { - commitDisplay = commitDisplay[:idx] + if vcs.dirty { + version += "-dirty" } - return Info{ Version: version, - GitCommit: commitDisplay, - GitBranch: branch, - BuildDate: buildDate, + GitCommit: vcs.revision, + BuildDate: vcs.buildTime, GoVersion: runtime.Version(), - Dirty: dirty, + Dirty: vcs.dirty, } } -// String returns a single-line version string func (i Info) String() string { - return fmt.Sprintf("%s (commit: %s, branch: %s, built: %s)", - i.Version, i.GitCommit, i.GitBranch, i.BuildDate) -} - -// Short returns just the version number -func (i Info) Short() string { - return i.Version -} - -// Full returns multi-line detailed version info -func (i Info) Full(binaryName string) string { - return fmt.Sprintf(`%s %s - Commit: %s - Branch: %s - Built: %s - Go: %s`, - binaryName, i.Version, i.GitCommit, - i.GitBranch, i.BuildDate, i.GoVersion) + return fmt.Sprintf("%s (built: %s)", i.Version, i.BuildDate) } -// vcsInfo holds version control information from Go build info type vcsInfo struct { revision string buildTime string dirty bool } -// getVCSInfo extracts all VCS info from Go build info in a single pass func getVCSInfo() vcsInfo { info := vcsInfo{ revision: "unknown", diff --git a/scripts/make-tarball b/scripts/make-tarball index 1d4b2c05c..ddfd96f9f 100755 --- a/scripts/make-tarball +++ b/scripts/make-tarball @@ -8,10 +8,7 @@ shift readonly bin="$GOPATH/bin/$command" readonly target="/tmp/$LOGNAME/$command.tar.gz" -# Source version info for LDFLAGS -. ./scripts/version.lib - -CGO_ENABLED=0 go install -ldflags "$LDFLAGS" ./cmd/$command +CGO_ENABLED=0 go install ./cmd/$command strip -o "$bin~" "$bin" if cmp -s "$bin~" "$bin"; then diff --git a/scripts/version.lib b/scripts/version.lib deleted file mode 100644 index 02d76806f..000000000 --- a/scripts/version.lib +++ /dev/null @@ -1,41 +0,0 @@ -# Version calculation library -# Source this file to get VERSION and LDFLAGS variables -# -# Usage: -# . ./scripts/version.lib -# go build -ldflags "$LDFLAGS" ./cmd/... - -# Get version info from git -GO_MODULE=$(head -1 go.mod | awk '{print $2}') -VERSION_PKG="${GO_MODULE}/lib/version" -GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") -GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown") -BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) - -# Calculate version from git tags -GIT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") -COMMITS_SINCE=$(git rev-list "${GIT_TAG}..HEAD" --count 2>/dev/null || echo "0") - -if [ "$COMMITS_SINCE" = "0" ]; then - # On a tag - check for dirty - if git diff --quiet 2>/dev/null; then - VERSION="$GIT_TAG" - else - VERSION="${GIT_TAG}-dirty" - fi -else - # After a tag - add prerelease info - if [ "$GIT_BRANCH" = "main" ] || [ "$GIT_BRANCH" = "master" ]; then - PRERELEASE="dev" - else - # Sanitize branch name for semver - PRERELEASE=$(echo "$GIT_BRANCH" | sed 's/[^a-zA-Z0-9]/-/g' | cut -c1-20) - fi - VERSION="${GIT_TAG}-${PRERELEASE}.${COMMITS_SINCE}+${GIT_COMMIT}" - if ! git diff --quiet 2>/dev/null; then - VERSION="${VERSION}-dirty" - fi -fi - -LDFLAGS="-X ${VERSION_PKG}.Version=${VERSION} -X ${VERSION_PKG}.GitCommit=${GIT_COMMIT} -X ${VERSION_PKG}.GitBranch=${GIT_BRANCH} -X ${VERSION_PKG}.BuildDate=${BUILD_DATE}" -