1
Fork 0

add version info to the binary

main
Motiejus Jakštys 2021-08-24 07:02:12 +03:00
parent be668f21e8
commit 6dd7678e64
3 changed files with 30 additions and 22 deletions

View File

@ -2,19 +2,24 @@ GODEPS = $(shell git ls-files '*.go' go.mod go.sum)
GOBIN = $(shell go env GOPATH)/bin/ GOBIN = $(shell go env GOPATH)/bin/
GOOSARCHS = $(sort \ GOOSARCHS = $(sort \
linux/amd64 \ darwin/amd64 \
linux/arm64 \ darwin/arm64 \
darwin/amd64 \ linux/amd64 \
darwin/arm64 \ linux/arm64 \
windows/amd64/.exe \ windows/amd64/.exe \
) windows/arm64/.exe)
VERSION = $(shell git describe --dirty) VSN = $(shell git describe --dirty)
LDFLAGS = -ldflags "-X main.Version=$(VERSION)" VSNHASH = $(shell git rev-parse --verify HEAD)
LDFLAGS = -ldflags "-X main.Version=$(VSN) -X main.VersionHash=$(VSNHASH)"
.PHONY: test
test:
go test -race -cover ./...
define undockertarget define undockertarget
UNDOCKERS += undocker-$(1)-$(2)-$(VERSION)-$(firstword $(3)) UNDOCKERS += undocker-$(1)-$(2)-$(VSN)$(firstword $(3))
undocker-$(1)-$(2)-$(VERSION)$(firstword $(3)): $(GODEPS) undocker-$(1)-$(2)-$(VSN)$(firstword $(3)): $(GODEPS)
CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build $(LDFLAGS) -o $$@ CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build $(LDFLAGS) -o $$@
endef endef
@ -22,11 +27,7 @@ $(foreach goosarch,$(GOOSARCHS),\
$(eval $(call undockertarget,$(word 1,$(subst /, ,$(goosarch))),$(word 2,$(subst /, ,$(goosarch))),$(word 3,$(subst /, ,$(goosarch)))))) $(eval $(call undockertarget,$(word 1,$(subst /, ,$(goosarch))),$(word 2,$(subst /, ,$(goosarch))),$(word 3,$(subst /, ,$(goosarch))))))
.PHONY: all .PHONY: all
all: $(UNDOCKERS) coverage.html all: $(UNDOCKERS)
.PHONY: test
test:
go test -race -cover ./...
.PHONY: lint .PHONY: lint
lint: vet staticcheck lint: vet staticcheck
@ -54,4 +55,4 @@ sha256sum.txt.asc: sha256sum.txt
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(UNDOCKERS) coverage.html sha256sum.txt sha256sum.txt.asc rm -f undocker-*-v* coverage.html sha256sum.txt sha256sum.txt.asc

View File

@ -80,11 +80,7 @@ Similar Projects
Changelog Changelog
--------- ---------
**1.0.1** **v1.0**
* bugfix: add missing error check when opening the tarball.
**1.0**
* initial release: `rootfs.Flatten` and a simple command-line application. * initial release: `rootfs.Flatten` and a simple command-line application.

13
main.go
View File

@ -11,6 +11,9 @@ import (
"git.sr.ht/~motiejus/undocker/rootfs" "git.sr.ht/~motiejus/undocker/rootfs"
) )
var Version = "unknown"
var VersionHash = "unknown"
const _usage = `Usage: const _usage = `Usage:
%s <infile> <outfile> %s <infile> <outfile>
@ -19,13 +22,21 @@ Flatten a Docker container image to a root file system.
Arguments: Arguments:
<infile>: Input Docker container. Tarball. <infile>: Input Docker container. Tarball.
<outfile>: Output tarball, the root file system. '-' is stdout. <outfile>: Output tarball, the root file system. '-' is stdout.
undocker %s (%s)
Built with %s
` `
func main() { func main() {
runtime.GOMAXPROCS(1) // no need to create that many threads runtime.GOMAXPROCS(1) // no need to create that many threads
if len(os.Args) != 3 { if len(os.Args) != 3 {
fmt.Fprintf(os.Stderr, _usage, filepath.Base(os.Args[0])) fmt.Fprintf(os.Stderr, _usage,
filepath.Base(os.Args[0]),
Version,
VersionHash,
runtime.Version(),
)
os.Exit(1) os.Exit(1)
} }