SHARE
TWEET

Untitled

a guest Aug 24th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. containers=(
  2.   docker.io/library/consul:latest
  3.   docker.io/library/vault:latest
  4.   docker.io/library/redis:alpine
  5.   docker.io/library/nginx:alpine
  6.   docker.io/library/alpine:latest
  7. )
  8.  
  9. urlencode() {
  10.     # urlencode <string>
  11.     old_lc_collate=$LC_COLLATE
  12.     LC_COLLATE=C
  13.    
  14.     local length="${#1}"
  15.     for (( i = 0; i < length; i++ )); do
  16.         local c="${1:i:1}"
  17.         case $c in
  18.             [a-zA-Z0-9.~_-]) printf "$c" ;;
  19.             *) printf '%%%02X' "'$c" ;;
  20.         esac
  21.     done
  22.    
  23.     LC_COLLATE=$old_lc_collate
  24. }
  25.  
  26. urldecode() {
  27.     # urldecode <string>
  28.  
  29.     local url_encoded="${1//+/ }"
  30.     printf '%b' "${url_encoded//%/\\x}"
  31. }
  32.  
  33. download_image_to_dir() {
  34.     local outfile=$(urlencode ${1})
  35.     local outdir="${2}"
  36.    
  37.     skopeo copy "docker://${1}" "oci-archive:${2}/${outfile}.tar"
  38. }
  39.  
  40. download_all_containers() {
  41.   local outdir="./containers"
  42.   mkdir -p "${outdir}"
  43.  
  44.   for item in "${containers[@]}"
  45.   do
  46.     download_image_to_dir "${item}" containers/
  47.   done
  48. }
  49.  
  50. upload_image_to_storage() {
  51.   local infile="${1}"
  52.   local imgname="$(urldecode $(basename "${infile}" .tar))"
  53.  
  54.   skopeo copy "oci-archive:${infile}" "containers-storage:${imgname}"
  55.    
  56. }
  57.  
  58. upload_local_containers() {
  59.   local indir="./containers"
  60.   for item in $(find "${indir}" -maxdepth 1 -name '*.tar');
  61.   do
  62.     upload_image_to_storage "${item}"
  63.   done
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top