Browse Source

new: dev: [compose-core] refactor ``service_base_docker_image()``

cache-relation
Valentin Lab 10 months ago
parent
commit
8ea4310945
  1. 45
      bin/compose-core

45
bin/compose-core

@ -1432,34 +1432,31 @@ service_base_docker_image() {
err "Could not get docker-compose service definition for $DARKYELLOW$master_service$NORMAL." err "Could not get docker-compose service definition for $DARKYELLOW$master_service$NORMAL."
return 1 return 1
} }
service_image=$(echo "$service_def" | shyaml get-value image 2>/dev/null)
if [ "$?" != 0 ]; then
## According to https://stackoverflow.com/questions/32230577 , if there's a build,
## then the builded image will get name ${project}_${service}
project=$(get_default_project_name) || return 1
image_name="${project}_${master_service}"
if ! docker_has_image "$image_name"; then
service_build=$(echo "$service_def" | shyaml get-value build 2>/dev/null)
if [ "$?" != 0 ]; then
err "Service $DARKYELLOW$service$NORMAL has no ${WHITE}image${NORMAL} nor ${WHITE}build${NORMAL} parameter."
echo "$service_def" >&2
return 1
fi
if service_image=$(echo "$service_def" | shyaml get-value image 2>/dev/null); then
printf "%s" "${service_image}" | tee "$cache_file"
return $?
fi
docker build "$service_build" -t "${image_name}" >&2 || {
err "Failed to build image '${image_name}' for ${DARKYELLOW}$service${NORMAL}."
return 1
}
fi
printf "%s" "${image_name}"
else
printf "%s" "${service_image}"
fi | tee "$cache_file"
if [ "${PIPESTATUS[0]}" != 0 ]; then
rm "$cache_file"
## According to https://stackoverflow.com/questions/32230577 , if there's a build,
## then the built image will get name ${project}_${service}
project=$(get_default_project_name) || return 1
image_name="${project}_${master_service}"
if docker_has_image "$image_name"; then
printf "%s" "${image_name}" | tee "$cache_file"
return $?
fi
if ! service_build=$(echo "$service_def" | shyaml get-value build 2>/dev/null); then
err "Service $DARKYELLOW$service$NORMAL has no ${WHITE}image${NORMAL} nor ${WHITE}build${NORMAL} parameter."
echo "$service_def" >&2
return 1 return 1
fi fi
docker build "$service_build" -t "${image_name}" >&2 || {
err "Failed to build image '${image_name}' for ${DARKYELLOW}$service${NORMAL}."
return 1
}
printf "%s" "${image_name}" | tee "$cache_file"
return $?
} }
export -f service_base_docker_image export -f service_base_docker_image

Loading…
Cancel
Save