Browse Source

chg: dev: ``cached_cmd_on_base_image`` is now cached through sessions.

hostresources
Valentin Lab 6 years ago
parent
commit
90994d3b91
  1. 37
      bin/compose-core

37
bin/compose-core

@ -343,6 +343,35 @@ docker_has_image() {
export -f 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() { cmd_on_base_image() {
local service="$1" base_image local service="$1" base_image
shift shift
@ -353,14 +382,18 @@ export -f cmd_on_base_image
cached_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 shift
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)" # debug "$FUNCNAME: cache hit ($*)"
quick_cat_stdin < "$cache_file" quick_cat_stdin < "$cache_file"
return 0 return 0
fi 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" echo "$result" | tee "$cache_file"
} }
export -f cached_cmd_on_base_image export -f cached_cmd_on_base_image

Loading…
Cancel
Save