Files
computer-playbook/scripts/meta/resolve/apps.sh
T
kevinveenbirkenbachandClaude Opus 4.7 286408fa91 refactor(roles): role-mapping SPOT under utils/roles + cli inspector + generalist lint
Move utils/roles/applications/files.py to utils/roles/mapping.py and add a
data-driven role-type detector in utils/roles/type.py. Each entry in
ROLE_FILES carries per-role-type allowed/mandatory flags plus marker entries
that drive get_role_types(); a role MAY belong to several types (e.g. an
application that also ships a system service).

Add cli/meta/roles/mapping with files / types / markers subcommands so
contributors can query the schema in text or JSON. Move
cli/meta/applications/ to cli/meta/roles/applications/ and adjust PROJECT_ROOT
parents indices accordingly. Move docs/contributing/design/services/ to
docs/contributing/design/role/services/ and document the mapping in
docs/contributing/design/role/mapping.md per documentation.md.

Replace the narrow test_app_only_files with a generalist
tests/integration/roles/meta/test_mapping.py that walks every role and every
ROLE_FILES entry and reports forbidden files, missing mandatory files,
forbidden entries, and missing mandatory entries in one structured fail
report. meta/info.yml and meta/users.yml are now allowed across every role
type. Create the seven mandatory files surfaced by the generalist test
(README.md for desk-keepassxc, desk-obs, web-svc-cdn following readme_md.md,
plus tasks/main.yml stubs for svc-db-memcached, svc-db-redis, sys-svc-proxy,
web-app-socialhome).

Audit and rewrite touched markdown for documentation.md compliance: replace
em-dashes with fluent sentences, drop SPOT self-labels, fix all broken
relative links introduced by the services/ move.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 13:21:22 +02:00

144 lines
4.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Purpose (SRP): Return JSON list of apps based on deployment type,
# optionally filtered by lifecycle and CI storage constraints.
#
# Inputs via env:
# TEST_DEPLOY_TYPE = server|workstation|universal (required)
# WHITELIST = optional space-separated list of app ids to keep
#
# Output:
# JSON array to stdout (single line, always valid)
: "${TEST_DEPLOY_TYPE:?TEST_DEPLOY_TYPE is required (server|workstation|universal)}"
PYTHON="${PYTHON:-python3}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
cd "$REPO_ROOT"
# ------------------------------------------------------------
# Load default environment (safe if already loaded via BASH_ENV)
# ------------------------------------------------------------
if [[ -f "scripts/meta/env/all.sh" ]]; then
# shellcheck source=scripts/meta/env/all.sh
source "scripts/meta/env/all.sh"
fi
# ------------------------------------------------------------
# Helpers (JSON-only, no text roundtrips)
# ------------------------------------------------------------
json_compact_array() {
# Read JSON from stdin, ensure it's an array, output compact single-line JSON.
jq -c 'if type=="array" then . else [] end'
}
jq_exclude_regex() {
# Args: regex
# Reads JSON array from stdin, filters out entries matching regex, outputs compact JSON.
local re="$1"
if [[ -z "${re}" ]]; then
json_compact_array
return 0
fi
jq -c --arg re "${re}" 'map(select(test($re) | not))'
}
jq_whitelist_filter() {
# Args: whitelist (space-separated app ids)
# Reads JSON array from stdin, keeps only entries in whitelist, outputs compact JSON.
local wl="${1:-}"
if [[ -z "${wl// /}" ]]; then
json_compact_array
return 0
fi
local wl_json
wl_json="$(printf '%s' "${wl}" | jq -Rc 'split(" ") | map(select(length>0))')"
jq -c --argjson wl "${wl_json}" 'map(select(. as $a | ($wl | index($a)) != null))'
}
compose_ci_exec() {
local -a compose_args=(docker compose --env-file env.ci)
if [[ -f "env.development" ]]; then
compose_args+=(--env-file env.development)
fi
compose_args+=(--profile ci exec -T infinito)
NIX_CONFIG="${NIX_CONFIG:-}" \
INFINITO_DISTRO="${INFINITO_DISTRO}" \
"${compose_args[@]}" "$@"
}
# ------------------------------------------------------------
# Lifecycle handling (always-on, original set)
# ------------------------------------------------------------
lifecycles_args=(--lifecycles alpha beta rc stable)
# ------------------------------------------------------------
# 1) Get JSON list from container (keep as JSON)
# ------------------------------------------------------------
apps_json="$(
compose_ci_exec \
"${PYTHON}" -m cli.meta.roles.applications.type \
--format json \
--type "${TEST_DEPLOY_TYPE}" \
"${lifecycles_args[@]}" |
json_compact_array
)"
# ------------------------------------------------------------
# 2) Global hard excludes (regex over app ids)
# ------------------------------------------------------------
apps_json="$(
printf '%s\n' "${apps_json}" |
jq_exclude_regex '^(web-opt-rdr-www|web-app-oauth2-proxy)$'
)"
# ------------------------------------------------------------
# 3) CI storage filter (JSON-only)
# ------------------------------------------------------------
if [[ -n "${GITHUB_ACTIONS:-}" && -z "${ACT:-}" ]]; then
required_storage="60GB"
# Extract roles from JSON to pass as args (safe: one per line -> bash array)
mapfile -t roles < <(printf '%s\n' "${apps_json}" | jq -r '.[]')
if [[ "${#roles[@]}" -gt 0 ]]; then
# Warnings pass (best-effort)
compose_ci_exec \
"${PYTHON}" -m cli.meta.roles.applications.sufficient_storage \
--roles "${roles[@]}" \
--required-storage "${required_storage}" \
--warnings \
--format json \
>/dev/null || true
# Real filter (JSON output)
apps_json="$(
compose_ci_exec \
"${PYTHON}" -m cli.meta.roles.applications.sufficient_storage \
--roles "${roles[@]}" \
--required-storage "${required_storage}" \
--format json |
json_compact_array
)"
fi
fi
# ------------------------------------------------------------
# 3b) Optional whitelist filter (space-separated list of app ids)
# ------------------------------------------------------------
apps_json="$(
printf '%s\n' "${apps_json}" |
jq_whitelist_filter "${WHITELIST:-}"
)"
# ------------------------------------------------------------
# 4) Final safety: compact JSON array, single line
# ------------------------------------------------------------
printf '%s\n' "${apps_json}" | json_compact_array