From 078efdfee000d19dfa7fa3f3ddfb6e1de08c9556 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 18 May 2022 17:57:16 +0200 Subject: [PATCH 1/2] Warn if build information are not available --- builder.sh | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/builder.sh b/builder.sh index 1b3115f..c06bb08 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" @@ -595,14 +598,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 +659,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}" From 526221e190dd051add218a69044c13239794e35a Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Mon, 10 Jun 2024 09:16:16 +0200 Subject: [PATCH 2/2] 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/builder.sh b/builder.sh index c06bb08..f4f268a 100755 --- a/builder.sh +++ b/builder.sh @@ -525,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