package-rootfs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. set -e
  3. set -o pipefail
  4. cd $(dirname $0)/..
  5. source scripts/version
  6. BUILD=$(pwd)/build
  7. IMAGE_CACHE=${BUILD}/image-cache
  8. PREPOP_DIR=${IMAGE_CACHE}/var/lib/system-docker
  9. INITRD_DIR=${BUILD}/initrd
  10. ARTIFACTS=$(pwd)/dist/artifacts
  11. INITRD=${ARTIFACTS}/initrd
  12. mkdir -p ${ARTIFACTS} ${PREPOP_DIR}
  13. if [ "$(docker info | grep 'Storage Driver: ' | sed 's/Storage Driver: //')" != "overlay" ]; then
  14. echo Overlay storage driver is require to prepackage exploded images
  15. echo packaging images.tar instead
  16. tar czf ${ARTIFACTS}/rootfs${SUFFIX}.tar.gz --exclude lib/modules --exclude lib/firmware -C ${INITRD_DIR} .
  17. exit 0
  18. fi
  19. DFS=$(docker run -d --privileged -v /lib/modules/$(uname -r):/lib/modules/$(uname -r) ${DFS_IMAGE}${SUFFIX} ${DFS_ARGS})
  20. trap "docker rm -fv ${DFS_ARCH} ${DFS}" EXIT
  21. docker exec -i ${DFS} docker load < ${INITRD_DIR}/usr/share/ros/images.tar
  22. docker stop ${DFS}
  23. docker run --rm --volumes-from=${DFS} --entrypoint /bin/bash rancher/os-base -c "tar -c -C /var/lib/docker ./image" | tar -x -C ${PREPOP_DIR}
  24. docker run --rm --volumes-from=${DFS} --entrypoint /bin/bash rancher/os-base -c "tar -c -C /var/lib/docker ./overlay" | tar -x -C ${PREPOP_DIR}
  25. tar -cf ${ARTIFACTS}/rootfs${SUFFIX}.tar --exclude usr/share/ros/images.tar --exclude lib/modules --exclude lib/firmware -C ${INITRD_DIR} .
  26. tar -rf ${ARTIFACTS}/rootfs${SUFFIX}.tar -C ${IMAGE_CACHE} .
  27. rm -f ${ARTIFACTS}/rootfs${SUFFIX}.tar.gz
  28. gzip ${ARTIFACTS}/rootfs${SUFFIX}.tar