mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
New cloud build scripts.
This commit is contained in:
@@ -1,75 +1,67 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Usage (from top of repo):
|
||||||
|
#
|
||||||
|
# releasing/cloudbuild.sh TAG [--snapshot]
|
||||||
|
#
|
||||||
|
# Where TAG is in the form
|
||||||
|
#
|
||||||
|
# api/v1.2.3
|
||||||
|
# kustomize/v1.2.3
|
||||||
|
# cmd/config/v1.2.3
|
||||||
|
# ... etc.
|
||||||
|
#
|
||||||
|
# Cloud build should be configured to trigger on tags
|
||||||
|
# matching:
|
||||||
|
#
|
||||||
|
# [\w/]+/v\d+\.\d+\.\d+
|
||||||
|
#
|
||||||
|
# This script runs goreleaser (http://goreleaser.com),
|
||||||
|
# presumably from a cloudbuild.yaml step that installed it.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
# Script to run http://goreleaser.com
|
fullTag=$1
|
||||||
|
|
||||||
# Removed from `build` stanza
|
|
||||||
# binary: $module
|
|
||||||
|
|
||||||
module=$1
|
|
||||||
shift
|
shift
|
||||||
|
echo "fullTag=$fullTag"
|
||||||
|
|
||||||
function setSemVer {
|
remainingArgs="$@"
|
||||||
# Check the tag for consistency with module name.
|
echo "Remaining args: $remainingArgs"
|
||||||
# The following assumes git tags formatted like
|
|
||||||
# "api/v1.2.3" and splits on the slash.
|
|
||||||
# Goreleaser doesn't know what to do with this
|
|
||||||
# tag format, and fails when creating an archive
|
|
||||||
# with a / in the name.
|
|
||||||
local fullTag=$(git describe)
|
|
||||||
local tModule=${fullTag%/*}
|
|
||||||
semVer=${fullTag#*/}
|
|
||||||
|
|
||||||
# Make sure version has no slash
|
# Take everything before the last slash.
|
||||||
# (k8s/v0.1.0 becomes v0.1.0)
|
# This is expected to match $module.
|
||||||
local tmp=${semVer#*/}
|
module=${fullTag%/*}
|
||||||
if [ "$tmp" != "$semVer" ]; then
|
echo "module=$module"
|
||||||
semVer="$tmp"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "tModule=$tModule"
|
# Take everything after the last slash.
|
||||||
|
# This should be something like "v1.2.3".
|
||||||
|
semVer=`echo $fullTag | sed "s|$module/||"`
|
||||||
echo "semVer=$semVer"
|
echo "semVer=$semVer"
|
||||||
if [ "$module" != "$tModule" ]; then
|
|
||||||
# Tag and argument sanity check
|
|
||||||
echo "Unexpected mismatch: moduleFromArg=$module, moduleFromTag=$tModule"
|
|
||||||
echo "Either the module arg to this script is wrong, or the git tag is wrong."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
setSemVer
|
# This is probably a directory called /workspace
|
||||||
|
echo "pwd = $PWD"
|
||||||
|
|
||||||
|
# Sanity check
|
||||||
|
echo "### ls -las . ################################"
|
||||||
|
ls -las .
|
||||||
|
# echo "### ls -C /usr/bin ################################"
|
||||||
|
# ls -C /usr/bin
|
||||||
|
echo "###################################"
|
||||||
|
|
||||||
|
|
||||||
|
# CD into the module directory.
|
||||||
|
# This directory expected to contain a main.go, so there's
|
||||||
|
# no need for extra details in the `build` stanza below.
|
||||||
cd $module
|
cd $module
|
||||||
|
|
||||||
# 2020/May/11 Windows build temporaraily removed
|
|
||||||
# ("- windows" removed from the goos: list below)
|
|
||||||
# because of https://github.com/microsoft/go-winio/issues/161
|
|
||||||
# Seeing the following in builds:
|
|
||||||
# : /go/pkg/mod/golang.org/x/crypto@v0.0.0-20190923035154-9ee001bba392/ssh/terminal/util_windows.go:97:61:
|
|
||||||
# multiple-value "golang.org/x/sys/windows".GetCurrentProcess() in single-value context
|
|
||||||
|
|
||||||
configFile=$(mktemp)
|
configFile=$(mktemp)
|
||||||
cat <<EOF >$configFile
|
cat <<EOF >$configFile
|
||||||
project_name: $module
|
project_name: $module
|
||||||
env:
|
|
||||||
- CGO_ENABLED=0
|
archives:
|
||||||
- GO111MODULE=on
|
- name_template: "${module}_${semVer}_{{ .Os }}_{{ .Arch }}"
|
||||||
checksum:
|
|
||||||
name_template: 'checksums.txt'
|
|
||||||
changelog:
|
|
||||||
sort: asc
|
|
||||||
filters:
|
|
||||||
exclude:
|
|
||||||
- '^docs:'
|
|
||||||
- '^test:'
|
|
||||||
- Merge pull request
|
|
||||||
- Merge branch
|
|
||||||
release:
|
|
||||||
github:
|
|
||||||
owner: kubernetes-sigs
|
|
||||||
name: kustomize
|
|
||||||
draft: true
|
|
||||||
builds:
|
builds:
|
||||||
- ldflags: >
|
- ldflags: >
|
||||||
-s
|
-s
|
||||||
@@ -81,12 +73,34 @@ builds:
|
|||||||
- linux
|
- linux
|
||||||
- darwin
|
- darwin
|
||||||
- windows
|
- windows
|
||||||
|
|
||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- amd64
|
||||||
archives:
|
|
||||||
- name_template: "${module}_${semVer}_{{ .Os }}_{{ .Arch }}"
|
changelog:
|
||||||
|
sort: asc
|
||||||
|
filters:
|
||||||
|
exclude:
|
||||||
|
- '^docs:'
|
||||||
|
- '^test:'
|
||||||
|
- Merge pull request
|
||||||
|
- Merge branch
|
||||||
|
|
||||||
|
checksum:
|
||||||
|
name_template: 'checksums.txt'
|
||||||
|
|
||||||
|
env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
- GO111MODULE=on
|
||||||
|
|
||||||
|
release:
|
||||||
|
github:
|
||||||
|
owner: monopole
|
||||||
|
name: kustomize
|
||||||
|
draft: true
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cat $configFile
|
cat $configFile
|
||||||
|
|
||||||
/bin/goreleaser release --config=$configFile --rm-dist --skip-validate $@
|
/bin/goreleaser release --config=$configFile --rm-dist --skip-validate $remainingArgs
|
||||||
|
|||||||
58
releasing/cloudbuild.yaml
Normal file
58
releasing/cloudbuild.yaml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
steps:
|
||||||
|
- name: 'bash'
|
||||||
|
args:
|
||||||
|
- 'echo'
|
||||||
|
- 'Cloud build substitution check: '
|
||||||
|
- 'BUILD_ID=$BUILD_ID'
|
||||||
|
- 'PROJECT_ID=$PROJECT_ID'
|
||||||
|
- 'REVISION_ID=$REVISION_ID'
|
||||||
|
- 'REPO_NAME=$REPO_NAME'
|
||||||
|
- 'COMMIT_SHA=$COMMIT_SHA'
|
||||||
|
- 'BRANCH_NAME=$BRANCH_NAME'
|
||||||
|
- 'TAG_NAME=$TAG_NAME'
|
||||||
|
|
||||||
|
# Cloud build has already copied the repo at the tag that
|
||||||
|
# that triggered the build to its /workspace directory, but
|
||||||
|
# hasn't actually _cloned_ the repo (there's no .git directory).
|
||||||
|
#
|
||||||
|
# The goreleaser tool, however, needs the repo and its history
|
||||||
|
# to produce release notes.
|
||||||
|
#
|
||||||
|
# So clone the repo to /workspace/myClone to avoid directory
|
||||||
|
# name collision.
|
||||||
|
#
|
||||||
|
- name: gcr.io/cloud-builders/git
|
||||||
|
args:
|
||||||
|
- clone
|
||||||
|
- https://github.com/kubernetes-sigs/kustomize.git
|
||||||
|
- myClone
|
||||||
|
|
||||||
|
# Checkout the proper tag.
|
||||||
|
- name: gcr.io/cloud-builders/git
|
||||||
|
dir: myClone
|
||||||
|
args:
|
||||||
|
- checkout
|
||||||
|
- $TAG_NAME
|
||||||
|
|
||||||
|
# Run goreleaser indirectly via a shell script
|
||||||
|
# to configure it properly.
|
||||||
|
- name: goreleaser/goreleaser:v0.138.0
|
||||||
|
entrypoint: /bin/sh
|
||||||
|
dir: myClone
|
||||||
|
secretEnv: ['GITHUB_TOKEN']
|
||||||
|
args:
|
||||||
|
- releasing/cloudbuild.sh
|
||||||
|
- $TAG_NAME
|
||||||
|
# - '--snapshot'
|
||||||
|
# Use this final arg in a local build, to suppress
|
||||||
|
# the release and leave the 'dist' directory in place.
|
||||||
|
|
||||||
|
# golreleaser expects the GITHUB_TOKEN env var to hold the github token
|
||||||
|
# it needs to write the released package and notes back to github.
|
||||||
|
# The raw token was encrypted by gcloud kms (Key Management Service)
|
||||||
|
# The base64 of that is shown below. It's decrypted by cloud build
|
||||||
|
# and provided back to goreleaser.
|
||||||
|
secrets:
|
||||||
|
- kmsKeyName: projects/jregan-corp-gke-dev/locations/global/keyRings/kust-cloud-key-ring/cryptoKeys/kust-cloud-key-name
|
||||||
|
secretEnv:
|
||||||
|
GITHUB_TOKEN: CiQAwfbOkSP4tJf3ZJZMjzHaRPZ2RxiQhORZ3xxlVtpoy8631uQSUACk6WMKjtkpsRkRl+uxWUVvN29M5qveyXjaDDO094/qwsSc8RiYlHYt7Ii1bWkkz3P1kG0nHfG7Fd46A+GJ6R5NhmNfingd/nu9iKrNwLXK
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
steps:
|
|
||||||
- name: "gcr.io/cloud-builders/git"
|
|
||||||
args: [fetch, --tags, --depth=100]
|
|
||||||
- name: "goreleaser/goreleaser:v0.134.0"
|
|
||||||
entrypoint: /bin/sh
|
|
||||||
args: ["releasing/cloudbuild.sh", "api"]
|
|
||||||
secretEnv: ['GITHUB_TOKEN']
|
|
||||||
secrets:
|
|
||||||
- kmsKeyName: projects/jregan-corp-gke-dev/locations/global/keyRings/kust-cloud-key-ring/cryptoKeys/kust-cloud-key-name
|
|
||||||
secretEnv:
|
|
||||||
GITHUB_TOKEN: CiQAwfbOkSP4tJf3ZJZMjzHaRPZ2RxiQhORZ3xxlVtpoy8631uQSUACk6WMKjtkpsRkRl+uxWUVvN29M5qveyXjaDDO094/qwsSc8RiYlHYt7Ii1bWkkz3P1kG0nHfG7Fd46A+GJ6R5NhmNfingd/nu9iKrNwLXK
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
steps:
|
|
||||||
- name: "gcr.io/cloud-builders/git"
|
|
||||||
args: [fetch, --tags, --depth=100]
|
|
||||||
- name: "goreleaser/goreleaser:v0.134.0"
|
|
||||||
entrypoint: /bin/sh
|
|
||||||
args: ["releasing/cloudbuild.sh", "kustomize"]
|
|
||||||
secretEnv: ['GITHUB_TOKEN']
|
|
||||||
secrets:
|
|
||||||
- kmsKeyName: projects/jregan-corp-gke-dev/locations/global/keyRings/kust-cloud-key-ring/cryptoKeys/kust-cloud-key-name
|
|
||||||
secretEnv:
|
|
||||||
GITHUB_TOKEN: CiQAwfbOkSP4tJf3ZJZMjzHaRPZ2RxiQhORZ3xxlVtpoy8631uQSUACk6WMKjtkpsRkRl+uxWUVvN29M5qveyXjaDDO094/qwsSc8RiYlHYt7Ii1bWkkz3P1kG0nHfG7Fd46A+GJ6R5NhmNfingd/nu9iKrNwLXK
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
steps:
|
|
||||||
- name: "gcr.io/cloud-builders/git"
|
|
||||||
args: [fetch, --tags, --depth=100]
|
|
||||||
- name: "goreleaser/goreleaser:v0.120.3"
|
|
||||||
entrypoint: /bin/sh
|
|
||||||
args: ["releasing/cloudbuild.sh", "pluginator"]
|
|
||||||
secretEnv: ['GITHUB_TOKEN']
|
|
||||||
secrets:
|
|
||||||
- kmsKeyName: projects/jregan-corp-gke-dev/locations/global/keyRings/kust-cloud-key-ring/cryptoKeys/kust-cloud-key-name
|
|
||||||
secretEnv:
|
|
||||||
GITHUB_TOKEN: CiQAwfbOkSP4tJf3ZJZMjzHaRPZ2RxiQhORZ3xxlVtpoy8631uQSUACk6WMKjtkpsRkRl+uxWUVvN29M5qveyXjaDDO094/qwsSc8RiYlHYt7Ii1bWkkz3P1kG0nHfG7Fd46A+GJ6R5NhmNfingd/nu9iKrNwLXK
|
|
||||||
@@ -1,67 +1,33 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# To test the release process, this script attempts to
|
# To test the release process, this script attempts
|
||||||
# use Google cloudbuild configuration to create a release
|
# to use a Google cloudbuild configuration to create
|
||||||
# locally.
|
# release artifacts locally.
|
||||||
#
|
|
||||||
# Usage: from the repo root, enter:
|
|
||||||
#
|
|
||||||
# module=kustomize
|
|
||||||
# module=pluginator # pick one
|
|
||||||
# module=api
|
|
||||||
#
|
|
||||||
# ./releasing/localbuild.sh $module
|
|
||||||
#
|
|
||||||
#
|
#
|
||||||
# See https://cloud.google.com/cloud-build/docs/build-debug-locally
|
# See https://cloud.google.com/cloud-build/docs/build-debug-locally
|
||||||
#
|
#
|
||||||
# At the time of writing,
|
# Usage: from the repo root, enter:
|
||||||
#
|
#
|
||||||
# https://pantheon.corp.google.com/cloud-build/triggers?project=jregan-corp-gke-dev
|
# ./releasing/localbuild.sh kustomize/v1.2.3
|
||||||
#
|
#
|
||||||
# has a trigger such that whenever a git tag is
|
# or some other valid tag value.
|
||||||
# applied to the kustomize repo, the cloud builder
|
|
||||||
# reads the repository-relative file
|
|
||||||
#
|
#
|
||||||
# releasing/cloudbuild_${module}.yaml
|
# IMPORTANT:
|
||||||
#
|
# The process clones the repo at the given tag,
|
||||||
# Inside this yaml file is a reference to the script
|
# so the repo must have the tag applied upstream.
|
||||||
#
|
# Either use an old tag, or disable the cloud build
|
||||||
# releasing/cloudbuild.sh
|
# trigger so that a new testing tag can be applied
|
||||||
#
|
# without setting off a cloud build.
|
||||||
# which runs goreleaser from the proper directory, with the
|
|
||||||
# proper config.
|
|
||||||
#
|
|
||||||
# The script you are reading now does something
|
|
||||||
# analogous via docker tricks.
|
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
module=$1
|
|
||||||
case "$module" in
|
|
||||||
api)
|
|
||||||
;;
|
|
||||||
kustomize)
|
|
||||||
;;
|
|
||||||
pluginator)
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Don't recognize module=$module"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
config=$(mktemp)
|
config=$(mktemp)
|
||||||
cp releasing/cloudbuild_${module}.yaml $config
|
cp releasing/cloudbuild.yaml $config
|
||||||
|
|
||||||
# Delete the cloud-builders/git step, which isn't needed
|
|
||||||
# for a local run.
|
|
||||||
sed -i '2,3d' $config
|
|
||||||
|
|
||||||
# Add the --snapshot flag to suppress the
|
# Add the --snapshot flag to suppress the
|
||||||
# github release and leave the build output
|
# github release and leave the build output
|
||||||
# in the kustomize/dist directory.
|
# in the kustomize/dist directory.
|
||||||
sed -i 's|"\]$|", "--snapshot"]|' $config
|
sed -i "s|# - '--snapshot|- '--snapshot|" $config
|
||||||
|
|
||||||
echo "Executing cloud-build-local with:"
|
echo "Executing cloud-build-local with:"
|
||||||
echo "========================="
|
echo "========================="
|
||||||
@@ -70,10 +36,12 @@ echo "========================="
|
|||||||
|
|
||||||
cloud-build-local \
|
cloud-build-local \
|
||||||
--config=$config \
|
--config=$config \
|
||||||
--bind-mount-source \
|
--substitutions=TAG_NAME=$1 \
|
||||||
--dryrun=false \
|
--dryrun=false \
|
||||||
.
|
.
|
||||||
|
|
||||||
|
# --bind-mount-source \
|
||||||
|
|
||||||
echo " "
|
echo " "
|
||||||
echo "Result of local build:"
|
echo "Result of local build:"
|
||||||
echo "##########################################"
|
echo "##########################################"
|
||||||
|
|||||||
Reference in New Issue
Block a user