Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 04848d1

Browse files
committed
Add release build process
1 parent f5744f7 commit 04848d1

File tree

7 files changed

+83
-10
lines changed

7 files changed

+83
-10
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
bin/
1+
_output
22
vendor-v[0-9].[0-9].[0-9]/
33

44
hack/*/.vagrant/

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ go:
33
- 1.6
44
script:
55
- test -z "$(go generate pkg/asset/templates_gen.go && git diff | tee /dev/stderr)"
6-
- make clean check all
6+
- make clean release

Makefile

+16-8
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,33 @@ export GO15VENDOREXPERIMENT:=1
22
export CGO_ENABLED:=0
33
export GOARCH:=amd64
44

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

8-
all: bin/linux/bootkube bin/darwin/bootkube
10+
all: _output/bin/linux/bootkube _output/bin/darwin/bootkube
11+
12+
release: clean check _output/release/bootkube-linux-amd64.tar.gz _output/release/bootkube-darwin-amd64.tar.gz
913

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

15-
bin/%/bootkube: $(GOFILES) pkg/asset/internal/templates.go
19+
_output/bin/%/bootkube: LDFLAGS=-X github.com/coreos/bootkube/pkg/version.Version=$(shell $(CURDIR)/build/git-version.sh)
20+
_output/bin/%/bootkube: $(GOFILES) pkg/asset/internal/templates.go
1621
mkdir -p $(dir $@)
17-
GOOS=$* go build -o bin/$*/bootkube github.com/coreos/bootkube/cmd/bootkube
22+
GOOS=$* go build -ldflags "$(LDFLAGS)" -o _output/bin/$*/bootkube github.com/coreos/bootkube/cmd/bootkube
23+
24+
_output/release/bootkube-%-amd64.tar.gz: _output/bin/%/bootkube
25+
@mkdir -p $(dir $@)
26+
tar czf $@ -C $(dir $<) bootkube
1827

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

22-
pkg/asset/internal/templates.go: $(GOFILES)
31+
pkg/asset/internal/templates.go: $(GOFILES) $(TEMPLATES)
2332
mkdir -p $(dir $@)
2433
go generate pkg/asset/templates_gen.go
2534

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

4958
clean:
50-
rm -rf bin/
59+
rm -rf _output
5160
rm -rf pkg/asset/internal
5261

53-
.PHONY: all check clean install vendor pkg/asset/internal/templates.go
54-
62+
.PHONY: all check clean install release vendor

build/build-release.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
6+
BOOTKUBE_ROOT=${SCRIPT_DIR}/..
7+
BOOTKUBE_RELEASE=${BOOTKUBE_BIN:-${BOOTKUBE_ROOT}/_output/release/bootkube-linux-amd64.tar.gz}
8+
DOCKER_REPO=${DOCKER_REPO:-quay.io/coreos/bootkube}
9+
DOCKER_TAG=${DOCKER_TAG:-$(${BOOTKUBE_ROOT}/build/git-version.sh)}
10+
DOCKER_PUSH=${DOCKER_PUSH:-false}
11+
12+
sudo rkt run \
13+
--volume bk,kind=host,source=${BOOTKUBE_ROOT} \
14+
--mount volume=bk,target=/go/src/github.com/coreos/bootkube \
15+
--insecure-options=image docker://golang:1.6.2 --exec /bin/bash -- -c \
16+
"cd /go/src/github.com/coreos/bootkube && make clean release"
17+
18+
TEMPDIR=$(mktemp -d -t bootkube.XXXX)
19+
20+
printf "FROM scratch\nCOPY bootkube /bootkube" > ${TEMPDIR}/Dockerfile
21+
tar xzvf ${BOOTKUBE_RELEASE} -C ${TEMPDIR}
22+
docker build -t ${DOCKER_REPO}:${DOCKER_TAG} ${TEMPDIR}
23+
rm -rf ${TEMPDIR}
24+
25+
if [[ ${DOCKER_PUSH} == "true" ]]; then
26+
docker push ${DOCKER_REPO}:${DOCKER_TAG}
27+
fi

build/git-version.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# parse the current git commit hash
5+
COMMIT=$(git rev-parse HEAD)
6+
7+
# check if the current commit has a matching tag
8+
TAG=$(git describe --exact-match --abbrev=0 --tags ${COMMIT} 2> /dev/null || true)
9+
10+
# use the matching tag as the version, if available
11+
if [ -z "$TAG" ]; then
12+
VERSION=$COMMIT
13+
else
14+
VERSION=$TAG
15+
fi
16+
17+
# check for changed files (not untracked files)
18+
if [ -n "$(git diff --shortstat 2> /dev/null | tail -n1)" ]; then
19+
VERSION="${VERSION}-dirty"
20+
fi
21+
22+
echo $VERSION

cmd/bootkube/main.go

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"os"
66

77
"github.com/spf13/cobra"
8+
9+
"github.com/coreos/bootkube/pkg/version"
810
)
911

1012
var (
@@ -13,9 +15,20 @@ var (
1315
Short: "Bootkube!",
1416
Long: "",
1517
}
18+
19+
cmdVersion = &cobra.Command{
20+
Use: "version",
21+
Short: "Output version information",
22+
Long: "",
23+
RunE: func(cmd *cobra.Command, args []string) error {
24+
fmt.Printf("Version: %s\n", version.Version)
25+
return nil
26+
},
27+
}
1628
)
1729

1830
func main() {
31+
cmdRoot.AddCommand(cmdVersion)
1932
if err := cmdRoot.Execute(); err != nil {
2033
fmt.Fprintln(os.Stderr, err)
2134
os.Exit(1)

pkg/version/version.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package version
2+
3+
var Version string = "none"

0 commit comments

Comments
 (0)