From 2904dcb53165920f0e9d0f0be6164af240f827b7 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Mon, 17 Jun 2024 19:27:49 +0200 Subject: [PATCH] Inform if build information are not available (#143) * Warn if build information are not available * Add informational log for add-ons In most cases the user provides a build metadata file. Write an informational log when the default is being used. --- builder.sh | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/builder.sh b/builder.sh index 1b3115f..f4f268a 100755 --- a/builder.sh +++ b/builder.sh @@ -431,14 +431,17 @@ function build_base() { local docker_tags=() # Read build.json - if bashio::fs.file_exists "/tmp/build_config/build.json"; then - build_from="$(jq --raw-output ".build_from.${build_arch} // empty" "/tmp/build_config/build.json")" - args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")" - labels="$(jq --raw-output '.labels // empty | keys[]' "/tmp/build_config/build.json")" - raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/build.json")" - shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")" + if ! bashio::fs.file_exists "/tmp/build_config/build.json"; then + bashio::log.error "Build information not found!" + return 1 fi + build_from="$(jq --raw-output ".build_from.${build_arch} // empty" "/tmp/build_config/build.json")" + args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")" + labels="$(jq --raw-output '.labels // empty | keys[]' "/tmp/build_config/build.json")" + raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/build.json")" + shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")" + # Set defaults build things if ! bashio::var.has_value "${build_from}"; then bashio::log.error "${build_arch} not supported for this build" @@ -522,6 +525,7 @@ function build_addon() { # Set defaults build things if [ -z "$build_from" ]; then + bashio::log.info "No build information or from not provided. Using default base image." build_from="homeassistant/${build_arch}-base:latest" fi @@ -595,14 +599,17 @@ function build_generic() { local docker_tags=() # Read build.json - if bashio::fs.file_exists "/tmp/build_config/build.json"; then - build_from="$(jq --raw-output ".build_from.$build_arch // empty" "/tmp/build_config/build.json")" - args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")" - labels="$(jq --raw-output '.labels // empty | keys[]' "/tmp/build_config/build.json")" - raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/build.json")" - shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")" + if ! bashio::fs.file_exists "/tmp/build_config/build.json"; then + bashio::log.error "Build information not found!" + return 1 fi + build_from="$(jq --raw-output ".build_from.$build_arch // empty" "/tmp/build_config/build.json")" + args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")" + labels="$(jq --raw-output '.labels // empty | keys[]' "/tmp/build_config/build.json")" + raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/build.json")" + shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")" + # Set defaults build things if ! bashio::var.has_value "$build_from"; then bashio::log.error "$build_arch not supported for this build" @@ -653,14 +660,17 @@ function build_machine() { local docker_tags=() # Read build.json - if bashio::fs.file_exists "/tmp/build_config/build.json"; then - build_from="$(jq --raw-output ".build_from.${build_arch} // empty" "/tmp/build_config/build.json")" - args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")" - labels="$(jq --raw-output '.labels // empty | keys[]' "/tmp/build_config/build.json")" - raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/build.json")" - shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")" + if ! bashio::fs.file_exists "/tmp/build_config/build.json"; then + bashio::log.error "Build information not found!" + return 1 fi + build_from="$(jq --raw-output ".build_from.${build_arch} // empty" "/tmp/build_config/build.json")" + args="$(jq --raw-output '.args // empty | keys[]' "/tmp/build_config/build.json")" + labels="$(jq --raw-output '.labels // empty | keys[]' "/tmp/build_config/build.json")" + raw_image="$(jq --raw-output '.image // empty' "/tmp/build_config/build.json")" + shadow_repository="$(jq --raw-output '.shadow_repository // empty' "/tmp/build_config/build.json")" + # Modify build_from if [[ "${build_from}" =~ :$ ]]; then build_from="${build_from}${VERSION}"