From 3dac0063df23296094be745f90affa33ea454aec Mon Sep 17 00:00:00 2001 From: Eric Chiang Date: Thu, 13 Oct 2016 17:58:40 -0700 Subject: [PATCH] *: properly compile version into docker images --- Makefile | 15 +++++++++++---- cmd/dex/version.go | 2 +- scripts/git-version | 5 +++-- scripts/rkt-build | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 0205b6df..727e2d2e 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,10 @@ bin/dex: FORCE generated bin/example-app: FORCE @go install -v -ldflags $(LD_FLAGS) $(REPO_PATH)/cmd/example-app +.PHONY: release-binary +release-binary: + @go build -o _output/bin/dex -v -ldflags $(LD_FLAGS) $(REPO_PATH)/cmd/dex + .PHONY: generated generated: server/templates_default.go @@ -67,7 +71,7 @@ _output/images/library-alpine-3.4.aci: @docker2aci docker://alpine:3.4 @mv library-alpine-3.4.aci _output/images/library-alpine-3.4.aci -_output/images/dex.aci: _output/bin/dex _output/images/library-alpine-3.4.aci +_output/images/dex.aci: clean-release _output/bin/dex _output/images/library-alpine-3.4.aci # Using acbuild to build a application container image. @sudo ./scripts/build-aci ./_output/images/library-alpine-3.4.aci @sudo chown $(user):$(group) _output/images/dex.aci @@ -76,8 +80,8 @@ _output/images/dex.aci: _output/bin/dex _output/images/library-alpine-3.4.aci aci: _output/images/dex.aci .PHONY: docker-image -docker-image: _output/bin/dex - @docker build -t $(DOCKER_IMAGE) . +docker-image: clean-release _output/bin/dex + @sudo docker build -t $(DOCKER_IMAGE) . .PHONY: grpc grpc: api/api.pb.go @@ -91,8 +95,11 @@ bin/protoc: scripts/get-protoc bin/protoc-gen-go: @go install -v $(REPO_PATH)/vendor/github.com/golang/protobuf/protoc-gen-go -clean: +clean: clean-release @rm -rf bin/ + +.PHONY: clean-release +clean-release: @rm -rf _output/ testall: testrace vet fmt lint diff --git a/cmd/dex/version.go b/cmd/dex/version.go index d9f72bc4..1e92c4dc 100644 --- a/cmd/dex/version.go +++ b/cmd/dex/version.go @@ -13,7 +13,7 @@ func commandVersion() *cobra.Command { Use: "version", Short: "Print the version and exit", Run: func(cmd *cobra.Command, args []string) { - fmt.Printf(`dex Version:%s + fmt.Printf(`dex Version: %s Go Version: %s Go OS/ARCH: %s %s `, version.Version, runtime.Version(), runtime.GOOS, runtime.GOARCH) diff --git a/scripts/git-version b/scripts/git-version index f0710e57..936641cb 100755 --- a/scripts/git-version +++ b/scripts/git-version @@ -1,4 +1,5 @@ -#!/bin/bash -e +#!/bin/sh -e +# Since this script will be run in a rkt container, use "/bin/sh" instead of "/bin/bash" # parse the current git commit hash COMMIT=`git rev-parse HEAD` @@ -18,4 +19,4 @@ if [ -n "$(git diff --shortstat 2> /dev/null | tail -n1)" ]; then VERSION="${VERSION}-dirty" fi -echo $VERSION \ No newline at end of file +echo $VERSION diff --git a/scripts/rkt-build b/scripts/rkt-build index 55afb513..4371f4af 100755 --- a/scripts/rkt-build +++ b/scripts/rkt-build @@ -10,4 +10,4 @@ sudo rkt run \ --insecure-options=image \ docker://golang:1.7.1-alpine \ --exec=/bin/sh -- -x -c \ - 'apk add --no-cache --update alpine-sdk && go install -v github.com/coreos/dex/cmd/dex && cp /go/bin/dex /go/src/github.com/coreos/dex/_output/bin' + 'apk add --no-cache --update alpine-sdk && cd /go/src/github.com/coreos/dex && make release-binary'