Add bin/install-pr script (#4147)

# Install PR

This script takes a Github pull request number as an argument, downloads the
docker images from the pull request's artifacts, pushes them, and installs
them on your Kubernetes cluster.  Requires a Github personal access token
in the $GITHUB_TOKEN environment variable.

Signed-off-by: Alex Leong <alex@buoyant.io>
This commit is contained in:
Alex Leong 2020-03-10 10:58:03 -07:00 committed by GitHub
parent c39b698525
commit 586911e340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 71 additions and 0 deletions

71
bin/install-pr Executable file
View File

@ -0,0 +1,71 @@
#!/bin/bash
### Install PR ###
#
# This script takes a Github pull request number as an argument, downloads the
# docker images from the pull request's artifacts, pushes them, and installs
# them on your Kubernetes cluster. Requires a Github personal access token
# in the $GITHUB_TOKEN environment variable.
set -eo pipefail
pr=$1
if [ -z "$pr" ]
then
echo "usage: ${0##*/} (PR number)" >&2
exit 1
fi
if [ -z "$GITHUB_TOKEN" ]
then
# shellcheck disable=SC2016
echo 'Generate a personal access token at https://github.com/settings/tokens and set it in the $GITHUB_TOKEN env var'
exit 1
fi
auth="Authorization: token $GITHUB_TOKEN"
branch=$(curl -s -H "$auth" "https://api.github.com/repos/linkerd/linkerd2/pulls/$pr" | jq -r '.head.ref')
artifacts=$(curl -s -H "$auth" "https://api.github.com/repos/linkerd/linkerd2/actions/workflows/kind_integration.yml/runs?branch=$branch" | jq -r '.workflow_runs[0].artifacts_url')
archive_url=$(curl -s -H "$auth" "$artifacts" | jq -r '.artifacts[0].archive_download_url')
dir=$(mktemp -d -t "linkerd-pr-$pr.XXXXXXXXXX")
cd "$dir" || exit
echo "### Downloading images ###"
curl -L -o archive.zip -H "$auth" "$archive_url"
unzip -o archive.zip
echo "### Pushing images ###"
for archive in cli-bin cni-plugin controller debug grafana proxy web
do
image=$(docker load -i "$archive.tar" | sed "s/Loaded image: //")
docker push "$image"
tag=$(echo "$image" | cut -f 2 -d ":")
done
cd -
rm -rf "$dir"
linkerd=$(bin/docker-pull-binaries "$tag" | head -n 1)
echo "### Pre checks ###"
$linkerd check --pre
echo "### Installing $tag ###"
$linkerd install | kubectl apply -f -
$linkerd check
echo "### Linkerd installed. CLI available: "
echo "$linkerd"