Browse Source

fix: docker base image was wrong in image building charms having more than one layer.

test
Valentin Lab 6 years ago
parent
commit
9b822d0b3e
  1. 35
      bin/compose-core

35
bin/compose-core

@ -1098,22 +1098,31 @@ service_base_docker_image() {
}
service_image=$(echo "$service_def" | shyaml get-value image 2>/dev/null)
if [ "$?" != 0 ]; 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
service_dockerfile="${service_build}"/Dockerfile
if ! [ -e "$service_dockerfile" ]; then
err "No Dockerfile found in '$service_dockerfile' location."
return 1
fi
## 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}_${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
grep '^FROM' "$service_dockerfile" | xargs printf "%s " | cut -f 2 -d " "
docker build "$service_build" -t "${project}_${service}" >&2 || {
err "Failed to build image for ${DARKYELLOW}$service${NORMAL}."
return 1
}
fi
printf "%s" "${project}_${service}"
else
echo "$service_image"
printf "%s" "${service_image}"
fi | tee "$cache_file"
if [ "${PIPESTATUS[0]}" != 0 ]; then
rm "$cache_file"
return 1
fi
}
export -f service_base_docker_image

Loading…
Cancel
Save