|
|
@ -352,14 +352,9 @@ 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 |
|
|
|
local image="$1" |
|
|
|
image_id=$(docker inspect "$image" --format='{{.Id}}') || return 1 |
|
|
|
echo "$image_id" | tee "$cache_file" |
|
|
|
echo "$image_id" # | tee "$cache_file" |
|
|
|
} |
|
|
|
export -f docker_image_id |
|
|
|
|
|
|
@ -407,6 +402,53 @@ cached_cmd_on_base_image() { |
|
|
|
export -f cached_cmd_on_base_image |
|
|
|
|
|
|
|
|
|
|
|
docker_update() { |
|
|
|
## YYY: warning, we a storing important information in cache, cache can |
|
|
|
## be removed. |
|
|
|
|
|
|
|
## We want here to cache the last script on given service whatever that script was |
|
|
|
local service="$1" script="$2" cache_file="$CACHEDIR/$FUNCNAME.cache.$1" \ |
|
|
|
previous_base_image stored_image_id |
|
|
|
shift |
|
|
|
shift |
|
|
|
## this will build it if necessary |
|
|
|
base_image=$(service_base_docker_image "$service") || return 1 |
|
|
|
|
|
|
|
## XXXvlab: there are probably ways to avoid rebuilding that each time |
|
|
|
image_id="$(docker_image_id "$base_image")" || return 1 |
|
|
|
|
|
|
|
if [ -e "$cache_file" ]; then |
|
|
|
info "Cache file exists" |
|
|
|
read-0 previous_base_image stored_image_id < <(cat "$cache_file") |
|
|
|
info "previous: $previous_base_image" |
|
|
|
info "stored: $stored_image_id" |
|
|
|
else |
|
|
|
info "No cache file $cache_file" |
|
|
|
previous_base_image="" |
|
|
|
fi |
|
|
|
if [ "$previous_base_image" -a "$stored_image_id" == "$image_id" ]; then |
|
|
|
info "Resetting $base_image to $previous_base_image" |
|
|
|
docker tag "$previous_base_image" "$base_image" || return 1 |
|
|
|
image_id="$(docker_image_id "$base_image")" || return 1 |
|
|
|
else |
|
|
|
previous_base_image="$image_id" |
|
|
|
fi |
|
|
|
info "Updating base image: $base_image (hash: $image_id)" |
|
|
|
echo "$script" | dupd --debug -u "$base_image" -- "$@" || { |
|
|
|
err "Failed updating base image" |
|
|
|
return 1 |
|
|
|
} |
|
|
|
new_image_id="$(docker_image_id "$base_image")" |
|
|
|
[ "$new_image_id" == "$previous_base_image" ] && { |
|
|
|
err "Image was not updated correctly (same id)." |
|
|
|
return 1 |
|
|
|
} |
|
|
|
printf "%s\0" "$previous_base_image" "$new_image_id" > "$cache_file" |
|
|
|
info "Wrote cache file $cache_file" |
|
|
|
} |
|
|
|
export -f docker_update |
|
|
|
|
|
|
|
|
|
|
|
image_exposed_ports_0() { |
|
|
|
local image="$1" |
|
|
|
docker inspect --format='{{range $p, $conf := .Config.ExposedPorts}}{{$p}}{{"\x00"}}{{end}}' "$image" |
|
|
|