Created
December 14, 2021 21:17
-
-
Save jamesandariese/3c85b8cf31a6891b6bc410f986e429ad to your computer and use it in GitHub Desktop.
make rootfs tarball for wsl or other purposes from a frozen docker image export
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### expects gzip, jq, and tar | |
### converts an image downloaded with the moby image download script into a rootfs.tar.gz file. | |
### get the moby script from https://github.com/moby/moby/blob/master/contrib/download-frozen-image-v2.sh | |
set -x | |
ROOT="$1" | |
if [ x"$ROOT" = x ];then | |
echo "please provide a root as arg 1" | |
exit 1 | |
fi | |
find_child_image_with_parent() { | |
if [ x"$1" = x -o x"$1" = xnull ];then | |
p=null | |
else | |
p='"'"$1"'"' | |
fi | |
jq -r --argjson p "$p" '.|select(.parent == $p)|.id' "$ROOT"/????????????????????????????????????????????????????????????????/json | |
} | |
TMPROOT="$ROOT/.$$-tmp" | |
if [ x"${TMPROOT%/*}" = x ];then | |
echo "root can't be /" | |
exit 1 | |
fi | |
rm -rf "$TMPROOT" | |
mkdir -p "$TMPROOT" | |
trap "rm -rf \"$TMPROOT\"" EXIT | |
P=null | |
while true;do | |
C=`find_child_image_with_parent "$P"` | |
[ x"$C" = x ] && break | |
echo "$C" | |
gzip -dcf "$ROOT/$C/layer.tar" | (cd "$TMPROOT";tar x) | |
P="$C" | |
done | |
(cd $TMPROOT;tar zcf ../rootfs.tar.gz .) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment