kustomize: automate github release publishing

An example release looks like:

https://github.com/droot/kubectl/releases/tag/v0.1.0
This commit is contained in:
Sunil Arora 2018-04-11 15:16:57 -07:00
parent 60665244b3
commit 88a1b80229
4 changed files with 52 additions and 36 deletions

View File

@ -0,0 +1,29 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
project_name: kustomize
builds:
- main: ./cmd/kustomize
binary: kustomize
ldflags: -s -X k8s.io/kubectl/cmd/kustomize/version.kustomizeVersion={{.Version}} -X k8s.io/kubectl/cmd/kustomize/version.gitCommit={{.Commit}} -X k8s.io/kubectl/cmd/kustomize/version.buildDate={{.Date}}
goos:
- darwin
- linux
- windows
env:
- CGO_ENABLED=0
archive:
wrap_in_directory: true
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
release:
github:
owner: droot
name: kubectl

View File

@ -22,30 +22,21 @@ 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
export PKG=k8s.io
export REPO=kubectl
export CMD=kustomize
mkdir -p /go/src/$PKG
ln -s $(pwd) /go/src/$PKG/$REPO
GO_PKG_OWNER=$GOPATH/src/$PKG
GO_PKG_PATH=$GO_PKG_OWNER/$REPO
# 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/$CMD/bin
mkdir -p $DEST || echo ""
mkdir -p $GO_PKG_OWNER
ln -s $(pwd) $GO_PKG_PATH
go build -o $DEST/$CMD $PKG/$REPO/cmd/$CMD
# 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
# Explicitly set the values of the variables in package "X" using ldflag so that they are statically compiled into
# the "version" command
export GITCOMMIT=$(git rev-parse HEAD)
export BUILDDATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
export X=$PKG/$REPO/cmd/$CMD/version
go build -o $DEST/$CMD \
-ldflags "-X $X.kustomizeVersion=$TAG -X $X.goos=$GOOS -X $X.goarch=$GOARCH -X $X.gitCommit=$GITCOMMIT -X $X.buildDate=$BUILDDATE" \
$PKG/$REPO/cmd/$CMD
# Generate the tar archive
cd /workspace/_output/
tar -czvf /workspace/$CMD-$VERSION-$GOOS-$GOARCH.tar.gz $CMD
/goreleaser release --config=cmd/$CMD/build/.goreleaser.yml --debug --rm-dist
# --skip-validate
# --snapshot --skip-publish

View File

@ -16,15 +16,10 @@
steps:
- name: "ubuntu"
args: ["mkdir", "-p", "/workspace/_output"]
- name: "golang:1.10-stretch"
- name: "gcr.io/kustomize-199618/golang_with_goreleaser:1.10-stretch"
args: ["bash", "cmd/kustomize/build/build.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', 'kustomize-${TAG_NAME}-${_GOOS}-${_GOARCH}.tar.gz', 'gs://kustomize-release/kustomize-${TAG_NAME}-${_GOOS}-${_GOARCH}.tar.gz']
env:
- 'GOOS=${_GOOS}'
- 'GOARCH=${_GOARCH}'
- 'VERSION=${TAG_NAME}'
secretEnv: ['GITHUB_TOKEN']
secrets:
- kmsKeyName: projects/kustomize-199618/locations/global/keyRings/github-tokens/cryptoKeys/gh-release-token
secretEnv:
GITHUB_TOKEN: CiQAyrREbPgXJOeT7M3t+WlxkhXwlMPudixBeiyWTjmLOMLqdK4SUQA0W+xUmDJKAhyfHCcwqSEzUn9OwKC7XAYcmwe0CCKTCbPbDgmioDK24q3LVapndXNvnnHvCjhOJNEr1o+P1DCF+LlzYV2YL8lP09rrKrslPg==

View File

@ -23,9 +23,10 @@
steps:
- name: "ubuntu"
args: ["mkdir", "-p", "/workspace/_output"]
- name: "golang:1.10-stretch"
- name: "gcr.io/kustomize-199618/golang_with_goreleaser:1.10-stretch"
args: ["bash", "cmd/kustomize/build/build.sh"]
env:
- 'GOOS=${_GOOS}'
- 'GOARCH=${_GOARCH}'
- 'VERSION=${TAG_NAME}'
secretEnv: ['GITHUB_TOKEN']
secrets:
- kmsKeyName: projects/kustomize-199618/locations/global/keyRings/github-tokens/cryptoKeys/gh-release-token
secretEnv:
GITHUB_TOKEN: CiQAyrREbPgXJOeT7M3t+WlxkhXwlMPudixBeiyWTjmLOMLqdK4SUQA0W+xUmDJKAhyfHCcwqSEzUn9OwKC7XAYcmwe0CCKTCbPbDgmioDK24q3LVapndXNvnnHvCjhOJNEr1o+P1DCF+LlzYV2YL8lP09rrKrslPg==