-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender-local-registry
executable file
·42 lines (35 loc) · 1.04 KB
/
render-local-registry
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
#!/usr/bin/env bash
LF=$'\n'
bold=$(tput bold)
normal=$(tput sgr0)
repo_image_tag='^([^/]+)(.+):(.+)'
helm='# Source: .+\.yaml'
template=$(</dev/stdin)
if ! [[ "${BASH_VERSINFO[5]}" =~ msys ]]; then
tty=/dev/tty
# Microsoft Windows is weird
elif [[ "$template" =~ $helm ]]; then
tty=/dev/console
else
tty=/dev/stderr
fi
trap 'echo "$normal" >$tty' EXIT
@() {
echo "$LF$bold$*$normal" >$tty
"$@"
}
preload() {
local image
yq -r '.spec.template.spec.containers[].image' 2>/dev/null | tr -d $'\r' | while read -r image; do
local local=localhost:5000/$image
if [[ "$local" =~ $repo_image_tag ]]; then
local version="\"${BASH_REMATCH[3]}\""
[[ $(curl -sS "${BASH_REMATCH[1]}/v2${BASH_REMATCH[2]}/tags/list") =~ $version ]] && continue
fi
[[ -n "$(docker images -q --filter=reference="$image")" ]] || @ docker pull "$image"
@ docker tag "$image" "$local"
@ docker push "$local"
done
}
preload <<<"$template" >$tty
sed -E -e 's,[[:space:]]image:[^[:alnum:]]+,&localhost:5000/,' -e '/imagePullPolicy/s/IfNotPresent/Always/' <<<"$template"