Skip to content

Commit c8635da

Browse files
author
Phillip Wittrock
authored
Merge pull request kubernetes-sigs#78 from droot/build-automation
added release automation
2 parents b3c7b05 + c106cf5 commit c8635da

6 files changed

+176
-71
lines changed

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Release:
1212

1313
Latest:
1414

15-
- [darwin master HEAD](https://storage.googleapis.com/kubebuilder-release/kubebuilder--darwin-amd64.tar.gz)
16-
- [linux master HEAD](https://storage.googleapis.com/kubebuilder-release/kubebuilder--linux-amd64.tar.gz)
15+
- [darwin master HEAD](https://storage.googleapis.com/kubebuilder-release/kubebuilder_master_darwin_amd64.tar.gz)
16+
- [linux master HEAD](https://storage.googleapis.com/kubebuilder-release/kubebuilder_master_linux_amd64.tar.gz)
1717

1818

1919
## `kubebuilder`
@@ -25,7 +25,22 @@ to simplify building and publishing Kubernetes APIs from scratch.
2525

2626
## TL;DR
2727

28-
**First:** Download the latest `kubebuilder-release-<version>-<operating-system>-amd64.tar.gz` release. Extract it into /usr/local/ and update your PATH to include /usr/local/kubebuilder/bin.
28+
**First:** Download the latest `kubebuilder_<version>_<operating-system>_amd64.tar.gz` release. Extracting the archive will give `kubebuilder_<version>_<os>_amd64` directory. Move the extracted directory to /usr/local/kubebuilder and update your PATH to include /usr/local/kubebuilder/bin. Given below are the steps:
29+
30+
```shell
31+
32+
# download the release
33+
wget /path/to/kubebuilder_<version>_<operating-system>_amd64.tar.gz
34+
35+
# extract the archive
36+
tar -zxvf kubebuilder_<version>_<operating-system>_amd64.tar.gz
37+
38+
sudo mv kubebuilder_<version>_<operating-system>_amd64 /usr/local/kubebuilder
39+
40+
#update your PATH to include /usr/local/kubebuilder/bin
41+
export PATH=$PATH:/usr/local/kubebuilder/bin
42+
43+
```
2944

3045
Create an _empty_ project under a new GOPATH.
3146

build/.goreleaser.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This is a GoReleaser configuration file for Kubebuilder release.
2+
# Make sure to check the documentation at http://goreleaser.com
3+
builds:
4+
- main: ./cmd/kubebuilder
5+
binary: kubebuilder
6+
ldflags: -s -X github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder/version.kubebuilderVersion={{.Version}} -X github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder/version.gitCommit={{.Commit}} -X github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder/version.buildDate={{.Date}} -X github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder/version.kubernetesVendorVersion={{.Env.KUBERNETES_VERSION}}
7+
goos:
8+
- darwin
9+
- linux
10+
goarch:
11+
- amd64
12+
env:
13+
- CGO_ENABLED=0
14+
- main: ./cmd/kubebuilder-gen
15+
binary: kubebuilder-gen
16+
goos:
17+
- darwin
18+
- linux
19+
goarch:
20+
- amd64
21+
env:
22+
- CGO_ENABLED=0
23+
archive:
24+
files:
25+
- "/workspace/_output/kubebuilder/bin/vendor.tar.gz"
26+
- "/workspace/_output/{{ .Os }}_{{ .Arch }}/kubebuilder/bin/*"
27+
wrap_in_directory: true
28+
checksum:
29+
name_template: 'checksums.txt'
30+
snapshot:
31+
name_template: "master"
32+
changelog:
33+
sort: asc
34+
filters:
35+
exclude:
36+
- '^docs:'
37+
- '^test:'
38+
release:
39+
github:
40+
owner: kubernetes-sigs
41+
name: kubebuilder

build/build_kubebuilder.sh

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,38 @@ set -x
2222
# - Create the directory to host the code that matches the expected GOPATH package locations
2323
# - Use /go as the default GOPATH because this is what the image uses
2424
# - Link our current directory (containing the source code) to the package location in the GOPATH
25-
mkdir -p /go/src/github.com/kubernetes-sigs
26-
ln -s $(pwd) /go/src/github.com/kubernetes-sigs/kubebuilder
27-
28-
# Create the output directory for the binaries we will build
29-
# Make sure CGO is 0 so the binaries are statically compiled and linux which is necessary for cross compiling go
30-
export CGO=0
31-
export DEST=/workspace/_output/kubebuilder/bin/
32-
mkdir -p $DEST || echo ""
33-
34-
# Explicitly set the values of the variables in package "X" using ldflag so that they are statically compiled into
35-
# the "version" command
36-
export X=github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder/version
37-
go build -o $DEST/kubebuilder \
38-
-ldflags "-X $X.kubeBuilderVersion=$VERSION -X $X.goos=$GOOS -X $X.goarch=$GOARCH -X $X.kubernetesVendorVersion=$KUBERNETES_VERSION" \
39-
github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder
40-
41-
# Also build the kubebuilder-gen command
42-
go build -o $DEST/kubebuilder-gen github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder-gen
25+
26+
OWNER="kubernetes-sigs"
27+
REPO="kubebuilder"
28+
29+
GO_PKG_OWNER=$GOPATH/src/github.com/$OWNER
30+
GO_PKG_PATH=$GO_PKG_OWNER/$REPO
31+
32+
mkdir -p $GO_PKG_OWNER
33+
ln -sf $(pwd) $GO_PKG_PATH
34+
35+
# When invoked in container builder, this script runs under /workspace which is
36+
# not under $GOPATH, so we need to `cd` to repo under GOPATH for it to build
37+
cd $GO_PKG_PATH
38+
39+
40+
# NOTE: if snapshot is enabled, release is not published to GitHub and the build
41+
# is available under workspace/dist directory.
42+
SNAPSHOT=""
43+
44+
# parse commandline args copied from the link below
45+
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
46+
47+
while [[ $# -gt 0 ]]
48+
do
49+
key="$1"
50+
51+
case $key in
52+
--snapshot)
53+
SNAPSHOT="--snapshot"
54+
shift # past argument
55+
;;
56+
esac
57+
done
58+
59+
/goreleaser release --config=build/.goreleaser.yml --debug --rm-dist ${SNAPSHOT}

build/cloudbuild.yaml

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,33 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# Instructions to run locally:
16+
# Download google container builder: https://github.com/kubernetes-sigs/container-builder-local
17+
# Set you GOOS and GOARCH vars to match your system
18+
# Set OUTPUT to the location to write the directory containing the tar.gz
19+
# $ container-builder-local --config=build/cloudbuild_with_goreleaser.yaml --dryrun=false \
20+
# --write-workspace=$OUTPUT .
21+
# Release tar will be in $OUTPUT
22+
1523
steps:
1624
- name: "ubuntu"
17-
args: ["mkdir", "-p", "/workspace/_output"]
18-
- name: "gcr.io/kubebuilder/thirdparty-${_GOOS}:1.9"
19-
args: ["tar", "-xzvf", "/kubebuilder_${_GOOS}_${_GOARCH}.tar.gz"]
20-
dir: "_output"
21-
- name: "golang:1.10-stretch"
22-
args: ["bash", "build/build_kubebuilder.sh"]
23-
env:
24-
- 'GOOS=${_GOOS}'
25-
- 'GOARCH=${_GOARCH}'
26-
- 'CGO=0'
27-
- 'VERSION=${TAG_NAME}'
28-
- 'KUBERNETES_VERSION=v1.9'
25+
args: ["mkdir", "-p", "/workspace/_output/linux_amd64"]
26+
- name: "gcr.io/kubebuilder/thirdparty-linux:1.9"
27+
args: ["tar", "-xzvf", "/kubebuilder_linux_amd64.tar.gz"]
28+
dir: "_output/linux_amd64"
2929
- name: "ubuntu"
30-
args: ["bash", "build/build_vendor.sh"]
30+
args: ["mkdir", "-p", "/workspace/_output/darwin_amd64"]
31+
- name: "gcr.io/kubebuilder/thirdparty-darwin:1.9"
32+
args: ["tar", "-xzvf", "/kubebuilder_darwin_amd64.tar.gz"]
33+
dir: "_output/darwin_amd64"
3134
- name: "ubuntu"
32-
args: ["bash", "build/package.sh"]
33-
env:
34-
- 'GOOS=${_GOOS}'
35-
- 'GOARCH=${_GOARCH}'
36-
- 'VERSION=${TAG_NAME}'
37-
- name: "golang:1.10-stretch"
38-
args: ["bash", "build/test.sh"]
39-
env:
40-
- 'GOOS=${_GOOS}'
41-
- 'GOARCH=${_GOARCH}'
42-
- 'VERSION=${TAG_NAME}'
43-
- name: 'gcr.io/cloud-builders/gsutil'
44-
args: ['-h', 'Content-Type:application/gzip', 'cp', '-a', 'public-read', 'kubebuilder-${TAG_NAME}-${_GOOS}-${_GOARCH}.tar.gz', 'gs://kubebuilder-release/kubebuilder-${TAG_NAME}-${_GOOS}-${_GOARCH}.tar.gz']
35+
args: ["bash", "build/build_vendor.sh"]
36+
- name: "gcr.io/kubebuilder/goreleaser_with_go_1.10:0.0.1"
37+
args: ["bash", "build/build_kubebuilder.sh"]
4538
env:
46-
- 'GOOS=${_GOOS}'
47-
- 'GOARCH=${_GOARCH}'
48-
- 'VERSION=${TAG_NAME}'
39+
- 'KUBERNETES_VERSION=1.9'
40+
secretEnv: ['GITHUB_TOKEN']
41+
secrets:
42+
- kmsKeyName: projects/kubebuilder/locations/global/keyRings/kubebuilder-gh-tokens/cryptoKeys/gh-release-token
43+
secretEnv:
44+
GITHUB_TOKEN: CiQAChsKTruEiSo6yBI+xg75jyr4f8yM93R2e9QbpeRX3jF3VAwSUQDQuYkCiUd+6e/1wKQAyHnf6BYv0GNGMghyNzYbXT0owBzQqmIQJeu/VDGZcEVabIWErNXjbPqPiysIu0uAiKAAUTUK0VYMr9E6GdTJ0+hVmg==

build/cloudbuild_local.yaml

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,23 @@
1717
# Set you GOOS and GOARCH vars to match your system
1818
# Set OUTPUT to the location to write the directory containing the tar.gz
1919
# $ container-builder-local --config=build/cloudbuild_local.yaml --dryrun=false \
20-
# --substitutions=_GOOS=$GOOS,_GOARCH=$GOARCH --write-workspace=$OUTPUT .
21-
# Release tar will be in $OUTPUT
20+
# --write-workspace=/tmp/w .
21+
# Release tar will be in /tmp/w/workspace/dist
2222

2323
steps:
2424
- name: "ubuntu"
25-
args: ["mkdir", "-p", "/workspace/_output"]
26-
- name: "gcr.io/kubebuilder/thirdparty-${_GOOS}:1.9"
27-
args: ["tar", "-xzvf", "/kubebuilder_${_GOOS}_${_GOARCH}.tar.gz"]
28-
dir: "_output"
29-
- name: "golang:1.10-stretch"
30-
args: ["bash", "build/build_kubebuilder.sh"]
31-
env:
32-
- 'GOOS=${_GOOS}'
33-
- 'GOARCH=${_GOARCH}'
34-
- 'CGO=0'
35-
- 'VERSION=${TAG_NAME}'
36-
- 'KUBERNETES_VERSION=v1.9'
25+
args: ["mkdir", "-p", "/workspace/_output/linux_amd64"]
26+
- name: "gcr.io/kubebuilder/thirdparty-linux:1.9"
27+
args: ["tar", "-xzvf", "/kubebuilder_linux_amd64.tar.gz"]
28+
dir: "_output/linux_amd64"
3729
- name: "ubuntu"
38-
args: ["bash", "build/build_vendor.sh"]
30+
args: ["mkdir", "-p", "/workspace/_output/darwin_amd64"]
31+
- name: "gcr.io/kubebuilder/thirdparty-darwin:1.9"
32+
args: ["tar", "-xzvf", "/kubebuilder_darwin_amd64.tar.gz"]
33+
dir: "_output/darwin_amd64"
3934
- name: "ubuntu"
40-
args: ["bash", "build/package.sh"]
35+
args: ["bash", "build/build_vendor.sh"]
36+
- name: "gcr.io/kubebuilder/goreleaser_with_go_1.10:0.0.1"
37+
args: ["bash", "build/build_kubebuilder.sh", "--snapshot"]
4138
env:
42-
- 'GOOS=${_GOOS}'
43-
- 'GOARCH=${_GOARCH}'
44-
- 'VERSION=${TAG_NAME}'
45-
- name: "ubuntu"
46-
args: ["bash", "-c", "ls | grep -v tar.gz | xargs rm -rf"]
39+
- 'KUBERNETES_VERSION=1.9'

build/cloudbuild_snapshot.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2018 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Instructions to run locally:
16+
# Download google container builder: https://github.com/kubernetes-sigs/container-builder-local
17+
# Set you GOOS and GOARCH vars to match your system
18+
# Set OUTPUT to the location to write the directory containing the tar.gz
19+
# $ container-builder-local --config=build/cloudbuild_snapshot.yaml --dryrun=false \
20+
# --write-workspace=$OUTPUT .
21+
# Release tar will be in $OUTPUT
22+
23+
steps:
24+
- name: "ubuntu"
25+
args: ["mkdir", "-p", "/workspace/_output/linux_amd64"]
26+
- name: "gcr.io/kubebuilder/thirdparty-linux:1.9"
27+
args: ["tar", "-xzvf", "/kubebuilder_linux_amd64.tar.gz"]
28+
dir: "_output/linux_amd64"
29+
- name: "ubuntu"
30+
args: ["mkdir", "-p", "/workspace/_output/darwin_amd64"]
31+
- name: "gcr.io/kubebuilder/thirdparty-darwin:1.9"
32+
args: ["tar", "-xzvf", "/kubebuilder_darwin_amd64.tar.gz"]
33+
dir: "_output/darwin_amd64"
34+
- name: "ubuntu"
35+
args: ["bash", "build/build_vendor.sh"]
36+
- name: "gcr.io/kubebuilder/goreleaser_with_go_1.10:0.0.1"
37+
args: ["bash", "build/build_kubebuilder.sh", "--snapshot"]
38+
env:
39+
- 'KUBERNETES_VERSION=1.9'
40+
- name: 'gcr.io/cloud-builders/gsutil'
41+
args: ['-h', 'Content-Type:application/gzip', 'cp', '-a', 'public-read', 'kubebuilder_master_linux_amd64.tar.gz', 'gs://kubebuilder-release/kubebuilder_master_linux_amd64.tar.gz']
42+
- name: 'gcr.io/cloud-builders/gsutil'
43+
args: ['-h', 'Content-Type:application/gzip', 'cp', '-a', 'public-read', 'kubebuilder_master_darwin_amd64.tar.gz', 'gs://kubebuilder-release/kubebuilder_master_darwin_amd64.tar.gz']

0 commit comments

Comments
 (0)