forked from kubernetes/test-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·137 lines (116 loc) · 3.65 KB
/
install.sh
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
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
if [[ $# -lt 6 ]]; then
echo "Usage: $(basename "$0") <gcp-project-id> <pool-name> <workers:200> <diskgb:600> <machine:n1-standard-2> <bot ...>" >&2
exit 1
fi
# Note: this currently requires your project to be added to a private list
# Contact fejta on #sig-testing or #prow on kubernetes slack to get on the
# list
# More info: https://cloud.google.com/remote-build-execution/docs/overview
proj=$1
pool=$2
workers=$3
disk=$4
machine=$5
shift 5
users=()
groups=()
bots=(
"$@"
)
log() {
(
set -o xtrace
"$@"
)
}
log gcloud services enable remotebuildexecution.googleapis.com "--project=$proj"
check_instance=(
gcloud alpha remote-build-execution instances describe default_instance "--project=$proj"
)
check_pools=(
gcloud alpha remote-build-execution worker-pools describe "$pool" "--project=$proj" --instance=default_instance
)
if ! "${check_instance[@]}" 2>/dev/null; then
log gcloud alpha remote-build-execution instances create \
default_instance \
"--project=$proj"
fi
if [[ -z $pool ]]; then
echo "Existing pools:" >&2
for i in $(gcloud alpha remote-build-execution worker-pools list \
"--project=$proj" \
--instance=default_instance \
--format='value(name)'); do
echo " $(basename "$i")" >&2
done
echo "Usage: $0 $1 <pool>" >&2
exit 1
fi
if ! "${check_pools[@]}" 2>/dev/null; then
log gcloud alpha remote-build-execution worker-pools create \
"$pool" \
"--project=$proj" \
--instance=default_instance \
"--worker-count=$workers" \
"--disk-size=$disk" \
"--machine-type=$machine"
else
log gcloud alpha remote-build-execution worker-pools update \
"$pool" \
"--project=$proj" \
--instance=default_instance \
"--worker-count=$workers" \
"--disk-size=$disk" \
"--machine-type=$machine"
fi
# https://cloud.google.com/remote-build-execution/docs/modify-worker-pool
echo "Update remote processing power:
gcloud alpha remote-build-execution worker-pools update \\
--project='$proj' \\
--instance=default_instance \\
--worker-count='$workers' \\
--disk-size='$disk' \\
--machine-type='$machine'
"
members=()
for u in "${users[@]}"; do
members+=("--member=user:$u")
done
for g in "${groups[@]}"; do
members+=("--member=group:$g")
done
for b in "${bots[@]}"; do
members+=("--member=serviceAccount:$b")
done
if [[ "${#members[@]}" -gt 0 ]]; then
log gcloud projects add-iam-policy-binding "$proj" \
"${members[@]}" \
--role=roles/remotebuildexecution.artifactCreator >/dev/null
fi
# https://cloud.google.com/remote-build-execution/docs/access-control
echo "Grant access to users and bots:
gcloud projects add-iam-policy-binding '$proj' \\
--role=roles/remotebuildexecution.artifactCreator \\
--member=user:[email protected] \\
--member:serviceAccount:[email protected] \\
--member:group:[email protected]
"
echo "Configure your bazel environment:"
echo " $(dirname "$0")/configure.sh"