Merge pull request #2787 from ijc/linuxkit-pkg-more-labels

Include tool version info in package/image labels
This commit is contained in:
Ian Campbell 2017-12-01 15:30:31 +00:00 committed by GitHub
commit f0059f03f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 12 deletions

View File

@ -50,7 +50,7 @@ bin/linuxkit: tmp_linuxkit_bin.tar
touch $@ touch $@
tmp_linuxkit_bin.tar: $(LINUXKIT_DEPS) tmp_linuxkit_bin.tar: $(LINUXKIT_DEPS)
tar cf - -C src/cmd/linuxkit . | docker run --rm --net=none --log-driver=none -i $(CROSS) $(GO_COMPILE) --package github.com/linuxkit/linuxkit/src/cmd/linuxkit --ldflags "-X main.GitCommit=$(GIT_COMMIT) -X main.Version=$(VERSION)" -o bin/linuxkit > $@ tar cf - -C src/cmd/linuxkit . | docker run --rm --net=none --log-driver=none -i $(CROSS) $(GO_COMPILE) --package github.com/linuxkit/linuxkit/src/cmd/linuxkit --ldflags "-X github.com/linuxkit/linuxkit/src/cmd/linuxkit/version.GitCommit=$(GIT_COMMIT) -X github.com/linuxkit/linuxkit/src/cmd/linuxkit/version.Version=$(VERSION)" -o bin/linuxkit > $@
.PHONY: test-cross .PHONY: test-cross
test-cross: test-cross:
@ -67,7 +67,7 @@ LOCAL_BUILDMODE?=pie
endif endif
LOCAL_BUILDMODE?=default LOCAL_BUILDMODE?=default
LOCAL_LDFLAGS += -s -w -extldflags \"-static\" -X main.GitCommit=$(GIT_COMMIT) -X main.Version=$(VERSION) LOCAL_LDFLAGS += -s -w -extldflags \"-static\" -X github.com/linuxkit/linuxkit/src/cmd/linuxkit/version.GitCommit=$(GIT_COMMIT) -X github.com/linuxkit/linuxkit/src/cmd/linuxkit/version.Version=$(VERSION)
LOCAL_TARGET ?= bin/linuxkit LOCAL_TARGET ?= bin/linuxkit
.PHONY: local-check local-build local-test local .PHONY: local-check local-build local-test local

View File

@ -7,6 +7,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/version"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
@ -27,12 +29,6 @@ type PkgConfig struct {
var ( var (
defaultLogFormatter = &log.TextFormatter{} defaultLogFormatter = &log.TextFormatter{}
// Version is the human-readable version
Version = "unknown"
// GitCommit hash, set at compile time
GitCommit = "unknown"
// Config is the global tool configuration // Config is the global tool configuration
Config = GlobalConfig{} Config = GlobalConfig{}
) )
@ -49,9 +45,9 @@ func (f *infoFormatter) Format(entry *log.Entry) ([]byte, error) {
return defaultLogFormatter.Format(entry) return defaultLogFormatter.Format(entry)
} }
func version() { func printVersion() {
fmt.Printf("%s version %s\n", filepath.Base(os.Args[0]), Version) fmt.Printf("%s version %s\n", filepath.Base(os.Args[0]), version.Version)
fmt.Printf("commit: %s\n", GitCommit) fmt.Printf("commit: %s\n", version.GitCommit)
os.Exit(0) os.Exit(0)
} }
@ -129,7 +125,7 @@ func main() {
case "run": case "run":
run(args[1:]) run(args[1:])
case "version": case "version":
version() printVersion()
case "help": case "help":
flag.Usage() flag.Usage()
default: default:

View File

@ -5,6 +5,8 @@ import (
"fmt" "fmt"
"os" "os"
"runtime" "runtime"
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/version"
) )
type buildOpts struct { type buildOpts struct {
@ -132,6 +134,9 @@ func (p Pkg) Build(bos ...BuildOpt) error {
args = append(args, "--label=org.mobyproject.config="+string(b)) args = append(args, "--label=org.mobyproject.config="+string(b))
} }
args = append(args, "--label=org.mobyproject.linuxkit.version="+version.Version)
args = append(args, "--label=org.mobyproject.linuxkit.revision="+version.GitCommit)
if err := d.build(p.Tag()+suffix, p.pkgPath, args...); err != nil { if err := d.build(p.Tag()+suffix, p.pkgPath, args...); err != nil {
return err return err
} }

View File

@ -0,0 +1,9 @@
package version
var (
// Version is the human-readable version
Version = "unknown"
// GitCommit hash, set at compile time
GitCommit = "unknown"
)