forked from kubernetes/release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8s-rapture.sh
executable file
·247 lines (210 loc) · 7.42 KB
/
k8s-rapture.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/env bash
# Copyright 2020 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.
# This is a temporary stopgap to add some automation to the Googler-only process.
# In the long term, we want to develop a different process that non-Googlers
# can perform.
#
# It builds and pushes both Debian and Red Hat packages, pausing for
# confirmation before promoting each repo to stable. It always sets the
# package revision to 0, so you should only use it for a new minor or patch
# release for which packages have never been pushed.
#
# This is based on a copy of the existing script from ex-Googler
# [email protected], with some modifications to reduce the number of manual
# prompts, which can potentially derail a release if the wrong option is chosen
# by the user accidentally.
#
# Example usage:
# git clone https://github.com/kubernetes/release.git
# cd release
# k8s-rapture.sh 1.6.12
cat <<EOF >&2
##### WARNING ##################################################################
# This script is an early experiment. Use at your own risk!
# In particular, I have no idea whether it will properly detect errors at
# various stages. Take care to check all results for sanity.
################################################################################
EOF
set -o errexit
set -o nounset
set -o pipefail
log() {
echo "$*" >&2
}
fatal() {
log "FATAL: $*"
exit 1
}
# TODO(mehdy) checks:
# 1. Check if on release repo
# 2. Check for prod access
# 3. Check if release repo up to date
# 4. Check if rpm and any other required command exists
# TODO(mehdy): Restructure the script into three phases:
# P1 - Building RPMs and DEBs
# P2 - Signing all packages
# P3 - Publish them.
# TODO(mehdy): Make the script rerunnable at any phase
#############################################################################
# Simple yes/no prompt
#
# @optparam default -n(default)/-y/-e (default to n, y or make (e)xplicit)
# @param message
askyorn () {
local yorn=z
local def=n
local msg="y/N"
case $1 in
-y) # yes default
def="y" msg="Y/n"
shift
;;
-e) # Explicit
def="" msg="y/n"
shift
;;
-n) shift
;;
esac
while [[ $yorn != [yYnN] ]]; do
echo -n "$*? ($msg): "
read yorn
: ${yorn:=$def}
done
# Final test to set return code
[[ $yorn == [yY] ]]
}
[[ -n "$1" ]] || fatal "no version specified"
askyorn "Continue RPMs and DEBs release for $1" || exit 1
version="$1"
release_dir="$(pwd)"
### Debian
publish_debs() {
local distro=xenial
log "Clearing output dir"
rm -rf packages/deb/bin
cd packages/deb
log "Setting all Revisions to \"00\" in build.go"
sed -i -r -e 's/\b(Revision:\s*)"[0-9]{2}"/\1"00"/' build.go
log "Building debs for Kubernetes v${version}"
./jenkins.sh --kube-version $version --distros $distro
log "Changing file owner from root to ${USER}"
sudo chown -R "${USER}" bin
log "Removing local debs that already exist on the server"
local debpath
for debfile in $(rapture --universe=cloud-apt listrepo "kubernetes-${distro}" | sed -r -e 's/^(\S+) (\S+) \[(\S+)\] .*$/\1_\2_\3.deb/'); do
debpath="bin/stable/${distro}/${debfile}"
if [[ -f "${debpath}" ]]; then
log "Removing ${debpath}"
rm "${debpath}"
fi
done
if ls bin/stable/${distro}/*.deb 1> /dev/null 2>&1;
then
log "Pushing debs to kubernetes-${distro}-unstable"
rapture --universe=cloud-apt addpkg -keepold "kubernetes-${distro}" bin/stable/${distro}/*.deb
else
log "No debs found in bin/stable/${distro}/*.deb, skipping rapture addpkg"
fi
log "Packages in kubernetes-${distro}-unstable:"
rapture --universe=cloud-apt listrepo "kubernetes-${distro}-unstable"
local target
target=$(rapture --universe=cloud-apt showrepo "kubernetes-${distro}-unstable" | awk '/ Current indirection:/ {print $3}')
log
log "Promoting ${target} to stable"
rapture --universe=cloud-apt settag "${target}" cloud-kubernetes-release.stable:true
cd ${release_dir}
}
### Red Hat
publish_rpms() {
local distro=el7
local keyfile
local RPMDIR
log "Clearing output dir"
rm -rf packages/rpm/output
cd packages/rpm
RPMDIR="$(pwd)"
log "Setting version in kubelet.spec"
local vparts=(${version//./ })
sed -i -r \
-e "s/(%global\\s+KUBE_MAJOR\\s+)[0-9]+/\\1${vparts[0]}/" \
-e "s/(%global\\s+KUBE_MINOR\\s+)[0-9]+/\\1${vparts[1]}/" \
-e "s/(%global\\s+KUBE_PATCH\\s+)[0-9]+/\\1${vparts[2]}/" \
-e "s/(%global\\s+RPM_RELEASE\\s+)[0-9]+/\\10/" \
kubelet.spec
log "Building RPMs for Kubernetes v${version}"
./docker-build.sh
log "Signing RPMs"
pushd /google/src/head/depot/google3/cloud/cluster/guest/cloud_rapture/rpmsign
for rpmfile in $(find "${RPMDIR}" -name '*.rpm'); do
./sign.sh "${rpmfile}"
done
popd
log "Importing key to check RPM signatures"
pushd /tmp
keyfile="$(mktemp)"
curl -sL https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg > ${keyfile}
rpm --import "${keyfile}"
rm "${keyfile}"
popd
log "Checking RPM signatures"
local check
for rpmfile in $(find "${RPMDIR}" -name '*.rpm'); do
check="$(rpm -Kv "${rpmfile}")"
echo "${check}"
echo "${check}" | egrep -q '\bOK\b' || fatal "RPM signing failed; check output doesn't contain OK: ${check}"
echo "${check}" | egrep -q '\bV4 RSA/SHA512 Signature\b' || fatal "RPM signing failed; check output doesn't contain pgp: ${check}"
echo "${check}" | egrep -vq 'NOT OK' || fatal "RPM signing failed; check output contains NOT OK: ${check}"
echo "${check}" | egrep -vq 'MISSING KEYS' || fatal "RPM signing failed; check output contains MISSING KEYS: ${check}"
done
log "Removing local RPMs that already exist on the server"
local archlist=()
local arch
local rpmfile
local rpmpath
mapfile -t archlist < <(find output/* -maxdepth 0 -type d -printf "%f\n")
for arch in "${archlist[@]}"; do
for rpmfile in $(rapture --universe=cloud-yum listrepo "kubernetes-${distro}-${arch}" | sed -r -e 's/^(\S+) [0-9]+:(\S+) \[(\S+)\] .*$/\1-\2.\3.rpm/'); do
rpmpath="output/${arch}/${rpmfile}"
if [[ -f "${rpmpath}" ]]; then
log "Removing ${rpmpath}"
rm "${rpmpath}"
fi
done
done
local repo
for arch in "${archlist[@]}"; do
repo="kubernetes-${distro}-${arch}"
if ls output/${arch}/*.rpm 1> /dev/null 2>&1;
then
log "Pushing RPMs to ${repo}-unstable"
rapture --universe=cloud-yum addpkg -keepold "${repo}" output/${arch}/*.rpm
else
log "No RPMs found in output/${arch}/ skipping rapture addpkg"
fi
done
local target
for arch in "${archlist[@]}"; do
repo="kubernetes-${distro}-${arch}"
log "Packages in ${repo}-unstable:"
rapture --universe=cloud-yum listrepo "${repo}-unstable"
target=$(rapture --universe=cloud-yum showrepo "${repo}-unstable" | awk '/ Current indirection:/ {print $3}')
log
log "Promoting ${target} to stable ${repo}"
rapture --universe=cloud-yum settag "${target}" cloud-kubernetes-release.stable:true
done
}
publish_debs
publish_rpms