-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrancher-save-images-v2.11.3.sh
More file actions
71 lines (65 loc) · 1.71 KB
/
rancher-save-images-v2.11.3.sh
File metadata and controls
71 lines (65 loc) · 1.71 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
#!/bin/bash
list="rancher-images.txt"
images="rancher-images.tar.gz"
source_registry=""
usage () {
echo "USAGE: $0 [--image-list rancher-images.txt] [--images rancher-images.tar.gz]"
echo " [-s|--source-registry] source registry to pull images from in registry:port format."
echo " [-l|--image-list path] text file with list of images; one image per line."
echo " [-i|--images path] tar.gz generated by docker save."
echo " [-h|--help] Usage message"
}
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-i|--images)
images="$2"
shift # past argument
shift # past value
;;
-l|--image-list)
list="$2"
shift # past argument
shift # past value
;;
-s|--source-registry)
source_registry="$2"
shift # past argument
shift # past value
;;
-h|--help)
help="true"
shift
;;
*)
usage
exit 1
;;
esac
done
if [[ $help ]]; then
usage
exit 0
fi
source_registry="${source_registry%/}"
if [ ! -z "${source_registry}" ]; then
source_registry="${source_registry}/"
fi
pulled=""
while IFS= read -r i; do
[ -z "${i}" ] && continue
i="${source_registry}${i}"
if docker pull "${i}" > /dev/null 2>&1; then
echo "Image pull success: ${i}"
pulled="${pulled} ${i}"
else
if docker inspect "${i}" > /dev/null 2>&1; then
pulled="${pulled} ${i}"
else
echo "Image pull failed: ${i}"
fi
fi
done < "${list}"
echo "Creating ${images} with $(echo ${pulled} | wc -w | tr -d '[:space:]') images"
docker save $(echo ${pulled}) | gzip --stdout > ${images}