diff --git a/.gitignore b/.gitignore index 748d6fd..af84076 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -docker-multi-arch-builder \ No newline at end of file + +# Ignore compilation result +bin/ \ No newline at end of file diff --git a/Makefile b/Makefile index 25100b9..1eb378d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,20 @@ .PHONY: build +GOARCH=amd64 +# GOARCH=arm +GOOS=darwin +# GOOS=linux +LDFLAGS=-w -s -X go/weather/internal/version.Version=$$(git rev-list -1 HEAD) +GO_BUILD_FLAGS=-tags dev +CGO_ENABLED=0 -build: - go build +build: dependencies + @echo "build for os $$GOOS and arch $$GOARCH" + go build -o bin/docker-multi-arch-builder-$(GOOS)-$(GOARCH) -ldflags="$(LDFLAGS)" $(GO_BUILD_FLAGS) main.go + +dependencies: + go mod download + go mod verify + +version: + ./bin/docker-multi-arch-builder-darwin-amd64 --version diff --git a/cmd/root.go b/cmd/root.go index c3f0f1c..a869d6b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,6 +1,7 @@ package cmd import ( + . "antoine-roux.tk/docker-multi-arch-builder/internal/version" "fmt" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -15,6 +16,7 @@ var ( Short: "dmab is an oci multi architecture builder", Long: `docker multi architecture builder is a go program use to build docker manifest with list of layer. Each layer point to docker image with annotated os, arch and variant information`, + Version: Version, } ) diff --git a/internal/version/dev.go b/internal/version/dev.go new file mode 100644 index 0000000..c923dc9 --- /dev/null +++ b/internal/version/dev.go @@ -0,0 +1,21 @@ +//go:build dev + +package version + +import ( + "fmt" +) + +//Version ... +var Version = "0.1.0" + +//Prerelease such as "dev" (in development), "beta", "rc1", etc. +var Prerelease = "dev" + +// String returns the complete version string, including prerelease +func String() string { + if Prerelease != "" { + return fmt.Sprintf("%s-%s", Version, Prerelease) + } + return Version +} diff --git a/internal/version/prod.go b/internal/version/prod.go new file mode 100644 index 0000000..3e70630 --- /dev/null +++ b/internal/version/prod.go @@ -0,0 +1,27 @@ +//go:build prod + +package version + +import ( + "fmt" + + version "github.com/hashicorp/go-version" +) + +//Version ... +var Version = "1.0.0" + +//Prerelease such as "dev" (in development), "beta", "rc1", etc. +var Prerelease = "prod" + +//SemVer management +var SemVer *version.Version + +func init() { + SemVer = version.Must(version.NewSemver(fmt.Sprintf("%s-%s", Version, Prerelease))) +} + +// String returns the complete version string, including prerelease +func String() string { + return SemVer.String() +}