Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#78 from droot/build-automation
Browse files Browse the repository at this point in the history
added release automation
  • Loading branch information
Phillip Wittrock authored Apr 19, 2018
2 parents b3c7b05 + c106cf5 commit c8635da
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 71 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Release:

Latest:

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


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

## TL;DR

**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.
**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:

```shell

# download the release
wget /path/to/kubebuilder_<version>_<operating-system>_amd64.tar.gz

# extract the archive
tar -zxvf kubebuilder_<version>_<operating-system>_amd64.tar.gz

sudo mv kubebuilder_<version>_<operating-system>_amd64 /usr/local/kubebuilder

#update your PATH to include /usr/local/kubebuilder/bin
export PATH=$PATH:/usr/local/kubebuilder/bin

```

Create an _empty_ project under a new GOPATH.

Expand Down
41 changes: 41 additions & 0 deletions build/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This is a GoReleaser configuration file for Kubebuilder release.
# Make sure to check the documentation at http://goreleaser.com
builds:
- main: ./cmd/kubebuilder
binary: kubebuilder
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}}
goos:
- darwin
- linux
goarch:
- amd64
env:
- CGO_ENABLED=0
- main: ./cmd/kubebuilder-gen
binary: kubebuilder-gen
goos:
- darwin
- linux
goarch:
- amd64
env:
- CGO_ENABLED=0
archive:
files:
- "/workspace/_output/kubebuilder/bin/vendor.tar.gz"
- "/workspace/_output/{{ .Os }}_{{ .Arch }}/kubebuilder/bin/*"
wrap_in_directory: true
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "master"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
release:
github:
owner: kubernetes-sigs
name: kubebuilder
53 changes: 35 additions & 18 deletions build/build_kubebuilder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,38 @@ set -x
# - Create the directory to host the code that matches the expected GOPATH package locations
# - Use /go as the default GOPATH because this is what the image uses
# - Link our current directory (containing the source code) to the package location in the GOPATH
mkdir -p /go/src/github.com/kubernetes-sigs
ln -s $(pwd) /go/src/github.com/kubernetes-sigs/kubebuilder

# Create the output directory for the binaries we will build
# Make sure CGO is 0 so the binaries are statically compiled and linux which is necessary for cross compiling go
export CGO=0
export DEST=/workspace/_output/kubebuilder/bin/
mkdir -p $DEST || echo ""

# Explicitly set the values of the variables in package "X" using ldflag so that they are statically compiled into
# the "version" command
export X=github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder/version
go build -o $DEST/kubebuilder \
-ldflags "-X $X.kubeBuilderVersion=$VERSION -X $X.goos=$GOOS -X $X.goarch=$GOARCH -X $X.kubernetesVendorVersion=$KUBERNETES_VERSION" \
github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder

# Also build the kubebuilder-gen command
go build -o $DEST/kubebuilder-gen github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder-gen

OWNER="kubernetes-sigs"
REPO="kubebuilder"

GO_PKG_OWNER=$GOPATH/src/github.com/$OWNER
GO_PKG_PATH=$GO_PKG_OWNER/$REPO

mkdir -p $GO_PKG_OWNER
ln -sf $(pwd) $GO_PKG_PATH

# When invoked in container builder, this script runs under /workspace which is
# not under $GOPATH, so we need to `cd` to repo under GOPATH for it to build
cd $GO_PKG_PATH


# NOTE: if snapshot is enabled, release is not published to GitHub and the build
# is available under workspace/dist directory.
SNAPSHOT=""

# parse commandline args copied from the link below
# 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

while [[ $# -gt 0 ]]
do
key="$1"

case $key in
--snapshot)
SNAPSHOT="--snapshot"
shift # past argument
;;
esac
done

/goreleaser release --config=build/.goreleaser.yml --debug --rm-dist ${SNAPSHOT}
54 changes: 25 additions & 29 deletions build/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Instructions to run locally:
# Download google container builder: https://github.com/kubernetes-sigs/container-builder-local
# Set you GOOS and GOARCH vars to match your system
# Set OUTPUT to the location to write the directory containing the tar.gz
# $ container-builder-local --config=build/cloudbuild_with_goreleaser.yaml --dryrun=false \
# --write-workspace=$OUTPUT .
# Release tar will be in $OUTPUT

steps:
- name: "ubuntu"
args: ["mkdir", "-p", "/workspace/_output"]
- name: "gcr.io/kubebuilder/thirdparty-${_GOOS}:1.9"
args: ["tar", "-xzvf", "/kubebuilder_${_GOOS}_${_GOARCH}.tar.gz"]
dir: "_output"
- name: "golang:1.10-stretch"
args: ["bash", "build/build_kubebuilder.sh"]
env:
- 'GOOS=${_GOOS}'
- 'GOARCH=${_GOARCH}'
- 'CGO=0'
- 'VERSION=${TAG_NAME}'
- 'KUBERNETES_VERSION=v1.9'
args: ["mkdir", "-p", "/workspace/_output/linux_amd64"]
- name: "gcr.io/kubebuilder/thirdparty-linux:1.9"
args: ["tar", "-xzvf", "/kubebuilder_linux_amd64.tar.gz"]
dir: "_output/linux_amd64"
- name: "ubuntu"
args: ["bash", "build/build_vendor.sh"]
args: ["mkdir", "-p", "/workspace/_output/darwin_amd64"]
- name: "gcr.io/kubebuilder/thirdparty-darwin:1.9"
args: ["tar", "-xzvf", "/kubebuilder_darwin_amd64.tar.gz"]
dir: "_output/darwin_amd64"
- name: "ubuntu"
args: ["bash", "build/package.sh"]
env:
- 'GOOS=${_GOOS}'
- 'GOARCH=${_GOARCH}'
- 'VERSION=${TAG_NAME}'
- name: "golang:1.10-stretch"
args: ["bash", "build/test.sh"]
env:
- 'GOOS=${_GOOS}'
- 'GOARCH=${_GOARCH}'
- 'VERSION=${TAG_NAME}'
- name: 'gcr.io/cloud-builders/gsutil'
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']
args: ["bash", "build/build_vendor.sh"]
- name: "gcr.io/kubebuilder/goreleaser_with_go_1.10:0.0.1"
args: ["bash", "build/build_kubebuilder.sh"]
env:
- 'GOOS=${_GOOS}'
- 'GOARCH=${_GOARCH}'
- 'VERSION=${TAG_NAME}'
- 'KUBERNETES_VERSION=1.9'
secretEnv: ['GITHUB_TOKEN']
secrets:
- kmsKeyName: projects/kubebuilder/locations/global/keyRings/kubebuilder-gh-tokens/cryptoKeys/gh-release-token
secretEnv:
GITHUB_TOKEN: CiQAChsKTruEiSo6yBI+xg75jyr4f8yM93R2e9QbpeRX3jF3VAwSUQDQuYkCiUd+6e/1wKQAyHnf6BYv0GNGMghyNzYbXT0owBzQqmIQJeu/VDGZcEVabIWErNXjbPqPiysIu0uAiKAAUTUK0VYMr9E6GdTJ0+hVmg==
35 changes: 14 additions & 21 deletions build/cloudbuild_local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,23 @@
# Set you GOOS and GOARCH vars to match your system
# Set OUTPUT to the location to write the directory containing the tar.gz
# $ container-builder-local --config=build/cloudbuild_local.yaml --dryrun=false \
# --substitutions=_GOOS=$GOOS,_GOARCH=$GOARCH --write-workspace=$OUTPUT .
# Release tar will be in $OUTPUT
# --write-workspace=/tmp/w .
# Release tar will be in /tmp/w/workspace/dist

steps:
- name: "ubuntu"
args: ["mkdir", "-p", "/workspace/_output"]
- name: "gcr.io/kubebuilder/thirdparty-${_GOOS}:1.9"
args: ["tar", "-xzvf", "/kubebuilder_${_GOOS}_${_GOARCH}.tar.gz"]
dir: "_output"
- name: "golang:1.10-stretch"
args: ["bash", "build/build_kubebuilder.sh"]
env:
- 'GOOS=${_GOOS}'
- 'GOARCH=${_GOARCH}'
- 'CGO=0'
- 'VERSION=${TAG_NAME}'
- 'KUBERNETES_VERSION=v1.9'
args: ["mkdir", "-p", "/workspace/_output/linux_amd64"]
- name: "gcr.io/kubebuilder/thirdparty-linux:1.9"
args: ["tar", "-xzvf", "/kubebuilder_linux_amd64.tar.gz"]
dir: "_output/linux_amd64"
- name: "ubuntu"
args: ["bash", "build/build_vendor.sh"]
args: ["mkdir", "-p", "/workspace/_output/darwin_amd64"]
- name: "gcr.io/kubebuilder/thirdparty-darwin:1.9"
args: ["tar", "-xzvf", "/kubebuilder_darwin_amd64.tar.gz"]
dir: "_output/darwin_amd64"
- name: "ubuntu"
args: ["bash", "build/package.sh"]
args: ["bash", "build/build_vendor.sh"]
- name: "gcr.io/kubebuilder/goreleaser_with_go_1.10:0.0.1"
args: ["bash", "build/build_kubebuilder.sh", "--snapshot"]
env:
- 'GOOS=${_GOOS}'
- 'GOARCH=${_GOARCH}'
- 'VERSION=${TAG_NAME}'
- name: "ubuntu"
args: ["bash", "-c", "ls | grep -v tar.gz | xargs rm -rf"]
- 'KUBERNETES_VERSION=1.9'
43 changes: 43 additions & 0 deletions build/cloudbuild_snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2018 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Instructions to run locally:
# Download google container builder: https://github.com/kubernetes-sigs/container-builder-local
# Set you GOOS and GOARCH vars to match your system
# Set OUTPUT to the location to write the directory containing the tar.gz
# $ container-builder-local --config=build/cloudbuild_snapshot.yaml --dryrun=false \
# --write-workspace=$OUTPUT .
# Release tar will be in $OUTPUT

steps:
- name: "ubuntu"
args: ["mkdir", "-p", "/workspace/_output/linux_amd64"]
- name: "gcr.io/kubebuilder/thirdparty-linux:1.9"
args: ["tar", "-xzvf", "/kubebuilder_linux_amd64.tar.gz"]
dir: "_output/linux_amd64"
- name: "ubuntu"
args: ["mkdir", "-p", "/workspace/_output/darwin_amd64"]
- name: "gcr.io/kubebuilder/thirdparty-darwin:1.9"
args: ["tar", "-xzvf", "/kubebuilder_darwin_amd64.tar.gz"]
dir: "_output/darwin_amd64"
- name: "ubuntu"
args: ["bash", "build/build_vendor.sh"]
- name: "gcr.io/kubebuilder/goreleaser_with_go_1.10:0.0.1"
args: ["bash", "build/build_kubebuilder.sh", "--snapshot"]
env:
- 'KUBERNETES_VERSION=1.9'
- name: 'gcr.io/cloud-builders/gsutil'
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']
- name: 'gcr.io/cloud-builders/gsutil'
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 comments on commit c8635da

Please sign in to comment.