From c106cf53d18e163ddfbba316dbefae643db5cc19 Mon Sep 17 00:00:00 2001 From: Sunil Arora Date: Thu, 19 Apr 2018 15:08:35 -0700 Subject: [PATCH] added release automation Highlights: Uses GoReleaser for building and publishing releases to Github Remove testing during the build process (will do done through Travis as presubmit) --- README.md | 21 +++++++++++-- build/.goreleaser.yml | 41 ++++++++++++++++++++++++++ build/build_kubebuilder.sh | 53 +++++++++++++++++++++------------ build/cloudbuild.yaml | 54 ++++++++++++++++------------------ build/cloudbuild_local.yaml | 35 +++++++++------------- build/cloudbuild_snapshot.yaml | 43 +++++++++++++++++++++++++++ 6 files changed, 176 insertions(+), 71 deletions(-) create mode 100644 build/.goreleaser.yml create mode 100644 build/cloudbuild_snapshot.yaml diff --git a/README.md b/README.md index 24e7af2c876..e0fa9e6ef7e 100644 --- a/README.md +++ b/README.md @@ -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` @@ -25,7 +25,22 @@ to simplify building and publishing Kubernetes APIs from scratch. ## TL;DR -**First:** Download the latest `kubebuilder-release---amd64.tar.gz` release. Extract it into /usr/local/ and update your PATH to include /usr/local/kubebuilder/bin. +**First:** Download the latest `kubebuilder___amd64.tar.gz` release. Extracting the archive will give `kubebuilder___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___amd64.tar.gz + +# extract the archive +tar -zxvf kubebuilder___amd64.tar.gz + +sudo mv kubebuilder___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. diff --git a/build/.goreleaser.yml b/build/.goreleaser.yml new file mode 100644 index 00000000000..bf2385b2600 --- /dev/null +++ b/build/.goreleaser.yml @@ -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 diff --git a/build/build_kubebuilder.sh b/build/build_kubebuilder.sh index 19f312958d6..8a682986c52 100644 --- a/build/build_kubebuilder.sh +++ b/build/build_kubebuilder.sh @@ -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} diff --git a/build/cloudbuild.yaml b/build/cloudbuild.yaml index 2174ac31f92..67258365dec 100644 --- a/build/cloudbuild.yaml +++ b/build/cloudbuild.yaml @@ -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== diff --git a/build/cloudbuild_local.yaml b/build/cloudbuild_local.yaml index 6d05d07252d..105ddd505b9 100644 --- a/build/cloudbuild_local.yaml +++ b/build/cloudbuild_local.yaml @@ -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' diff --git a/build/cloudbuild_snapshot.yaml b/build/cloudbuild_snapshot.yaml new file mode 100644 index 00000000000..d064e4cc10c --- /dev/null +++ b/build/cloudbuild_snapshot.yaml @@ -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']