Skip to content

Commit 8fe37f3

Browse files
committed
add script caching images from docker-compose.yml
1 parent 139dff9 commit 8fe37f3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

load_images.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
## this simple script checks if you have docker images stored as tar archives
4+
## if so - it will load it from there, if not - it will pull and save it there
5+
## useful for circle images caching:
6+
## https://circleci.com/docs/docker#caching-docker-layers
7+
8+
cache_dir=~/cache_docker_images/
9+
mkdir -p $cache_dir
10+
for image in `cat docker-compose.yml | grep 'image:' | grep -o ' [^ ]*$'`; do
11+
filename=$( echo "$image" | sed -r 's/\//_/g' )
12+
13+
image_path="$cache_dir""$filename"".tar"
14+
15+
if [[ -e $image_path ]]; then
16+
echo "Image $image exists in $image_path, loading..."
17+
docker load -i $image_path
18+
else
19+
echo "Image $image not found, pulling..."
20+
docker pull $image
21+
echo "saving $image > $image_path"
22+
docker save $image > $image_path
23+
fi
24+
25+
done

0 commit comments

Comments
 (0)