Skip to content

Commit 49f58ce

Browse files
Fix bugs in get-components-json.include.sh and simplify get-services-json.include.sh (#628)
## Overview `get-components-json.include.sh` was unable to handle the case where a component was commented out in the `BIRDHOUSE_EXTRA_CONF_DIRS` variable. Also, it did not display custom components (i.e. those not in one of the `birhouse/*components/` directories). This also simplifies the code in both files to make it easier to maintain: - removed unnecessary variable declarations - simplify component discovery `get-components-json.include.sh` ## Changes **Non-breaking changes** - bug fix **Breaking changes** - None ## Related Issue / Discussion ## Additional Information Note that the changes here are fully backwards compatible. Even though we no longer source `read-configs.include.sh` the `read_configs` and/or `read_basic_configs` functions were never called so even if you had another script that called these scripts without first reading in the relevant configuration variables, it would already be failing anyway (since neither script would have loaded the correct variables). ## CI Operations <!-- The test suite can be run using a different DACCS config with ``birdhouse_daccs_configs_branch: branch_name`` in the PR description. To globally skip the test suite regardless of the commit message use ``birdhouse_skip_ci`` set to ``true`` in the PR description. Using ``[<cmd>]`` (with the brackets) where ``<cmd> = skip ci`` in the commit message will override ``birdhouse_skip_ci`` from the PR description. Such commit command can be used to override the PR description behavior for a specific commit update. However, a commit message cannot 'force run' a PR which the description turns off the CI. To run the CI, the PR should instead be updated with a ``true`` value, and a running message can be posted in following PR comments to trigger tests once again. --> birdhouse_daccs_configs_branch: master birdhouse_skip_ci: false
2 parents 3f2b8cb + 3d0b8d2 commit 49f58ce

File tree

3 files changed

+22
-65
lines changed

3 files changed

+22
-65
lines changed

CHANGES.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@
1515
[Unreleased](https://github.com/bird-house/birdhouse-deploy/tree/master) (latest)
1616
------------------------------------------------------------------------------------------------------------------
1717

18-
[//]: # (list changes here, using '-' for each new entry, remove this when items are added)
18+
## Fixes
19+
20+
- Fix bugs in `get-components-json.include.sh` and simplify `get-services-json.include.sh`
21+
22+
`get-components-json.include.sh` was unable to handle the case where a component was commented out in
23+
the `BIRDHOUSE_EXTRA_CONF_DIRS` variable.
24+
25+
This also simplifies the code in both files to make it easier to maintain:
26+
27+
- removed unnecessary variable declarations
28+
- simplify component discovery `get-components-json.include.sh`
1929

2030
[2.20.2](https://github.com/bird-house/birdhouse-deploy/tree/2.20.2) (2026-01-05)
2131
------------------------------------------------------------------------------------------------------------------

birdhouse/scripts/get-components-json.include.sh

Lines changed: 11 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,59 +17,14 @@
1717
# }
1818
#
1919

20-
THIS_FILE="$(readlink -f "$0" || realpath "$0")"
21-
THIS_DIR="$(dirname "${THIS_FILE}")"
22-
COMPOSE_DIR="${COMPOSE_DIR:-$(dirname "${THIS_DIR}")}"
23-
24-
if [ -f "${COMPOSE_DIR}/read-configs.include.sh" ]; then
25-
. "${COMPOSE_DIR}/read-configs.include.sh"
26-
fi
27-
28-
# default value in case of error or missing definitions
29-
export BIRDHOUSE_DEPLOY_COMPONENTS_JSON='{"components": []}'
30-
if [ -z "${ALL_CONF_DIRS}" ]; then
31-
log WARN "No components in BIRDHOUSE_DEFAULT_CONF_DIRS and BIRDHOUSE_EXTRA_CONF_DIRS. Components JSON list will be empty!"
32-
return
33-
fi
34-
35-
# resolve path considering if sourced or executed, and whether from current dir, birdhouse-compose include or another dir
36-
BIRDHOUSE_DEPLOY_COMPONENTS_ROOT=$(dirname -- "$(realpath "$0")")
37-
if [ "$(echo "${BIRDHOUSE_DEPLOY_COMPONENTS_ROOT}" | grep -cE "/birdhouse/?\$" 2>/dev/null)" -eq 1 ]; then
38-
BIRDHOUSE_DEPLOY_COMPONENTS_ROOT=.
39-
else
40-
BIRDHOUSE_DEPLOY_COMPONENTS_ROOT="${BIRDHOUSE_DEPLOY_COMPONENTS_ROOT}/.."
41-
fi
42-
cd "${BIRDHOUSE_DEPLOY_COMPONENTS_ROOT}" || true # ignore error for now, empty list expected of known components after
43-
44-
# note: no quotes in 'ls' on purpose to expand glob patterns
45-
BIRDHOUSE_DEPLOY_COMPONENTS_LIST_KNOWN="$( \
46-
ls -d1 ./*components/*/ 2>/dev/null \
47-
| sed -E "s|\./(.*)/|\1|" \
48-
| sed -E '/^[[:space:]]*$/d' \
49-
| sed -E 's/^|[[:space:]]+/ -e /' \
50-
)"
51-
if [ -z "${BIRDHOUSE_DEPLOY_COMPONENTS_LIST_KNOWN}" ]; then
52-
log WARN "" \
53-
"Could not resolve known birdhouse-deploy components." \
54-
"Aborting to avoid potentially leaking sensible details." \
55-
"Components will not be reported on the platform's JSON endpoint."
56-
return
57-
fi
58-
BIRDHOUSE_DEPLOY_COMPONENTS_LIST_ACTIVE=$( \
59-
echo "${ALL_CONF_DIRS}" \
60-
| sed '/^[[:space:]]*$/d' \
61-
)
62-
63-
# create a JSON list using the specified components
64-
# each component that starts by './' gets replaced with the below birdhouse prefix to provide contextual information
65-
# other component locations are considered 'custom' and marked as such to provide contextual information
66-
BIRDHOUSE_DEPLOY_COMPONENTS_BASE="bird-house/birdhouse-deploy:"
67-
BIRDHOUSE_DEPLOY_COMPONENTS_LIST=$( \
68-
echo "${BIRDHOUSE_DEPLOY_COMPONENTS_LIST_ACTIVE}" \
69-
| grep ${BIRDHOUSE_DEPLOY_COMPONENTS_LIST_KNOWN} \
70-
| sed -E 's|^\s*([A-Za-z0-9./_-]+)\s*$|"\1",|g' \
71-
| sed -E "s|^\"\./(.*)\"|\"${BIRDHOUSE_DEPLOY_COMPONENTS_BASE}\\1\"|g" \
72-
| sed '/^\n*$/d' \
73-
)
74-
BIRDHOUSE_DEPLOY_COMPONENTS_LIST="${BIRDHOUSE_DEPLOY_COMPONENTS_LIST%?}" # remove last comma
75-
export BIRDHOUSE_DEPLOY_COMPONENTS_JSON="{\"components\": [${BIRDHOUSE_DEPLOY_COMPONENTS_LIST}]}"
20+
for adir in ${ALL_CONF_DIRS}; do
21+
[ -d "${adir}" ] || continue
22+
real_adir="$(readlink -f "${adir}" || realpath "${adir}")"
23+
if [ "${real_adir}" != "${real_adir#${COMPOSE_DIR%/}/*components/}" ]; then
24+
# component is in one of the *components directories in COMPOSE_DIR (not custom)
25+
# custom components are not included in the /components endpoint
26+
component="bird-house/birdhouse-deploy:${real_adir#${COMPOSE_DIR%/}/}"
27+
BIRDHOUSE_DEPLOY_COMPONENTS_LIST="${BIRDHOUSE_DEPLOY_COMPONENTS_LIST}\"${component}\","
28+
fi
29+
done
30+
export BIRDHOUSE_DEPLOY_COMPONENTS_JSON="{\"components\": [${BIRDHOUSE_DEPLOY_COMPONENTS_LIST%,}]}"

birdhouse/scripts/get-services-json.include.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
#!/bin/sh
22

3-
THIS_FILE="$(readlink -f "$0" || realpath "$0")"
4-
THIS_DIR="$(dirname "${THIS_FILE}")"
5-
COMPOSE_DIR="${COMPOSE_DIR:-$(dirname "${THIS_DIR}")}"
6-
7-
if [ -f "${COMPOSE_DIR}/read-configs.include.sh" ]; then
8-
. "${COMPOSE_DIR}/read-configs.include.sh"
9-
fi
10-
113
# default value in case of error or missing definitions
124

135
for adir in ${ALL_CONF_DIRS}; do

0 commit comments

Comments
 (0)