1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #!/usr/bin/env bash
set -e
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) ROOT_DIR=$(dirname "$CUR_DIR")
mkdir -p "$ROOT_DIR"/images
function save() { if [ ! -f "$1" ]; then echo "file not found: $1" exit 1 fi images=$(docker-compose -f "$1" config --images | sort -u) for image in $images; do name=${image////-} name=${name//:/_} if [ -f "$ROOT_DIR/images/$name.tar.gz" ]; then echo "-> exist $name.tar.gz, skip" continue fi docker image pull --platform linux/amd64 "$image" echo "=> save $image to $name.tar.gz" docker image save "$image" | gzip > "$ROOT_DIR/images/$name.tar.gz" done }
if [ -z "$1" ]; then files=$(find . -type f -name "docker-compose*.yaml" | sort -u) for file in $files; do echo ">> found $file" save "$file" done else save "$1" fi
|