-
-
Save dirkakrid/070b11ed002a3b4f2075da737559328a to your computer and use it in GitHub Desktop.
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 | |
set -e | |
set -o pipefail | |
function list_tars { | |
ROOT=$1 | |
TAG=${2:-latest} | |
BASE=$(sed -e 's/.*{\(".*"\)}.*/\1/g' "${ROOT}/repositories" | sed 's/"//g' | awk -v RS=',' -F: '/^'${TAG}'/ {print $2}') | |
CUR=$BASE | |
while [[ -f "${ROOT}/${CUR}/json" ]]; do | |
PARENT=$(sed -e 's/.*{\(".*"\)}.*/\1/g' ${ROOT}/${CUR}/json | sed 's/"//g' | awk -v RS=',' -F: '/^parent/ {print $2}') | |
if [[ "${PARENT}" != "" ]]; then | |
echo ${PARENT} | |
fi | |
CUR=${PARENT} | |
done | tac | |
echo ${BASE} | |
} | |
[[ "$1" == "" ]] && { | |
echo "please provide docker image to squash!" | |
exit -1 | |
} | |
[[ "$2" == "" ]] && { | |
echo "please provide out folder!" | |
exit -1 | |
} | |
OUT=$2 | |
ROOT="${OUT}/.out" | |
TAG=":${3:-latest}" | |
mkdir -p "${ROOT}" | |
docker pull $1$TAG | |
docker save $1$TAG | tar -C "${ROOT}" -xf- | |
for p in $(list_tars ${ROOT} $3); do | |
f="${ROOT}/${p}/layer.tar" | |
if [[ -f "${f}" ]]; then | |
tar --numeric-owner -C "${OUT}" -xf "${f}" | |
fi | |
done | |
rm -fr "${ROOT}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment