From df993d8b0db23ae21320b9fb48d8438b3de1c3d9 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 5 Apr 2017 19:52:31 +0100 Subject: [PATCH 1/5] build: Fix copy&paste error for Infrakit dependencies Signed-off-by: Rolf Neugebauer --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 258db5f0e..d41ca7112 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ bin/moby: $(MOBY_DEPS) | bin tar cf - vendor src/initrd src/pad4 -C src/cmd/moby . | docker run --rm --net=none --log-driver=none -i $(CROSS) $(GO_COMPILE) --package github.com/docker/moby -o $@ | tar xf - touch $@ -MOBY_DEPS=$(wildcard src/cmd/infrakit-instance-hyperkit/*.go) +INFRAKIT_DEPS=$(wildcard src/cmd/infrakit-instance-hyperkit/*.go) bin/infrakit-instance-hyperkit: $(INFRAKIT_DEPS) | bin tar cf - vendor -C src/cmd/infrakit-instance-hyperkit . | docker run --rm --net=none --log-driver=none -i $(CROSS) $(GO_COMPILE) --package github.com/docker/moby -o $@ | tar xf - touch $@ From fa7c85e235c953ba25d8b1cde06005116c255b1d Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 5 Apr 2017 19:59:12 +0100 Subject: [PATCH 2/5] build: Improve dependency for CLI/infrakit build Use vendor.conf as a proxy for ./vendor contents Signed-off-by: Rolf Neugebauer --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d41ca7112..8df6a3278 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,6 @@ all: default GO_COMPILE=mobylinux/go-compile:3afebc59c5cde31024493c3f91e6102d584a30b9@sha256:e0786141ea7df8ba5735b63f2a24b4ade9eae5a02b0e04c4fca33b425ec69b0a -MOBY_DEPS=$(wildcard src/cmd/moby/*.go) GOOS=$(shell uname -s | tr '[:upper:]' '[:lower:]') GOARCH=amd64 ifneq ($(GOOS),linux) @@ -14,11 +13,13 @@ ifeq ($(GOOS),darwin) default: bin/infrakit-instance-hyperkit endif +MOBY_DEPS=$(wildcard src/cmd/moby/*.go) Makefile vendor.conf +MOBY_DEPS+=$(wildcard src/initrd/*.go) $(wildcard src/pad4/*.go) bin/moby: $(MOBY_DEPS) | bin tar cf - vendor src/initrd src/pad4 -C src/cmd/moby . | docker run --rm --net=none --log-driver=none -i $(CROSS) $(GO_COMPILE) --package github.com/docker/moby -o $@ | tar xf - touch $@ -INFRAKIT_DEPS=$(wildcard src/cmd/infrakit-instance-hyperkit/*.go) +INFRAKIT_DEPS=$(wildcard src/cmd/infrakit-instance-hyperkit/*.go) Makefile vendor.conf bin/infrakit-instance-hyperkit: $(INFRAKIT_DEPS) | bin tar cf - vendor -C src/cmd/infrakit-instance-hyperkit . | docker run --rm --net=none --log-driver=none -i $(CROSS) $(GO_COMPILE) --package github.com/docker/moby -o $@ | tar xf - touch $@ From d33892e9f890c3e8bae4224221dca70b227673fc Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 5 Apr 2017 20:46:25 +0100 Subject: [PATCH 3/5] cli: Fix "build" when the basename contains a "." Something like "moby-4.10.yml" did not work when invoked like "moby build moby-4.10". While at it, also allow .yaml as an extension. Signed-off-by: Rolf Neugebauer --- src/cmd/moby/build.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/moby/build.go b/src/cmd/moby/build.go index c029f5716..1c6efad6d 100644 --- a/src/cmd/moby/build.go +++ b/src/cmd/moby/build.go @@ -35,7 +35,7 @@ func build(args []string) { os.Exit(1) } conf := remArgs[0] - if filepath.Ext(conf) == "" { + if !(filepath.Ext(conf) == ".yml" || filepath.Ext(conf) == ".yaml") { conf = conf + ".yml" } From f76f2b66549a7ecc8a5197348fbcaf632f75eb67 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 5 Apr 2017 23:05:05 +0100 Subject: [PATCH 4/5] tools: Add --ldflags to go-compile This flags allows passing additional ldflags to the build. It is primarily there to pass -C arguments to specify values of variables at compile time. Signed-off-by: Rolf Neugebauer --- tools/go-compile/compile.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/go-compile/compile.sh b/tools/go-compile/compile.sh index e49fb5b7e..e5f6806ca 100755 --- a/tools/go-compile/compile.sh +++ b/tools/go-compile/compile.sh @@ -26,6 +26,10 @@ do package="$2" shift ;; + --ldflags) + ldflags="$2" + shift + ;; *) echo "Unknown option $1" exit 1 @@ -61,9 +65,14 @@ test -z $(find . -type f -name "*.go" -not -path "*/vendor/*" -not -name "*.pb.* if [ "$GOOS" = "darwin" ] then - go build -o $out "$package" + if [ -z "$ldflags" ] + then + go build -o $out "$package" + else + go build -o $out -ldflags "${ldflags}" "$package" + fi else - go build -o $out -buildmode pie --ldflags '-s -w -extldflags "-static"' "$package" + go build -o $out -buildmode pie -ldflags "-s -w ${ldflags} -extldflags \"-static\"" "$package" fi tar cf - $out From 3e53aab4ce6e8162310509e1ba84e885e999e9dd Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 5 Apr 2017 23:53:35 +0100 Subject: [PATCH 5/5] cli: Add a 'version' version Pass version and git commit hash from the Makefile into main.go. Add a 'version' subcommand to print the information. While at it also tweak the help output to only print the command name and not the entire path. Signed-off-by: Rolf Neugebauer --- Makefile | 7 +++++-- src/cmd/moby/main.go | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 8df6a3278..c06af4476 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,10 @@ default: bin/moby moby-initrd.img all: default -GO_COMPILE=mobylinux/go-compile:3afebc59c5cde31024493c3f91e6102d584a30b9@sha256:e0786141ea7df8ba5735b63f2a24b4ade9eae5a02b0e04c4fca33b425ec69b0a +VERSION="0.0" # dummy for now +GIT_COMMIT=$(shell git rev-list -1 HEAD) + +GO_COMPILE=mobylinux/go-compile:a2ff853b00d687f845d0f67189fa645a567c006e@sha256:09fff8a5c022fc9ead35b2779209c043196b09193c6e61d98603d402c0971f03 GOOS=$(shell uname -s | tr '[:upper:]' '[:lower:]') GOARCH=amd64 @@ -16,7 +19,7 @@ endif MOBY_DEPS=$(wildcard src/cmd/moby/*.go) Makefile vendor.conf MOBY_DEPS+=$(wildcard src/initrd/*.go) $(wildcard src/pad4/*.go) bin/moby: $(MOBY_DEPS) | bin - tar cf - vendor src/initrd src/pad4 -C src/cmd/moby . | docker run --rm --net=none --log-driver=none -i $(CROSS) $(GO_COMPILE) --package github.com/docker/moby -o $@ | tar xf - + tar cf - vendor src/initrd src/pad4 -C src/cmd/moby . | docker run --rm --net=none --log-driver=none -i $(CROSS) $(GO_COMPILE) --package github.com/docker/moby --ldflags "-X main.GitCommit=$(GIT_COMMIT) -X main.Version=$(VERSION)" -o $@ | tar xf - touch $@ INFRAKIT_DEPS=$(wildcard src/cmd/infrakit-instance-hyperkit/*.go) Makefile vendor.conf diff --git a/src/cmd/moby/main.go b/src/cmd/moby/main.go index 8496624bc..6ccf996a4 100644 --- a/src/cmd/moby/main.go +++ b/src/cmd/moby/main.go @@ -4,12 +4,19 @@ import ( "flag" "fmt" "os" + "path/filepath" log "github.com/Sirupsen/logrus" ) var ( defaultLogFormatter = &log.TextFormatter{} + + // Version is the human-readable version + Version = "unknown" + + // GitCommit hash, set at compile time + GitCommit = "unknown" ) // infoFormatter overrides the default format for Info() log events to @@ -24,15 +31,22 @@ func (f *infoFormatter) Format(entry *log.Entry) ([]byte, error) { return defaultLogFormatter.Format(entry) } +func version() { + fmt.Printf("%s version %s\n", filepath.Base(os.Args[0]), Version) + fmt.Printf("commit: %s\n", GitCommit) + os.Exit(0) +} + func main() { flag.Usage = func() { - fmt.Printf("USAGE: %s [options] COMMAND\n\n", os.Args[0]) + fmt.Printf("USAGE: %s [options] COMMAND\n\n", filepath.Base(os.Args[0])) fmt.Printf("Commands:\n") fmt.Printf(" build Build a Moby image from a YAML file\n") fmt.Printf(" run Run a Moby image on a local hypervisor\n") + fmt.Printf(" version Print version information\n") fmt.Printf(" help Print this message\n") fmt.Printf("\n") - fmt.Printf("Run '%s COMMAND --help' for more information on the command\n", os.Args[0]) + fmt.Printf("Run '%s COMMAND --help' for more information on the command\n", filepath.Base(os.Args[0])) fmt.Printf("\n") fmt.Printf("Options:\n") flag.PrintDefaults() @@ -69,6 +83,8 @@ func main() { build(args[1:]) case "run": run(args[1:]) + case "version": + version() case "help": flag.Usage() default: