Files
computer-playbook/scripts/ci/discover.sh
T
kevinveenbirkenbach c92aff464b feat(ci): add min_storage validation and CI filtering with warnings
- Add sufficient_storage CLI for validating docker.services.<entity>.min_storage
- Introduce role_resource_validation utility with human-friendly size parsing
- Filter CI app discovery by available runner storage (default: 12GB)
- Emit GitHub Actions warnings for:
  - missing min_storage metadata (treated as 0GB)
  - roles exceeding available runner storage
- Add BigBlueButton min_storage metadata (50GB)
- Add unit tests for validation logic and CLI behavior
- Add humanfriendly dependency for size parsing

https://chatgpt.com/share/696e097b-1038-800f-b8fc-23e9dadfa021
2026-01-19 11:37:28 +01:00

140 lines
3.7 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
# Purpose (SRP): Return JSON list of apps based on mode + regex filters.
#
# Inputs via env:
# TEST_DEPLOY_TYPE = server|workstation|universal
# INCLUDE_RE (optional)
# EXCLUDE_RE (optional)
# FINAL_EXCLUDE_RE (optional)
#
# Output:
# JSON array to stdout
TEST_DEPLOY_TYPE="${TEST_DEPLOY_TYPE:-server}"
INCLUDE_RE="${INCLUDE_RE:-}"
EXCLUDE_RE="${EXCLUDE_RE:-}"
FINAL_EXCLUDE_RE="${FINAL_EXCLUDE_RE:-}"
json_nonempty() {
local j="${1:-}"
[[ -n "${j}" ]] || j='[]'
echo "${j}"
}
apply_final_exclude() {
local apps_json="$1"
local final_excl="$2"
if [[ -z "${final_excl}" ]]; then
echo "${apps_json}"
return 0
fi
local txt
txt="$(echo "${apps_json}" | jq -r '.[]' | grep -Ev "${final_excl}" || true)"
printf "%s\n" "${txt}" \
| jq -R -s -c 'split("\n") | map(select(length>0))'
}
filter_by_ci_storage() {
local apps_json="$1"
# Only enforce on GitHub Actions, but NOT in act
if [[ -z "${GITHUB_ACTIONS:-}" || -n "${ACT:-}" ]]; then
echo "${apps_json}"
return 0
fi
local required_storage="${CI_REQUIRED_STORAGE:-12GB}"
# Extract roles into bash array
mapfile -t roles < <(echo "${apps_json}" | jq -r '.[]')
if [[ "${#roles[@]}" -eq 0 ]]; then
echo "${apps_json}"
return 0
fi
# 1) Warnings run (show what gets filtered)
# We do NOT want to change the JSON output of discover.sh, so we discard this stdout.
python -m cli.meta.applications.sufficient_storage \
--roles "${roles[@]}" \
--required-storage "${required_storage}" \
--warnings \
>/dev/null || true
# 2) Filter run: capture kept roles (space-separated)
local kept
kept="$(
python -m cli.meta.applications.sufficient_storage \
--roles "${roles[@]}" \
--required-storage "${required_storage}"
)"
# Convert back to JSON
if [[ -z "${kept}" ]]; then
echo "[]"
return 0
fi
# shellcheck disable=SC2086
printf "%s\n" ${kept} | jq -R -s -c 'split("\n") | map(select(length>0))'
}
discover_simple() {
local include_re="$1"
local exclude_re="$2"
INCLUDE_RE="${include_re}" EXCLUDE_RE="${exclude_re}" scripts/tests/discover-apps.sh
}
case "${TEST_DEPLOY_TYPE}" in
server)
: "${INCLUDE_RE:=^(web-app-|web-svc-)}"
: "${EXCLUDE_RE:=^(web-app-oauth2-proxy)$}"
apps_json="$(discover_simple "${INCLUDE_RE}" "${EXCLUDE_RE}")"
apps_json="$(json_nonempty "${apps_json}")"
;;
workstation)
: "${INCLUDE_RE:=^(desk-|util-desk-)}"
: "${EXCLUDE_RE:=}"
apps_json="$(discover_simple "${INCLUDE_RE}" "${EXCLUDE_RE}")"
apps_json="$(json_nonempty "${apps_json}")"
;;
universal)
# universal = all - (server ∪ workstation)
all_json="$(discover_simple '.*' '')"
all_json="$(json_nonempty "${all_json}")"
server_json="$(discover_simple '^(web-app-|web-svc-)' '^(web-app-oauth2-proxy)$')"
server_json="$(json_nonempty "${server_json}")"
workstation_json="$(discover_simple '^(desk-|util-desk-)' '')"
workstation_json="$(json_nonempty "${workstation_json}")"
apps_json="$(
jq -nc \
--argjson all "${all_json}" \
--argjson server "${server_json}" \
--argjson workstation "${workstation_json}" \
'
def uniq: unique;
def union($a;$b): ($a + $b) | uniq;
def minus($a;$b): $a | map(select(. as $x | ($b | index($x)) | not));
(union($server; $workstation) | uniq) as $covered
| minus($all; $covered)
| unique
'
)"
;;
*)
echo "ERROR: TEST_DEPLOY_TYPE must be server|workstation|universal (got: ${TEST_DEPLOY_TYPE})" >&2
exit 2
;;
esac
apps_json="$(filter_by_ci_storage "${apps_json}")"
apps_json="$(apply_final_exclude "${apps_json}" "${FINAL_EXCLUDE_RE}")"
echo "${apps_json}"