|
|
@ -343,6 +343,35 @@ docker_has_image() { |
|
|
|
export -f docker_has_image |
|
|
|
|
|
|
|
|
|
|
|
docker_image_id() { |
|
|
|
local image="$1" image_id cache_file="$state_dir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" |
|
|
|
if [ -e "$cache_file" ]; then |
|
|
|
# debug "$FUNCNAME: cache hit ($*)" |
|
|
|
quick_cat_stdin < "$cache_file" |
|
|
|
return 0 |
|
|
|
fi |
|
|
|
image_id=$(docker inspect "$image" --format='{{.Id}}') || return 1 |
|
|
|
echo "$image_id" | tee "$cache_file" |
|
|
|
} |
|
|
|
export -f docker_image_id |
|
|
|
|
|
|
|
|
|
|
|
cached_cmd_on_image() { |
|
|
|
local image="$1" cache_file |
|
|
|
image_id=$(docker_image_id "$image") || return 1 |
|
|
|
cache_file="$CACHEDIR/$FUNCNAME.cache.$(echo "$*" | md5_compat)" |
|
|
|
if [ -e "$cache_file" ]; then |
|
|
|
# debug "$FUNCNAME: cache hit ($*)" |
|
|
|
quick_cat_stdin < "$cache_file" |
|
|
|
return 0 |
|
|
|
fi |
|
|
|
shift |
|
|
|
out=$(docker run -i --rm --entrypoint /bin/bash "$image_id" -c "$*") || return 1 |
|
|
|
echo "$out" | tee "$cache_file" |
|
|
|
} |
|
|
|
export -f cached_cmd_on_image |
|
|
|
|
|
|
|
|
|
|
|
cmd_on_base_image() { |
|
|
|
local service="$1" base_image |
|
|
|
shift |
|
|
@ -353,14 +382,18 @@ export -f cmd_on_base_image |
|
|
|
|
|
|
|
|
|
|
|
cached_cmd_on_base_image() { |
|
|
|
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" |
|
|
|
local service="$1" base_image cache_file="$state_dir/$FUNCNAME.cache.$(printf "%s\0" "$@" | md5_compat)" |
|
|
|
shift |
|
|
|
if [ -e "$cache_file" ]; then |
|
|
|
# debug "$FUNCNAME: cache hit ($*)" |
|
|
|
quick_cat_stdin < "$cache_file" |
|
|
|
return 0 |
|
|
|
fi |
|
|
|
result=$(cmd_on_base_image "$service" "$@") || return 1 |
|
|
|
base_image=$(service_base_docker_image "$service") || return 1 |
|
|
|
if ! docker_has_image "$base_image"; then |
|
|
|
docker pull "$base_image" |
|
|
|
fi |
|
|
|
result=$(cached_cmd_on_image "$base_image" "$@") || return 1 |
|
|
|
echo "$result" | tee "$cache_file" |
|
|
|
} |
|
|
|
export -f cached_cmd_on_base_image |
|
|
|