preload.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. set -e
  3. BASE=${1:-${PRELOAD_DIR}}
  4. BASE=${BASE:-/mnt/preload}
  5. if [ "${SYSTEM_IMAGES}" = "true" ]; then
  6. docker_bin=system-docker
  7. else
  8. docker_bin=docker
  9. fi
  10. should_load() {
  11. file=${1}
  12. if [[ ${file} =~ \.done$ ]]; then echo false
  13. elif [ -f ${file} ]; then
  14. if [[ ${file} -nt ${file}.done ]]; then echo true
  15. else echo false
  16. fi
  17. else echo false
  18. fi
  19. }
  20. if [ -d ${BASE} ]; then
  21. echo Preloading docker images from ${BASE}...
  22. for file in $(ls ${BASE}); do
  23. path=${BASE}/${file}
  24. loading=$(should_load ${path})
  25. if [ ${loading} == "true" ]; then
  26. CAT="cat ${path}"
  27. if [[ ${file} =~ \.t?gz$ ]]; then CAT="${CAT} | gunzip"; fi
  28. if [[ ${file} =~ \.t?xz$ ]]; then CAT="${CAT} | unxz"; fi
  29. wait-for-docker
  30. CAT="${CAT} | ${docker_bin} load"
  31. echo loading from ${path}
  32. eval ${CAT} || :
  33. touch ${path}.done || :
  34. fi
  35. done
  36. echo Done.
  37. else
  38. echo Can not preload images from ${BASE}: not a dir or does not exist.
  39. fi