Browse Source

fix: [compose-core] add ``build`` support again, after the cache introduced a regression

cache-relation
Valentin Lab 9 months ago
parent
commit
9655a98c41
  1. 75
      bin/compose-core

75
bin/compose-core

@ -1523,11 +1523,55 @@ cache:image:produce() {
;; ;;
build) build)
local service_build="$src" local service_build="$src"
build_opts=()
if [ "$COMPOSE_ACTION" == "build" ]; then
while read-0 arg; do
case "$arg" in
-t|--tag)
## XXXvlab: doesn't seem to be actually a valid option
if [ -n "$COMPOSE_PUSH_TO_REGISTRY" ]; then
err "You can't use -t|--tag option when pushing to a registry."
exit 1
fi
has_named_image=true
read-0 val ## should always be okay because already checked
build_opts+=("$arg" "$val")
;;
--help|-h)
docker-compose "$action" --help |
filter_docker_compose_help_message >&2
exit 0
;;
--*|-*)
if str_pattern_matches "$arg" $DC_MATCH_MULTI; then
read-0 value
build_opts+=("$arg" "$value")
shift
elif str_pattern_matches "$arg" $DC_MATCH_SINGLE; then
build_opts+=("$arg")
else
err "Unexpected error while parsing a second time the build arguments."
fi
;;
*)
## Already parsed
build_opts+=("$arg")
;;
esac
done < <(cla.normalize "${action_opts[@]}")
fi
if [ -z "$has_named_image" ]; then
build_opts+=(-t "${charm_image}")
fi
Wrap -v -d "Building ${DARKPINK}$charm${NORMAL}:$hash image" -- \ Wrap -v -d "Building ${DARKPINK}$charm${NORMAL}:$hash image" -- \
docker build "$service_build" -t "${charm_image}" >&2 || {
docker build "$service_build" -t "${charm_image}" "${build_opts[@]}" >&2 || {
err "Failed to build image '${charm_image}' for ${DARKYELLOW}$service${NORMAL}." err "Failed to build image '${charm_image}' for ${DARKYELLOW}$service${NORMAL}."
return 1 return 1
} }
if [ -n "$has_named_image" ]; then
exit 0
fi
;; ;;
*) *)
err "Unknown type '$type'." err "Unknown type '$type'."
@ -1621,7 +1665,7 @@ service_ensure_image_ready() {
.services.[\"${service_quoted}\"].image = \"${charm_image_name}:${hash}\"" \ .services.[\"${service_quoted}\"].image = \"${charm_image_name}:${hash}\"" \
"$_CURRENT_DOCKER_COMPOSE" || return 1 "$_CURRENT_DOCKER_COMPOSE" || return 1
if docker_has_image "${charm_image_name}:${hash}"; then
if [ "$COMPOSE_ACTION" != "build" ] && docker_has_image "${charm_image_name}:${hash}"; then
if [ -n "$DEBUG" ]; then if [ -n "$DEBUG" ]; then
Elt "using ${DARKPINK}$charm${NORMAL}'s image from local cache" >&2 Elt "using ${DARKPINK}$charm${NORMAL}'s image from local cache" >&2
print_status noop >&2 print_status noop >&2
@ -1634,7 +1678,7 @@ service_ensure_image_ready() {
fi fi
## Can we pull it ? Let's check on $COMPOSE_DOCKER_REGISTRY ## Can we pull it ? Let's check on $COMPOSE_DOCKER_REGISTRY
if [ -n "$COMPOSE_DOCKER_REGISTRY" ]; then
if [ "$COMPOSE_ACTION" != "build" ] && [ -n "$COMPOSE_DOCKER_REGISTRY" ]; then
img=$(cache:image:registry:get "$charm" "$hash" "$service") || { img=$(cache:image:registry:get "$charm" "$hash" "$service") || {
err "Failed to get image '$charm_image_name:$hash' from registry for ${DARKYELLOW}$service${NORMAL}." err "Failed to get image '$charm_image_name:$hash' from registry for ${DARKYELLOW}$service${NORMAL}."
return 1 return 1
@ -4750,6 +4794,8 @@ while read-0 arg; do
shift shift
done < <(cla.normalize "$@") done < <(cla.normalize "$@")
[ -n "$CACHEDIR" ] || die "No cache directory defined."
[ -d "$CACHEDIR" ] || die "Cache directory '$CACHEDIR' doesn't exists."
case "$action" in case "$action" in
cache) cache)
case "${remainder_args[0]}" in case "${remainder_args[0]}" in
@ -4758,8 +4804,6 @@ case "$action" in
exit 0 exit 0
;; ;;
clear) clear)
[ -n "$CACHEDIR" ] || die "No cache directory defined."
[ -d "$CACHEDIR" ] || die "Cache directory '$CACHEDIR' doesn't exists."
Wrap "${wrap_opts[@]}" -v -d "clear cache directory" -- rm -rf "$CACHEDIR/"* Wrap "${wrap_opts[@]}" -v -d "clear cache directory" -- rm -rf "$CACHEDIR/"*
## clear all docker caches ## clear all docker caches
@ -4911,6 +4955,9 @@ get_docker_compose "${services_args[@]}" >/dev/null || { ## precalculate variab
full_init= full_init=
case "$action" in case "$action" in
build)
full_init=true ## will actually stop after build
;;
up|run) up|run)
full_init=true full_init=true
post_hook=true post_hook=true
@ -4936,19 +4983,21 @@ case "$action" in
;; ;;
esac esac
if [ -n "$full_init" ]; then if [ -n "$full_init" ]; then
## init in order
if [[ -z "$no_init" && -z "$no_hooks" ]]; then
Section setup host resources
setup_host_resources "${services_args[@]}" || exit 1
Section "acquire charm's images"
if [[ "$action" == "build" ]] || [[ -z "$no_init" && -z "$no_hooks" ]]; then
[[ "$action" == "build" ]] || Section "acquire charm's images"
run_service_acquire_images "${services_args[@]}" || exit 1 run_service_acquire_images "${services_args[@]}" || exit 1
Feed Feed
[ "$action" == "build" ] && {
exit 0
}
Section setup host resources
setup_host_resources "${services_args[@]}" || exit 1
## init in order
Section initialisation Section initialisation
run_service_hook init "${services_args[@]}" || exit 1 run_service_hook init "${services_args[@]}" || exit 1
fi fi
## Get relations ## Get relations
if [[ -z "$no_relations" && -z "$no_hooks" ]]; then if [[ -z "$no_relations" && -z "$no_hooks" ]]; then
if [ "${#rebuild_relations_to_service[@]}" != 0 ]; then if [ "${#rebuild_relations_to_service[@]}" != 0 ]; then
@ -4975,6 +5024,8 @@ fi | log
if [ "${PIPESTATUS[0]}" != 0 ]; then if [ "${PIPESTATUS[0]}" != 0 ]; then
exit 1 exit 1
fi fi
[ "$action" == "build" ] && exit 0
if [ "$action" == "run" ] && [ "${#services_args}" != 0 ]; then if [ "$action" == "run" ] && [ "${#services_args}" != 0 ]; then
charm=$(get_service_charm "${services_args[0]}") || exit 1 charm=$(get_service_charm "${services_args[0]}") || exit 1

Loading…
Cancel
Save