tar-images 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. set -ex
  3. INIT_DEP="rancher/os-bootstrap"
  4. SHARED_DEP="rancher/os-base"
  5. INIT_IMAGES_DST="build/images-init.tar"
  6. SYSTEM_IMAGES_DST="build/images-system.tar"
  7. USER_IMAGES_DST="build/images-user.tar"
  8. cd $(dirname $0)/..
  9. IMAGES=$(bin/host_ros c images -i build/initrd/usr/share/ros/os-config.yml)
  10. INIT_IMAGES=""
  11. SYSTEM_IMAGES=""
  12. USER_IMAGES=""
  13. for i in ${APPEND_SYSTEM_IMAGES};do
  14. IMAGES="${IMAGES} ${i}"
  15. done
  16. for i in ${IMAGES}; do
  17. echo "tar-image: pull($i)"
  18. if ! docker inspect $i >/dev/null 2>&1; then
  19. docker pull ${i}
  20. fi
  21. if [ "${i%%:*}" != "$INIT_DEP" ] ; then
  22. SYSTEM_IMAGES="$SYSTEM_IMAGES $i"
  23. fi
  24. if [ "${i%%:*}" = "$INIT_DEP" ] || [ "${i%%:*}" = "$SHARED_DEP" ] ; then
  25. INIT_IMAGES="$INIT_IMAGES $i"
  26. fi
  27. done
  28. for i in ${APPEND_USER_IMAGES}; do
  29. USER_IMAGES="${USER_IMAGES} ${i}"
  30. done
  31. echo "tar-image: SYSTEM_IMAGES=$SYSTEM_IMAGES"
  32. echo "tar-image: INIT_IMAGES=$INIT_IMAGES"
  33. echo "tar-image: USER_IMAGES=$USER_IMAGES"
  34. if [ "$COMPRESS" == "" ]; then
  35. ARCHIVE_CMD="gzip"
  36. else
  37. # system-docker can not load images which compressed by xz with a compression level of 9
  38. # decompression consumes more memory if using level 9
  39. # the default compression level for xz is 6
  40. ARCHIVE_CMD="xz -4 -e"
  41. fi
  42. docker save ${INIT_IMAGES} | ${ARCHIVE_CMD} > ${INIT_IMAGES_DST}
  43. docker save ${SYSTEM_IMAGES} | ${ARCHIVE_CMD} > ${SYSTEM_IMAGES_DST}
  44. if [ ! -z "$USER_IMAGES" ]; then
  45. docker save ${USER_IMAGES} | ${ARCHIVE_CMD} > ${USER_IMAGES_DST}
  46. fi
  47. echo "tar-images: DONE"