Skip to content

Commit

Permalink
Inform if build information are not available (#143)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
agners authored Jun 17, 2024
1 parent 9ea8b74 commit 2904dcb
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit 2904dcb

Please sign in to comment.