Enhance build taget into Makefile, add --version support
This commit is contained in:
parent
32c218f8ce
commit
c6230ca794
4
.gitignore
vendored
4
.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
docker-multi-arch-builder
|
|
||||||
|
# Ignore compilation result
|
||||||
|
bin/
|
19
Makefile
19
Makefile
@ -1,5 +1,20 @@
|
|||||||
.PHONY: build
|
.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:
|
build: dependencies
|
||||||
go build
|
@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
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
. "antoine-roux.tk/docker-multi-arch-builder/internal/version"
|
||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -15,6 +16,7 @@ var (
|
|||||||
Short: "dmab is an oci multi architecture builder",
|
Short: "dmab is an oci multi architecture builder",
|
||||||
Long: `docker multi architecture builder is a go program use to build docker manifest
|
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`,
|
with list of layer. Each layer point to docker image with annotated os, arch and variant information`,
|
||||||
|
Version: Version,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
21
internal/version/dev.go
Normal file
21
internal/version/dev.go
Normal file
@ -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
|
||||||
|
}
|
27
internal/version/prod.go
Normal file
27
internal/version/prod.go
Normal file
@ -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()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user