Update cloud build process for kustomize.

This commit is contained in:
Jeffrey Regan
2019-09-26 11:27:17 -07:00
parent fa1af6f51e
commit a694ac7b63
12 changed files with 302 additions and 245 deletions

View File

@@ -1,59 +1,15 @@
#!/bin/bash
set -e
set -x
# Google Container Builder automatically checks
# out all the code under the /workspace directory,
# but we actually want it to under the correct
# expected package in the GOPATH (/go)
#
# - 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
# goreleaser must be run from the _module_ being released.
cd kustomize
OWNER="sigs.k8s.io"
REPO="kustomize"
GO_PKG_OWNER=$GOPATH/src/$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
# 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 \
/bin/goreleaser \
release \
--config=releasing/goreleaser.yaml \
--config=../releasing/goreleaser.yaml \
--rm-dist \
--skip-validate ${SNAPSHOT}
--skip-validate \
$@

View File

@@ -1,10 +1,9 @@
steps:
- name: "gcr.io/cloud-builders/git"
args: [fetch, --tags, --depth=100]
- name: "gcr.io/kubebuilder/goreleaser_with_go_1.12.5:0.0.1"
args: ["bash", "releasing/cloudbuild.sh"]
- name: goreleaser/goreleaser
entrypoint: /bin/sh
args: ["releasing/cloudbuild.sh"]
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==
GITHUB_TOKEN: CiQAyrREbPgXJOeT7M3t+WlxkhXwlMPudixBeiyWTjmLOMLqdK4SUQA0W+xUmDJKAhyfHCcwqSEzUn9OwKC7XAYcmwe0CCKTCbPbDgmioDK24q3LVapndXNvnnHvCjhOJNEr1o+P1DCF+LlzYV2YL8lP09rrKrslPg==

View File

@@ -6,12 +6,13 @@
#
project_name: kustomize
builds:
- main: ./cmd/kustomize/main.go
- main: ./main.go
binary: kustomize
ldflags: -s -X sigs.k8s.io/kustomize/v3/pkg/commands/misc.kustomizeVersion={{.Version}} -X sigs.k8s.io/kustomize/v3/pkg/commands/misc.gitCommit={{.Commit}} -X sigs.k8s.io/kustomize/v3/pkg/commands/misc.buildDate={{.Date}}
ldflags: -s -X sigs.k8s.io/kustomize/kustomize/v3/provenance.version={{.Version}} -X sigs.k8s.io/kustomize/kustomize/v3/provenance.gitCommit={{.Commit}} -X sigs.k8s.io/kustomize/kustomize/v3/provenance.buildDate={{.Date}}
goos:
- darwin
- linux
- darwin
- windows
goarch:
- amd64
env:

View File

@@ -1,6 +1,6 @@
#!/bin/bash
# Usage
# Usage - from the repository root, enter
#
# ./releasing/localbuild.sh
#
@@ -23,44 +23,27 @@
#
# releasing/cloudbuild.sh
#
# which runs goreleaser from the proper directory.
#
# The script you are reading now does something
# analogous via docker tricks.
set -e
if [ -z ${GOPATH+x} ]; then
echo GOPATH is unset; cannot proceed.
exit 1
fi
pushd $GOPATH/src/sigs.k8s.io/kustomize
pwd
# The first "step" in the following uses a special
# goreleaser container image that the kubebuilder folks made.
# TODO: On a rainy day, switch to something more standard.
# Modify cloudbuild.yaml to add the --snapshot flag.
# This suppresses the github release, and leaves
# the build output in the kustomize/dist directory.
config=$(mktemp)
cat <<EOF >$config
steps:
- name: "gcr.io/kubebuilder/goreleaser_with_go_1.12.5:0.0.1"
args: ["bash", "releasing/cloudbuild.sh", "--snapshot"]
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==
EOF
sed 's|\["releasing/cloudbuild.sh"\]|["releasing/cloudbuild.sh", "--snapshot"]|' \
releasing/cloudbuild.yaml > $config
cloud-build-local \
--config=$config \
--bind-mount-source \
--dryrun=false \
.
--config=$config \
--bind-mount-source \
--dryrun=false \
.
# Print results of local build, which went to ./dist
# Print results of local build
echo "##########################################"
tree ./dist
tree ./kustomize/dist
echo "##########################################"
popd