forked from linkerd/linkerd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-pr
executable file
·155 lines (132 loc) · 3.88 KB
/
install-pr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env bash
### Install PR ###
#
# This script takes a GitHub pull request number as an argument and loads the
# images into a local Kubernetes cluster. It then installs the CLI so that it
# can be used to install with any specific configuration needed.
#
# It requires a GitHub personal access token in the $GITHUB_TOKEN environment
# variable.
set -eo pipefail
cluster=""
is_kind=false
is_k3d=false
# Read script flags and arguments
while :
do
case $1 in
-h|--help)
echo "Install Linkerd with the changes made in a GitHub Pull Request."
echo ""
echo "Usage:"
echo " --cluster: The name of the cluster to use"
echo ""
echo " # Install Linkerd into the current cluster"
echo " bin/install-pr 1234"
echo ""
echo " # Install Linkerd into the current k3d cluster"
echo " bin/install-pr --k3d 1234"
echo ""
echo " # Install Linkerd into the current KinD cluster"
echo " bin/install-pr --kind 1234"
echo ""
echo " # Install Linkerd into the 'pr-1234' k3d cluster"
echo " bin/install-pr --k3d --cluster pr-1234 1234"
exit 0
;;
--cluster)
cluster=$2
shift
;;
--kind)
is_kind=true
;;
--k3d)
is_k3d=true
;;
-?*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
*)
break
esac
shift
done
pr=$1
if [ -z "$pr" ]
then
echo "Error: ${0##*/} accepts 1 argument" >&2
echo "Usage:" >&2
echo " ${0##*/} ####" >&2
exit 1
fi
if [ -z "$GITHUB_TOKEN" ]
then
# shellcheck disable=SC2016
echo 'Error: Generate a personal access token at https://github.com/settings/tokens and set it in the $GITHUB_TOKEN env var'
exit 1
fi
linkerd2_pulls_url="https://api.github.com/repos/linkerd/linkerd2/pulls"
linkerd2_integration_url="https://api.github.com/repos/linkerd/linkerd2/actions/workflows/integration_tests.yml"
# Get the URL for downloading the artifacts archive
auth="Authorization: token $GITHUB_TOKEN"
branch=$(curl -sL -H "$auth" "$linkerd2_pulls_url/$pr" | jq -r '.head.ref')
artifacts=$(curl -sL -H "$auth" "$linkerd2_integration_url/runs?branch=$branch" | jq -r '.workflow_runs[0].artifacts_url')
archive=$(curl -sL -H "$auth" "$artifacts" | jq -r '.artifacts[0].archive_download_url')
bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd )
dir=$(mktemp -d -t "linkerd-pr-$pr.XXXXXXXXXX")
# shellcheck source=_docker.sh
. "$bindir"/_docker.sh
cd "$dir" || exit
echo "### Downloading images ###"
curl -L -o archive.zip -H "$auth" "$archive"
unzip -o archive.zip -d image-archives/
echo "### Loading images into Docker ###"
image=$(docker load -i image-archives/cli-bin.tar | sed 's/Loaded image: //')
tag=$(echo "$image" | cut -f 2 -d ":")
for image in "${DOCKER_IMAGES[@]}"
do
docker load -i "image-archives/$image.tar"
done
if [ "$is_kind" = true ] || [ "$is_k3d" = true ]
then
# When importing into k3d or kind, the images must be renamed to use the
# proper registry so that users don't have to change the default install
# output.
docker_rename_registry "$tag" "ghcr.io/linkerd" "cr.l5d.io/linkerd"
distro="k3d"
if [ "$is_kind" = true ]
then
distro="kind"
fi
export TAG="$tag"
"$bindir"/image-load --"$distro" --cluster "$cluster"
else
# The images were built with the ghcr.io registry so when pushing to a
# remote cluster for testing, no renaming needs to occur.
for image in "${DOCKER_IMAGES[@]}"
do
docker push "$image"
done
fi
cd -
rm -rf "$dir"
case $(uname) in
Darwin)
platform="darwin"
;;
Linux)
platform="linux"
;;
*)
platform="windows"
;;
esac
# Images created based off PRs use the ghcr.io registry, so override the
# default here when pulling the binary.
export DOCKER_REGISTRY=ghcr.io/linkerd
linkerd=$("$bindir"/docker-pull-binaries "$tag" | awk -v platform=$platform '$0 ~ platform')
echo ""
echo "Linkerd CLI available:"
echo "$linkerd"