Repository navigation
Expand file tree
/
Copy pathimage-load
More file actions
executable file
·152 lines (138 loc) · 3.6 KB
/
Copy pathimage-load
File metadata and controls
executable file
·152 lines (138 loc) · 3.6 KB
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
#!/usr/bin/env bash
set -eo pipefail
kind=""
k3d=""
cluster=""
archive=""
preload=""
images=()
bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd )
# shellcheck source=_docker.sh
. "$bindir"/_docker.sh
usage() {
printf "Load into KinD/k3d the referred Linkerd images. If no images are specified all of them are loaded (%s)\n" "${DOCKER_IMAGES[*]}"
echo ""
echo "Usage:"
echo " bin/image-load [--kind] [--k3d] [--cluster name] [--preload] [--archive] [image] [image]..."
echo ""
echo "Examples:"
echo ""
echo " # Load all the images from the local docker instance into KinD"
echo " bin/image-load"
echo ""
echo " # Load only the proxy and controller images into k3d"
echo " bin/image-load --k3d proxy controller"
echo ""
echo " # Load all the images from tar files located under the 'image-archives' directory into k3d"
echo " bin/image-load --k3d --archive"
echo ""
echo "Available Commands:"
echo " --cluster: target cluster name (defaults to 'k3s-default' under k3d, and 'kind' under KinD)."
echo " --kind: use a KinD cluster (default)."
echo " --k3d: use a k3d cluster."
echo " --preload: pull the docker images from a public registry prior to loading them into the cluster, which appears to be faster than having k3d pulling them itself."
echo " --archive: load the images from local .tar files in the current directory."
}
while :
do
case ${1:-} in
-h|--help)
usage
exit 0
;;
--cluster)
cluster=$2
shift
;;
--kind)
kind=1
;;
--k3d)
k3d=1
;;
--preload)
preload=1
;;
--archive)
archive=1
;;
*)
if [ -z "${1:-}" ]; then
break
fi
if echo "$1" | grep -q '^-.*' ; then
echo "Unexpected flag: $1" >&2
usage
exit 1
fi
images+=("$1")
esac
shift
done
if [ ${#images[@]} -eq 0 ]; then
images=("${DOCKER_IMAGES[@]}")
fi
bindir=$( cd "${0%/*}" && pwd )
if [ -n "$k3d" ]; then
if [ -n "$kind" ]; then
echo $k3d
echo "Error: --kind and --k3d can't be used simultaneously" >&2
usage
exit 1
fi
if [ -z "$cluster" ]; then
cluster="k3s-default"
fi
bin="$bindir"/k3d
image_sub_cmd=(image import -c "$cluster")
else
kind=1
bin="$bindir"/kind
if [ -z "$cluster" ]; then
cluster="kind"
fi
if [ $archive ]; then
image_sub_cmd=(load image-archive --name "$cluster")
else
image_sub_cmd=(load docker-image --name "$cluster")
fi
fi
if [ -z "$archive" ]; then
# shellcheck source=_tag.sh
. "$bindir"/_tag.sh
# shellcheck source=_docker.sh
. "$bindir"/_docker.sh
TAG=${TAG:-$(head_root_tag)}
fi
# This is really to load the binary synchronously, before
# the parallel executions below attempt doing so
"$bin" version
rm -f load_fail
for i in "${!images[@]}"; do
if [ $archive ]; then
param="image-archives/${images[$i]}.tar"
else
param="$DOCKER_REGISTRY/${images[$i]}:$TAG"
if [ $preload ]; then
"$bindir"/docker pull -q "$param" || (echo "Error pulling image $param"; touch load_fail) &
fi
fi
if [ -n "$kind" ]; then
printf 'Importing %s...\n' "${images[$i]}"
"$bin" "${image_sub_cmd[@]}" "${param[@]}" || touch load_fail &
else
# "k3d image import" commands don't behave well when parallelized
# but all the images can be loaded in a single invocation
images[$i]=$param
fi
done
wait < <(jobs -p)
if [ -f load_fail ]; then
echo "Loading docker images into the cluster failed."
rm load_fail
exit 1
fi
if [ -n "$k3d" ]; then
printf 'Importing %s...\n' "${images[@]}"
"$bin" "${image_sub_cmd[@]}" "${images[@]}"
fi