-
Notifications
You must be signed in to change notification settings - Fork 119
/
publish.sh
executable file
·229 lines (196 loc) · 7.77 KB
/
publish.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
#!/bin/bash
set -e
archs=(amd64 s390x)
ARCH=$(uname -m | grep -q s390x && echo s390x || echo amd64)
export KUBEVIRTCI_TAG=${KUBEVIRTCI_TAG:-$(date +"%y%m%d%H%M")-$(git rev-parse --short HEAD)}
PREV_KUBEVIRTCI_TAG=$(curl -sL https://storage.googleapis.com/kubevirt-prow/release/kubevirt/kubevirtci/latest?ignoreCache=1)
BYPASS_PMAN=${BYPASS_PMAN:-false}
PHASES=${PHASES:-k8s}
function detect_cri() {
if podman ps >/dev/null 2>&1; then echo podman; elif docker ps >/dev/null 2>&1; then echo docker; fi
}
TARGET_REPO="quay.io/kubevirtci"
TARGET_KUBEVIRT_REPO="quay.io/kubevirt"
TARGET_GIT_REMOTE="https://[email protected]/kubevirt/kubevirtci.git"
export CRI_BIN=${CRI_BIN:-$(detect_cri)}
IMAGES_TO_BUILD=()
IMAGES_TO_RETAG=()
function run_provision_manager() {
if [ "$BYPASS_PMAN" == "true" ]; then
IMAGES_TO_BUILD=($(find cluster-provision/k8s/* -maxdepth 0 -type d -printf '%f\n'))
echo "INFO: Provision manager bypassed, rebuilding all vm based providers"
echo "IMAGES_TO_BUILD: $(echo ${IMAGES_TO_BUILD[@]})"
return
fi
json_result=$(${CRI_BIN} run --rm -v $(pwd):/workdir:Z quay.io/kubevirtci/gocli provision-manager)
echo "INFO: Provision manager results: $json_result"
while IFS=":" read key value; do
if [[ "$value" == "true" ]]; then
IMAGES_TO_BUILD+=("$key")
else
IMAGES_TO_RETAG+=("$key")
fi
done < <(echo "$json_result" | jq -r 'to_entries[] | "\(.key):\(.value)"')
echo "IMAGES_TO_BUILD: ${IMAGES_TO_BUILD[@]}"
echo "IMAGES_TO_RETAG: ${IMAGES_TO_RETAG[@]}"
}
function build_gocli() {
(cd cluster-provision/gocli && make container)
if [ $ARCH == "amd64" ]; then
${CRI_BIN} tag ${TARGET_REPO}/gocli ${TARGET_REPO}/gocli:${KUBEVIRTCI_TAG}
else
${CRI_BIN} tag ${TARGET_REPO}/gocli ${TARGET_REPO}/gocli:${KUBEVIRTCI_TAG}-${ARCH}
fi
}
function build_centos9_base_image_with_deps() {
(cd cluster-provision/centos9 && ./build.sh)
IMAGE_TO_BUILD="$(find cluster-provision/k8s/* -maxdepth 0 -type d -printf '%f\n' | tail -1)"
(cd cluster-provision/k8s/${IMAGE_TO_BUILD} && ../provision.sh)
}
function build_clusters() {
for i in "${IMAGES_TO_BUILD[@]}"; do
if [ $ARCH == "amd64" ]; then
echo "INFO: building $i"
cluster-provision/gocli/build/cli provision --phases k8s cluster-provision/k8s/$i
${CRI_BIN} tag ${TARGET_REPO}/k8s-$i ${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}
cluster-provision/gocli/build/cli provision --phases k8s cluster-provision/k8s/$i --slim
${CRI_BIN} tag ${TARGET_REPO}/k8s-$i ${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}-slim
elif [[ "$ARCH" == "s390x" && ( "$i" == "1.30" || "$i" == "1.31" ) ]]; then
echo "INFO: building $i slim"
cluster-provision/gocli/build/cli provision --phases k8s cluster-provision/k8s/$i --slim
${CRI_BIN} tag ${TARGET_REPO}/k8s-$i ${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}-slim-${ARCH}
fi
done
}
function push_node_base_image() {
if [ $ARCH == "amd64" ]; then
TARGET_IMAGE="${TARGET_REPO}/centos9:${KUBEVIRTCI_TAG}"
else
TARGET_IMAGE="${TARGET_REPO}/centos9:${KUBEVIRTCI_TAG}-${ARCH}"
fi
podman tag ${TARGET_REPO}/centos9-base:latest ${TARGET_IMAGE}
echo "INFO: push $TARGET_IMAGE"
podman push ${TARGET_IMAGE}
}
function push_cluster_images() {
for i in "${IMAGES_TO_BUILD[@]}"; do
if [ $ARCH == "amd64" ]; then
echo "INFO: push $i"
TARGET_IMAGE="${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}"
podman push "$TARGET_IMAGE"
TARGET_IMAGE="${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}-slim"
podman push "$TARGET_IMAGE"
elif [[ "$ARCH" == "s390x" && ( "$i" == "1.30" || "$i" == "1.31" ) ]]; then
echo "INFO: push $i slim"
TARGET_IMAGE="${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}-slim-${ARCH}"
podman push "$TARGET_IMAGE"
fi
done
# images that the change doesn't affect can be retagged from previous tag
for i in ${IMAGES_TO_RETAG[@]}; do
if [ $ARCH == "amd64" ]; then
echo "INFO: retagging $i (previous tag $PREV_KUBEVIRTCI_TAG)"
skopeo copy "docker://${TARGET_REPO}/k8s-$i:${PREV_KUBEVIRTCI_TAG}" "docker://${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}"
echo "INFO: retagging $i (previous tag $PREV_KUBEVIRTCI_TAG-slim)"
skopeo copy "docker://${TARGET_REPO}/k8s-$i:${PREV_KUBEVIRTCI_TAG}-slim" "docker://${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}-slim"
elif [[ "$ARCH" == "s390x" && ( "$i" == "1.30" || "$i" == "1.31" ) ]]; then
echo "INFO: retagging $i (previous tag $PREV_KUBEVIRTCI_TAG-slim-$ARCH)"
skopeo copy "docker://${TARGET_REPO}/k8s-$i:${PREV_KUBEVIRTCI_TAG}-slim-${ARCH}" "docker://${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}-slim-${ARCH}"
fi
done
}
function push_gocli() {
echo "INFO: push gocli for ${ARCH}"
if [ $ARCH == "amd64" ]; then
TARGET_IMAGE="${TARGET_REPO}/gocli:${KUBEVIRTCI_TAG}"
else
TARGET_IMAGE="${TARGET_REPO}/gocli:${KUBEVIRTCI_TAG}-${ARCH}"
fi
podman push "$TARGET_IMAGE"
}
function publish_node_base_image() {
build_centos9_base_image_with_deps
push_node_base_image
}
function publish_clusters() {
build_clusters
push_cluster_images
}
function build_alpine_container_disk() {
echo "INFO: build alpine container disk"
(cd cluster-provision/images/vm-image-builder && ./create-containerdisk.sh alpine-cloud-init)
${CRI_BIN} tag alpine-cloud-init:devel ${TARGET_REPO}/alpine-with-test-tooling-container-disk:${KUBEVIRTCI_TAG}
${CRI_BIN} tag alpine-cloud-init:devel ${TARGET_KUBEVIRT_REPO}/alpine-with-test-tooling-container-disk:devel
}
function push_alpine_container_disk() {
echo "INFO: push alpine container disk"
TARGET_IMAGE="${TARGET_REPO}/alpine-with-test-tooling-container-disk:${KUBEVIRTCI_TAG}"
podman push $TARGET_IMAGE
TARGET_KUBEVIRT_IMAGE="${TARGET_KUBEVIRT_REPO}/alpine-with-test-tooling-container-disk:devel"
podman push $TARGET_KUBEVIRT_IMAGE
}
function publish_alpine_container_disk() {
build_alpine_container_disk
push_alpine_container_disk
}
function create_git_tag() {
if [ "$CI" == "true" ]; then
git config user.name "kubevirt-bot"
git config user.email "[email protected]"
fi
echo "INFO: push new tag $KUBEVIRTCI_TAG"
git tag ${KUBEVIRTCI_TAG}
git push ${TARGET_GIT_REMOTE} ${KUBEVIRTCI_TAG}
}
publish_manifest() {
local cur_archs=("${archs[@]}")
local amend=""
local image_name="${1:?}"
local image_tag="${2:?}"
local full_image_name="${TARGET_REPO}/${image_name}:${image_tag}"
if [[ "$image_name" != "centos9" && "$image_name" != "gocli" && ! ( ( "$image_name" == "k8s-1.30" || "$image_name" == "k8s-1.31" ) && "$image_tag" =~ "slim" ) ]]; then
unset 'cur_archs[1]'
fi
for arch in ${cur_archs[*]};do
if [ "$arch" = "amd64" ]; then
amend+=" --amend ${TARGET_REPO}/${image_name}:${image_tag}"
else
amend+=" --amend ${TARGET_REPO}/${image_name}:${image_tag}-${arch}"
fi
done
podman manifest create ${full_image_name} ${amend}
podman manifest push ${full_image_name} "docker://${full_image_name}"
}
function main() {
if [ "$PHASES" == "linux" ]; then
publish_node_base_image
if [ $ARCH == "s390x" ]; then
publish_manifest "centos9" $KUBEVIRTCI_TAG
elif [ $ARCH == "amd64" ]; then
echo "${TARGET_REPO}/centos9:${KUBEVIRTCI_TAG}" > cluster-provision/k8s/base-image
fi
exit 0
fi
build_gocli
run_provision_manager
publish_clusters
for i in "${IMAGES_TO_BUILD[@]}"; do
if [ $ARCH == "s390x" ]; then
echo "INFO: publish manifests of $i"
publish_manifest k8s-$i $KUBEVIRTCI_TAG
publish_manifest k8s-$i ${KUBEVIRTCI_TAG}-slim
fi
done
# Currently the underlying build tool alpine-make-vm-image supports only x86_64 and aarch64
if [ $ARCH == "amd64" ]; then
publish_alpine_container_disk
fi
push_gocli
if [ $ARCH == "s390x" ]; then
publish_manifest "gocli" $KUBEVIRTCI_TAG
fi
if [ $ARCH == "amd64" ]; then
create_git_tag
fi
}
main "$@"