Skip to content

Commit

Permalink
Add release build process
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronlevy committed Jun 1, 2016
1 parent f5744f7 commit 04848d1
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bin/
_output
vendor-v[0-9].[0-9].[0-9]/

hack/*/.vagrant/
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ go:
- 1.6
script:
- test -z "$(go generate pkg/asset/templates_gen.go && git diff | tee /dev/stderr)"
- make clean check all
- make clean release
24 changes: 16 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,33 @@ export GO15VENDOREXPERIMENT:=1
export CGO_ENABLED:=0
export GOARCH:=amd64

LOCAL_OS:=$(shell uname | tr A-Z a-z)
GOFILES:=$(shell find . -name '*.go' | grep -v -E '(./vendor|internal/templates.go)')
TEMPLATES:=$(shell find pkg/asset/templates -type f)
GOPATH_BIN:=$(shell echo ${GOPATH} | awk 'BEGIN { FS = ":" }; { print $1 }')/bin

all: bin/linux/bootkube bin/darwin/bootkube
all: _output/bin/linux/bootkube _output/bin/darwin/bootkube

release: clean check _output/release/bootkube-linux-amd64.tar.gz _output/release/bootkube-darwin-amd64.tar.gz

check: pkg/asset/internal/templates.go
@find . -name vendor -prune -o -name '*.go' -exec gofmt -s -d {} +
@go vet $(shell go list ./... | grep -v '/vendor/')
@go test -v $(shell go list ./... | grep -v '/vendor/')

bin/%/bootkube: $(GOFILES) pkg/asset/internal/templates.go
_output/bin/%/bootkube: LDFLAGS=-X github.com/coreos/bootkube/pkg/version.Version=$(shell $(CURDIR)/build/git-version.sh)
_output/bin/%/bootkube: $(GOFILES) pkg/asset/internal/templates.go
mkdir -p $(dir $@)
GOOS=$* go build -o bin/$*/bootkube github.com/coreos/bootkube/cmd/bootkube
GOOS=$* go build -ldflags "$(LDFLAGS)" -o _output/bin/$*/bootkube github.com/coreos/bootkube/cmd/bootkube

_output/release/bootkube-%-amd64.tar.gz: _output/bin/%/bootkube
@mkdir -p $(dir $@)
tar czf $@ -C $(dir $<) bootkube

install: bin/$(shell uname | tr A-Z a-z)/bootkube
install: _output/bin/$(LOCAL_OS)/bootkube
cp $< $(GOPATH_BIN)

pkg/asset/internal/templates.go: $(GOFILES)
pkg/asset/internal/templates.go: $(GOFILES) $(TEMPLATES)
mkdir -p $(dir $@)
go generate pkg/asset/templates_gen.go

Expand Down Expand Up @@ -47,8 +56,7 @@ vendor-$(VENDOR_VERSION):
@rm -rf $@/k8s.io/kubernetes/Godeps $@/k8s.io/kubernetes/.git

clean:
rm -rf bin/
rm -rf _output
rm -rf pkg/asset/internal

.PHONY: all check clean install vendor pkg/asset/internal/templates.go

.PHONY: all check clean install release vendor
27 changes: 27 additions & 0 deletions build/build-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
set -euo pipefail

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

BOOTKUBE_ROOT=${SCRIPT_DIR}/..
BOOTKUBE_RELEASE=${BOOTKUBE_BIN:-${BOOTKUBE_ROOT}/_output/release/bootkube-linux-amd64.tar.gz}
DOCKER_REPO=${DOCKER_REPO:-quay.io/coreos/bootkube}
DOCKER_TAG=${DOCKER_TAG:-$(${BOOTKUBE_ROOT}/build/git-version.sh)}
DOCKER_PUSH=${DOCKER_PUSH:-false}

sudo rkt run \
--volume bk,kind=host,source=${BOOTKUBE_ROOT} \
--mount volume=bk,target=/go/src/github.com/coreos/bootkube \
--insecure-options=image docker://golang:1.6.2 --exec /bin/bash -- -c \
"cd /go/src/github.com/coreos/bootkube && make clean release"

TEMPDIR=$(mktemp -d -t bootkube.XXXX)

printf "FROM scratch\nCOPY bootkube /bootkube" > ${TEMPDIR}/Dockerfile
tar xzvf ${BOOTKUBE_RELEASE} -C ${TEMPDIR}
docker build -t ${DOCKER_REPO}:${DOCKER_TAG} ${TEMPDIR}
rm -rf ${TEMPDIR}

if [[ ${DOCKER_PUSH} == "true" ]]; then
docker push ${DOCKER_REPO}:${DOCKER_TAG}
fi
22 changes: 22 additions & 0 deletions build/git-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -euo pipefail

# parse the current git commit hash
COMMIT=$(git rev-parse HEAD)

# check if the current commit has a matching tag
TAG=$(git describe --exact-match --abbrev=0 --tags ${COMMIT} 2> /dev/null || true)

# use the matching tag as the version, if available
if [ -z "$TAG" ]; then
VERSION=$COMMIT
else
VERSION=$TAG
fi

# check for changed files (not untracked files)
if [ -n "$(git diff --shortstat 2> /dev/null | tail -n1)" ]; then
VERSION="${VERSION}-dirty"
fi

echo $VERSION
13 changes: 13 additions & 0 deletions cmd/bootkube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"os"

"github.com/spf13/cobra"

"github.com/coreos/bootkube/pkg/version"
)

var (
Expand All @@ -13,9 +15,20 @@ var (
Short: "Bootkube!",
Long: "",
}

cmdVersion = &cobra.Command{
Use: "version",
Short: "Output version information",
Long: "",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Printf("Version: %s\n", version.Version)
return nil
},
}
)

func main() {
cmdRoot.AddCommand(cmdVersion)
if err := cmdRoot.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand Down
3 changes: 3 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package version

var Version string = "none"

0 comments on commit 04848d1

Please sign in to comment.