forked from kubernetes/test-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prow-images.sh
executable file
·81 lines (73 loc) · 2.36 KB
/
prow-images.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
#!/usr/bin/env bash
# Copyright 2022 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 nounset
set -o errexit
set -o pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
cd $REPO_ROOT
source hack/build/setup-go.sh
readonly PROW_IMAGES_DEF_FILE="prow/.prow-images"
IMAGES=()
if [[ -n "${PROW_IMAGES:-}" ]]; then
# Building prow images from supplied
IFS=' ' read -ra IMAGES <<< "${PROW_IMAGES}"
else
# Building all prow images
while IFS= read -r image; do
IMAGES+=($image)
done < "$PROW_IMAGES_DEF_FILE"
fi
# overridable registry to use
KO_DOCKER_REPO="${KO_DOCKER_REPO:-}"
if [[ -z "${KO_DOCKER_REPO}" ]]; then
echo "KO_DOCKER_REPO must be provided"
exit 1
fi
export KO_DOCKER_REPO
# push or local tar?
PUSH="${PUSH:-false}"
# overridable auto-tag
TAG="${TAG:-"$(date +v%Y%m%d)-$(git describe --always --dirty)"}"
# build ko
cd 'hack/tools'
go build -o "${REPO_ROOT}/_bin/ko" github.com/google/ko
cd "${REPO_ROOT}"
echo "Images: ${IMAGES[@]}"
for image in "${IMAGES[@]}"; do
echo "Building $image"
name="$(basename "${image}")"
# gather static files if there is any
gather_static_file_script="${image}/gather-static.sh"
if [[ -f $gather_static_file_script ]]; then
source $gather_static_file_script
fi
# push or local tarball
publish_args=(--tarball=_bin/"${name}".tar --push=false)
if [[ "${PUSH}" != 'false' ]]; then
publish_args=(--push=true)
fi
# specify tag
publish_args+=(--base-import-paths --tags="${TAG}" --tags="latest" --tags="latest-root" --platform=linux/amd64)
# actually build
failed=0
(set -x; _bin/ko publish "${publish_args[@]}" ./"${image}") || failed=1
if [[ -f $gather_static_file_script ]]; then
CLEAN=true $gather_static_file_script
fi
if (( failed )); then
echo "Failed building image: ${image}"
exit 1
fi
done