github.com/cilium/cilium@v1.16.2/test/provision/container-images.sh (about) 1 #!/usr/bin/env bash 2 3 function check_img_list { 4 local imgs=$@ 5 for img in $imgs ; do 6 #fmt_img=$img 7 fmt_img=$(echo $img | sed -e 's/.*docker.io\///g' | sed -e 's/library\///g') 8 #echo "checking if $img is cached..." 9 IMG_EXISTS=$(docker images $fmt_img | wc -l) 10 if [[ "$IMG_EXISTS" != "2" ]] ; then 11 #echo "*******************************" 12 echo -e "not cached in VM: \t$img" 13 echo -e "pulling: \t\t$img" 14 case $K8S_VERSION in 15 "1.16"|"1.17"|"1.18"|"1.19"|"1.20"|"1.21"|"1.22"|"1.23") 16 docker pull $img --quiet & 17 ;; 18 *) 19 sudo ctr images pull "${img}" >/dev/null & 20 ;; 21 esac 22 #echo "*******************************" 23 else 24 echo -e "already cached: \t$img" 25 fi 26 done 27 } 28 29 function test_images { 30 echo "Downloading all container images needed for tests" 31 # Filter out just image names. 32 # grep's -I ignores binary files, -no-filename doesn't print filenames 33 # sed's -n does not print non-matching lines and the `#p` prints only 34 # matching groups. `#` is used as the sed delimiter to avoid escaping `/` in 35 # the regex. 36 DOCKER_IMAGES=$(grep -rI --no-filename "docker.io" . | sed -nEe 's#.*(docker.io/[-_a-zA-Z0-9]+/[-_a-zA-Z0-9]+:[-_.a-zA-Z0-9]+).*#\1#p' | sort | uniq) 37 QUAY_IMAGES=$(grep -rI --no-filename "quay.io" . | sed -nEe 's#.*(quay.io/[-_a-zA-Z0-9]+/[-_a-zA-Z0-9]+:[-_.a-zA-Z0-9]+).*#\1#p' | sort | uniq) 38 39 check_img_list $DOCKER_IMAGES 40 check_img_list $QUAY_IMAGES 41 42 for p in `jobs -p`; do 43 wait $p 44 done 45 } 46 47 function cilium_images { 48 echo "Downloading all images needed to build cilium" 49 CILIUM_IMGS=$(grep -rI --no-filename "quay.io" images/*/Dockerfile | sed -nEe 's#.*(quay.io/[-_a-zA-Z0-9]+/[-_a-zA-Z0-9]+:[-_.a-zA-Z0-9]+)[^-_.a-zA-Z0-9].*#\1#p' | sort | uniq) 50 51 check_img_list $CILIUM_IMGS 52 for p in `jobs -p`; do 53 wait $p 54 done 55 } 56 57 if [ $# -lt 2 ]; then 58 echo "Usage: $0 <function-name> <path to root of cilium repository>" 59 exit 1 60 fi 61 62 OLDDIR=$PWD 63 cd $2 64 65 trap "cd $OLDDIR" EXIT 66 67 $1