diff --git a/.github/workflows/lint-shell.yml b/.github/workflows/lint-shell.yml index c6ba4b1870..a8ee63a057 100644 --- a/.github/workflows/lint-shell.yml +++ b/.github/workflows/lint-shell.yml @@ -14,9 +14,14 @@ jobs: - uses: actions/checkout@v6 - name: Run ShellCheck (container) run: | + mapfile -d '' shell_files < <(find . -type f -name '*.sh' -print0) + if [ "${#shell_files[@]}" -eq 0 ]; then + echo "No shell scripts found." + exit 0 + fi + docker run --rm \ -v "$PWD:/mnt" \ -w /mnt \ koalaman/shellcheck:latest \ - -x $(find . -type f -name '*.sh' -print) - + -x "${shell_files[@]}" diff --git a/Makefile b/Makefile index 533203a1ac..9a46bc7f78 100644 --- a/Makefile +++ b/Makefile @@ -17,11 +17,11 @@ $(error Missing env file: $(ENV_SH)) endif .PHONY: \ - setup setup-clean install install-ansible install-venv install-python install-system-python \ - test test-lint test-unit test-integration test-deploy test-deploy-app \ + setup setup-clean install install-ansible install-lint install-venv install-python install-system-python \ + test lint lint-action lint-ansible lint-python lint-shellcheck test-lint test-unit test-integration test-deploy test-deploy-app \ clean clean-sudo down \ list tree mig dockerignore \ - print-python lint-ansible \ + print-python \ dns-setup dns-remove \ dev-environment-bootstrap dev-environment-teardown \ apparmor-teardown apparmor-restore \ @@ -32,7 +32,7 @@ endif test-act-all test-act-app \ test-local-app test-local-reset test-local-run-all test-local-cleanup test-local-web-purge \ test-local-rapid test-local-rapid-fresh test-local-full \ - format bootstrap setup-development + bootstrap setup-development dev-environment-bootstrap: apparmor-teardown dns-setup disable-ipv6 dev-environment-teardown: apparmor-restore dns-remove @@ -122,6 +122,9 @@ install-ansible: @ANSIBLE_COLLECTIONS_DIR="$(HOME)/.ansible/collections" \ bash scripts/install/ansible.sh +install-lint: + @bash scripts/install/lint.sh + install-system-python: @bash roles/dev-python/files/install.sh ensure @@ -131,7 +134,7 @@ install-venv: install-system-python install-python: install-venv @bash scripts/install/python.sh -install: install-python install-ansible +install: install-python install-ansible install-lint setup: dockerignore @bash scripts/setup.sh @@ -144,14 +147,23 @@ bootstrap: install setup setup-clean: clean setup @echo "Full build with cleanup before was executed." -format: - set -euo pipefail; \ - shfmt -w scripts; \ - ruff format .; \ - ruff check . --fix +# --- Lint --- +lint: lint-action lint-ansible lint-python lint-shellcheck + +lint-action: + @bash scripts/lint/action.sh + +lint-ansible: + @bash scripts/lint/ansible.sh + +lint-python: + @bash scripts/lint/python.sh + +lint-shellcheck: + @bash scripts/lint/shellcheck.sh # --- Tests (separated) --- -test: test-lint test-unit test-integration lint-ansible test-deploy +test: lint test-lint test-unit test-integration test-deploy @echo "βœ… Full test (setup + tests) executed." test-lint: install @@ -211,8 +223,3 @@ test-local-rapid-fresh: test-local-cleanup-entity test-local-rapid test-local-full: @echo "=== local full deploy (type=$${TEST_DEPLOY_TYPE}, distro=$${INFINITO_DISTRO}) ===" @bash scripts/tests/deploy/local/all.sh - -# Backwards compatible target (kept) -lint-ansible: - @echo "πŸ“‘ Checking Ansible syntax…" - ansible-playbook -i localhost, -c local $(foreach f,$(wildcard group_vars/all/*.yml),-e @$(f)) playbook.yml --syntax-check diff --git a/roles/dev-python/files/install.sh b/roles/dev-python/files/install.sh index a44f3698d9..729ef4efd9 100755 --- a/roles/dev-python/files/install.sh +++ b/roles/dev-python/files/install.sh @@ -41,11 +41,16 @@ run_privileged() { fi } -need_privileged_or_fail() { +can_run_privileged() { if [[ "${EUID}" -eq 0 ]]; then return 0 fi - if command -v sudo >/dev/null 2>&1; then + command -v sudo >/dev/null 2>&1 || return 1 + sudo -n true >/dev/null 2>&1 +} + +need_privileged_or_fail() { + if can_run_privileged; then return 0 fi echo "[ERROR] Root privileges are required (sudo unavailable)." >&2 @@ -331,7 +336,18 @@ resolve_or_install_python_bin() { } if [[ "${MODE}" == "ensure" ]]; then - ensure_python_bin + if PYBIN="$(pick_python_bin)"; then + if ! can_run_privileged; then + log "Using existing Python without privileged system-wide symlink updates: $("${PYBIN}" --version)" + if "${PYBIN}" -m pip --version >/dev/null 2>&1; then + log "Existing pip: $("${PYBIN}" -m pip --version)" + exit 0 + fi + fi + else + ensure_python_bin + fi + configure_defaults "${PYBIN}" log "Default python: $(python3 --version)" log "Default pip: $(pip3 --version)" diff --git a/scripts/administration/apparmor/teardown.sh b/scripts/administration/apparmor/teardown.sh index 3081a90844..1bc48b3eb2 100755 --- a/scripts/administration/apparmor/teardown.sh +++ b/scripts/administration/apparmor/teardown.sh @@ -6,9 +6,9 @@ echo "[apparmor] tearing down (dev mode)" systemctl stop apparmor || true if command -v aa-teardown >/dev/null 2>&1; then - aa-teardown + aa-teardown else - apparmor_parser -R /etc/apparmor.d/* || true + apparmor_parser -R /etc/apparmor.d/* || true fi echo "[apparmor] teardown complete" diff --git a/scripts/administration/ghcr/cleanup_ci_images.sh b/scripts/administration/ghcr/cleanup_ci_images.sh index e21afee276..87f33ffe01 100755 --- a/scripts/administration/ghcr/cleanup_ci_images.sh +++ b/scripts/administration/ghcr/cleanup_ci_images.sh @@ -2,7 +2,7 @@ set -euo pipefail usage() { - cat <<'USAGE' + cat <<'USAGE' Usage: cleanup_ci_images.sh [--days N] [--owner OWNER] [--distros "arch debian ..."] @@ -33,27 +33,43 @@ OWNER="${OWNER:-}" DISTROS="${DISTROS:-arch debian ubuntu fedora centos}" while [[ $# -gt 0 ]]; do - case "$1" in - --days) DAYS="${2:-}"; shift 2 ;; - --owner) OWNER="${2:-}"; shift 2 ;; - --distros) DISTROS="${2:-}"; shift 2 ;; - -h|--help) usage; exit 0 ;; - *) echo "Unknown arg: $1" >&2; usage; exit 2 ;; - esac + case "$1" in + --days) + DAYS="${2:-}" + shift 2 + ;; + --owner) + OWNER="${2:-}" + shift 2 + ;; + --distros) + DISTROS="${2:-}" + shift 2 + ;; + -h | --help) + usage + exit 0 + ;; + *) + echo "Unknown arg: $1" >&2 + usage + exit 2 + ;; + esac done if [[ -z "${OWNER}" ]]; then - echo "ERROR: OWNER is required (env OWNER or --owner)." >&2 - exit 2 + echo "ERROR: OWNER is required (env OWNER or --owner)." >&2 + exit 2 fi if ! command -v gh >/dev/null 2>&1; then - echo "ERROR: gh CLI not found." >&2 - exit 1 + echo "ERROR: gh CLI not found." >&2 + exit 1 fi if ! command -v jq >/dev/null 2>&1; then - echo "ERROR: jq not found." >&2 - exit 1 + echo "ERROR: jq not found." >&2 + exit 1 fi cutoff="$(date -u -d "${DAYS} days ago" +%s)" @@ -67,15 +83,18 @@ echo # Try orgs first, fall back to users gh_api_json() { - local method="$1"; shift - local endpoint="$1"; shift - local scope="$1"; shift # orgs|users + local method="$1" + shift + local endpoint="$1" + shift + local scope="$1" + shift # orgs|users - if [[ "${method}" == "GET" ]]; then - gh api -H "Accept: application/vnd.github+json" "/${scope}/${OWNER}/${endpoint}" "$@" 2>/dev/null || true - else - gh api -X "${method}" -H "Accept: application/vnd.github+json" "/${scope}/${OWNER}/${endpoint}" "$@" 2>/dev/null || true - fi + if [[ "${method}" == "GET" ]]; then + gh api -H "Accept: application/vnd.github+json" "/${scope}/${OWNER}/${endpoint}" "$@" 2>/dev/null || true + else + gh api -X "${method}" -H "Accept: application/vnd.github+json" "/${scope}/${OWNER}/${endpoint}" "$@" 2>/dev/null || true + fi } # Determine whether OWNER is org or user. @@ -84,81 +103,81 @@ gh_api_json() { # - otherwise try users endpoint; if that returns JSON array, treat as user # Returns: "orgs" or "users" on stdout. detect_scope_for_pkg() { - local pkg="$1" - local endpoint="packages/container/${pkg}/versions?per_page=1&page=1" + local pkg="$1" + local endpoint="packages/container/${pkg}/versions?per_page=1&page=1" - local r - r="$(gh_api_json GET "${endpoint}" orgs)" - if [[ -n "${r}" ]] && echo "${r}" | jq -e 'type=="array"' >/dev/null 2>&1; then - echo "orgs" - return 0 - fi + local r + r="$(gh_api_json GET "${endpoint}" orgs)" + if [[ -n "${r}" ]] && echo "${r}" | jq -e 'type=="array"' >/dev/null 2>&1; then + echo "orgs" + return 0 + fi - r="$(gh_api_json GET "${endpoint}" users)" - if [[ -n "${r}" ]] && echo "${r}" | jq -e 'type=="array"' >/dev/null 2>&1; then - echo "users" - return 0 - fi + r="$(gh_api_json GET "${endpoint}" users)" + if [[ -n "${r}" ]] && echo "${r}" | jq -e 'type=="array"' >/dev/null 2>&1; then + echo "users" + return 0 + fi - # unknown (no access / package missing). default to orgs (safe), caller will handle empties. - echo "orgs" + # unknown (no access / package missing). default to orgs (safe), caller will handle empties. + echo "orgs" } list_versions() { - local pkg="$1" - local scope - scope="$(detect_scope_for_pkg "${pkg}")" + local pkg="$1" + local scope + scope="$(detect_scope_for_pkg "${pkg}")" - local page=1 - while :; do - resp="$(gh_api_json GET "packages/container/${pkg}/versions?per_page=100&page=${page}" "${scope}")" + local page=1 + while :; do + resp="$(gh_api_json GET "packages/container/${pkg}/versions?per_page=100&page=${page}" "${scope}")" - if [[ -z "${resp}" ]] || [[ "${resp}" == "[]" ]]; then - break - fi + if [[ -z "${resp}" ]] || [[ "${resp}" == "[]" ]]; then + break + fi - echo "${resp}" + echo "${resp}" - count="$(echo "${resp}" | jq 'length')" - if [[ "${count}" -lt 100 ]]; then - break - fi - page=$((page+1)) - done + count="$(echo "${resp}" | jq 'length')" + if [[ "${count}" -lt 100 ]]; then + break + fi + page=$((page + 1)) + done } delete_version() { - local pkg="$1" - local id="$2" + local pkg="$1" + local id="$2" - # Try orgs first - if gh api -X DELETE -H "Accept: application/vnd.github+json" \ - "/orgs/${OWNER}/packages/container/${pkg}/versions/${id}" >/dev/null 2>&1; then - return 0 - fi + # Try orgs first + if gh api -X DELETE -H "Accept: application/vnd.github+json" \ + "/orgs/${OWNER}/packages/container/${pkg}/versions/${id}" >/dev/null 2>&1; then + return 0 + fi - # Fallback to users - gh api -X DELETE -H "Accept: application/vnd.github+json" \ - "/users/${OWNER}/packages/container/${pkg}/versions/${id}" >/dev/null + # Fallback to users + gh api -X DELETE -H "Accept: application/vnd.github+json" \ + "/users/${OWNER}/packages/container/${pkg}/versions/${id}" >/dev/null } # --- main ------------------------------------------------------------------- for d in ${DISTROS}; do - pkg="infinito-${d}" - echo "=== Package: ${pkg} ===" + pkg="infinito-${d}" + echo "=== Package: ${pkg} ===" - all="$(list_versions "${pkg}" | jq -s 'add' 2>/dev/null || echo '[]')" - total="$(echo "${all}" | jq 'length')" - echo "Found versions: ${total}" + all="$(list_versions "${pkg}" | jq -s 'add' 2>/dev/null || echo '[]')" + total="$(echo "${all}" | jq 'length')" + echo "Found versions: ${total}" - if [[ "${total}" -eq 0 ]]; then - echo "Skip: no versions (or package not found / no access)" - echo - continue - fi + if [[ "${total}" -eq 0 ]]; then + echo "Skip: no versions (or package not found / no access)" + echo + continue + fi - deletable="$(echo "${all}" | jq --argjson cutoff "${cutoff}" ' + deletable="$(echo "${all}" | jq --argjson cutoff "${cutoff}" ' map( . as $v | ($v.created_at | fromdateiso8601) as $created @@ -175,24 +194,24 @@ for d in ${DISTROS}; do | map(select((.tags | all(startswith("ci-"))))) ')" - del_count="$(echo "${deletable}" | jq 'length')" - echo "Deletable versions: ${del_count}" + del_count="$(echo "${deletable}" | jq 'length')" + echo "Deletable versions: ${del_count}" - if [[ "${del_count}" -eq 0 ]]; then - echo "Nothing to delete." - echo - continue - fi + if [[ "${del_count}" -eq 0 ]]; then + echo "Nothing to delete." + echo + continue + fi - echo "${deletable}" | jq -r '.[] | "DELETE id=\(.id) created_at=\(.created_at) tags=\(.tags|join(","))"' + echo "${deletable}" | jq -r '.[] | "DELETE id=\(.id) created_at=\(.created_at) tags=\(.tags|join(","))"' - echo "${deletable}" | jq -r '.[].id' | while read -r id; do - echo "Deleting ${pkg} version id=${id} ..." - delete_version "${pkg}" "${id}" - done + echo "${deletable}" | jq -r '.[].id' | while read -r id; do + echo "Deleting ${pkg} version id=${id} ..." + delete_version "${pkg}" "${id}" + done - echo "Done: ${pkg}" - echo + echo "Done: ${pkg}" + echo done echo ">>> Cleanup finished." diff --git a/scripts/administration/purge/entity/all.sh b/scripts/administration/purge/entity/all.sh index a56dc95a4b..5b82076991 100755 --- a/scripts/administration/purge/entity/all.sh +++ b/scripts/administration/purge/entity/all.sh @@ -17,11 +17,17 @@ WIPE_DATA_ONLY=false DB_ONLY=false while [[ "${1:-}" == --* ]]; do - case "${1}" in - --wipe-data-only) WIPE_DATA_ONLY=true; shift ;; - --db-only) DB_ONLY=true; shift ;; - --help|-h) - cat <<'EOF' + case "${1}" in + --wipe-data-only) + WIPE_DATA_ONLY=true + shift + ;; + --db-only) + DB_ONLY=true + shift + ;; + --help | -h) + cat <<'EOF' Usage: purge/entity/all.sh [--wipe-data-only] [--db-only] [STACK2] [...] @@ -29,60 +35,60 @@ Flags: --wipe-data-only Truncate all tables (keep schema) instead of dropping DB --db-only Only purge DB; skip compose down and filesystem cleanup EOF - exit 0 - ;; - *) - echo "ERROR: Unknown flag: ${1}" >&2 - exit 2 - ;; - esac + exit 0 + ;; + *) + echo "ERROR: Unknown flag: ${1}" >&2 + exit 2 + ;; + esac done if [[ "$#" -lt 1 ]]; then - echo "ERROR: No stack names provided." >&2 - echo "Usage: $0 [--wipe-data-only] [--db-only] [STACK2] [...]" >&2 - exit 2 + echo "ERROR: No stack names provided." >&2 + echo "Usage: $0 [--wipe-data-only] [--db-only] [STACK2] [...]" >&2 + exit 2 fi SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" -log() { echo ">>> $*"; } +log() { echo ">>> $*"; } warn() { echo "!!! WARNING: $*" >&2; } overall_rc=0 for STACK_NAME in "$@"; do -( - set -euo pipefail + ( + set -euo pipefail - echo - log "============================================================" - log "Purging stack: ${STACK_NAME}" - log "============================================================" + echo + log "============================================================" + log "Purging stack: ${STACK_NAME}" + log "============================================================" - db_args=() - if [[ "${WIPE_DATA_ONLY}" == "true" ]]; then - db_args+=(--wipe-data-only) - fi + db_args=() + if [[ "${WIPE_DATA_ONLY}" == "true" ]]; then + db_args+=(--wipe-data-only) + fi - # 1) DB purge always (requested: try both backends best effort) - "${SCRIPT_DIR}/db.sh" "${db_args[@]}" "${STACK_NAME}" + # 1) DB purge always (requested: try both backends best effort) + "${SCRIPT_DIR}/db.sh" "${db_args[@]}" "${STACK_NAME}" - # 2/3) Optional: compose + filesystem cleanup - if [[ "${DB_ONLY}" == "true" ]]; then - log "DB-only mode active β€” skipping compose and filesystem cleanup" - exit 0 - fi + # 2/3) Optional: compose + filesystem cleanup + if [[ "${DB_ONLY}" == "true" ]]; then + log "DB-only mode active β€” skipping compose and filesystem cleanup" + exit 0 + fi - "${SCRIPT_DIR}/compose.sh" "${STACK_NAME}" - "${SCRIPT_DIR}/dir.sh" "${STACK_NAME}" + "${SCRIPT_DIR}/compose.sh" "${STACK_NAME}" + "${SCRIPT_DIR}/dir.sh" "${STACK_NAME}" - log "Stack '${STACK_NAME}' purged." -) || { - rc=$? - overall_rc=1 - warn "Stack '${STACK_NAME}' purge failed (rc=${rc}) β€” continuing" -} + log "Stack '${STACK_NAME}' purged." + ) || { + rc=$? + overall_rc=1 + warn "Stack '${STACK_NAME}' purge failed (rc=${rc}) β€” continuing" + } done log "All requested stacks processed." diff --git a/scripts/administration/purge/entity/compose.sh b/scripts/administration/purge/entity/compose.sh index df99456d78..a6bf35d4ca 100755 --- a/scripts/administration/purge/entity/compose.sh +++ b/scripts/administration/purge/entity/compose.sh @@ -7,11 +7,11 @@ set -euo pipefail if [[ "$#" -lt 1 ]]; then - echo "ERROR: No stack names provided." >&2 - exit 2 + echo "ERROR: No stack names provided." >&2 + exit 2 fi -log() { echo ">>> $*"; } +log() { echo ">>> $*"; } warn() { echo "!!! WARNING: $*" >&2; } run_no_stdin() { "$@" [STACK2] [...] Flags: --wipe-data-only Truncate all tables (keep schema) instead of dropping DB EOF - exit 0 - ;; - *) - echo "ERROR: Unknown flag: ${1}" >&2 - exit 2 - ;; - esac + exit 0 + ;; + *) + echo "ERROR: Unknown flag: ${1}" >&2 + exit 2 + ;; + esac done if [[ "$#" -lt 1 ]]; then - echo "ERROR: No stack names provided." >&2 - exit 2 + echo "ERROR: No stack names provided." >&2 + exit 2 fi -log() { echo ">>> $*"; } +log() { echo ">>> $*"; } warn() { echo "!!! WARNING: $*" >&2; } env_get() { - local env_file="$1" - local key="$2" + local env_file="$1" + local key="$2" - awk -F= -v k="$key" ' + awk -F= -v k="$key" ' $1 ~ "^[[:space:]]*"k"[[:space:]]*$" { v=$0 sub("^[^=]*=","",v) @@ -65,43 +68,43 @@ run_no_stdin() { "$@" pg_backend_pid(); DROP DATABASE IF EXISTS "${db_name}"; SQL - local rc=$? - set -e + local rc=$? + set -e - [[ $rc -ne 0 ]] && warn "Postgres DROP DATABASE failed for '${db_name}' (rc=${rc})" + [[ $rc -ne 0 ]] && warn "Postgres DROP DATABASE failed for '${db_name}' (rc=${rc})" } truncate_postgres_db_best_effort() { - local db_name="$1" + local db_name="$1" - if ! container ps --format '{{.Names}}' | grep -qx 'postgres'; then - warn "Postgres container 'postgres' not running β€” skipping Postgres TRUNCATE for '${db_name}'" - return 0 - fi + if ! container ps --format '{{.Names}}' | grep -qx 'postgres'; then + warn "Postgres container 'postgres' not running β€” skipping Postgres TRUNCATE for '${db_name}'" + return 0 + fi - log "Truncating all tables in Postgres database '${db_name}'..." + log "Truncating all tables in Postgres database '${db_name}'..." - set +e - docker exec -i postgres psql -U postgres -d "${db_name}" <<'SQL' + set +e + docker exec -i postgres psql -U postgres -d "${db_name}" <<'SQL' DO $$ DECLARE r RECORD; @@ -115,10 +118,10 @@ BEGIN END LOOP; END $$; SQL - local rc=$? - set -e + local rc=$? + set -e - [[ $rc -ne 0 ]] && warn "Postgres TRUNCATE failed for '${db_name}' (rc=${rc})" + [[ $rc -ne 0 ]] && warn "Postgres TRUNCATE failed for '${db_name}' (rc=${rc})" } # --------------------------------------------------------------------------- @@ -126,103 +129,103 @@ SQL # --------------------------------------------------------------------------- drop_mariadb_db_best_effort() { - local db_name="$1" + local db_name="$1" - if ! container ps --format '{{.Names}}' | grep -qx 'mariadb'; then - warn "MariaDB container 'mariadb' not running β€” skipping MariaDB DROP for '${db_name}'" - return 0 - fi + if ! container ps --format '{{.Names}}' | grep -qx 'mariadb'; then + warn "MariaDB container 'mariadb' not running β€” skipping MariaDB DROP for '${db_name}'" + return 0 + fi - case "${db_name}" in - mysql|information_schema|performance_schema|sys) - warn "Refusing to drop MariaDB system database '${db_name}'" - return 0 - ;; - esac + case "${db_name}" in + mysql | information_schema | performance_schema | sys) + warn "Refusing to drop MariaDB system database '${db_name}'" + return 0 + ;; + esac - local mariadb_env="/opt/compose/mariadb/.env/env" - [[ ! -f "${mariadb_env}" ]] && { - warn "MariaDB env file not found (${mariadb_env}) β€” skipping MariaDB DROP" - return 0 - } + local mariadb_env="/opt/compose/mariadb/.env/env" + [[ ! -f "${mariadb_env}" ]] && { + warn "MariaDB env file not found (${mariadb_env}) β€” skipping MariaDB DROP" + return 0 + } - local root_pw - root_pw="$(env_get "${mariadb_env}" MARIADB_ROOT_PASSWORD || true)" - [[ -z "${root_pw}" ]] && { - warn "MARIADB_ROOT_PASSWORD not found β€” skipping MariaDB DROP" - return 0 - } + local root_pw + root_pw="$(env_get "${mariadb_env}" MARIADB_ROOT_PASSWORD || true)" + [[ -z "${root_pw}" ]] && { + warn "MARIADB_ROOT_PASSWORD not found β€” skipping MariaDB DROP" + return 0 + } - log "Dropping MariaDB database '${db_name}'..." + log "Dropping MariaDB database '${db_name}'..." - set +e - run_no_stdin docker exec mariadb mariadb -uroot -p"${root_pw}" \ - -e "DROP DATABASE IF EXISTS \`${db_name}\`;" - local rc=$? - set -e + set +e + run_no_stdin docker exec mariadb mariadb -uroot -p"${root_pw}" \ + -e "DROP DATABASE IF EXISTS \`${db_name}\`;" + local rc=$? + set -e - [[ $rc -ne 0 ]] && warn "MariaDB DROP DATABASE failed for '${db_name}' (rc=${rc})" + [[ $rc -ne 0 ]] && warn "MariaDB DROP DATABASE failed for '${db_name}' (rc=${rc})" } truncate_mariadb_db_best_effort() { - local db_name="$1" + local db_name="$1" - if ! container ps --format '{{.Names}}' | grep -qx 'mariadb'; then - warn "MariaDB container 'mariadb' not running β€” skipping MariaDB TRUNCATE for '${db_name}'" - return 0 - fi + if ! container ps --format '{{.Names}}' | grep -qx 'mariadb'; then + warn "MariaDB container 'mariadb' not running β€” skipping MariaDB TRUNCATE for '${db_name}'" + return 0 + fi - local mariadb_env="/opt/compose/mariadb/.env/env" - [[ ! -f "${mariadb_env}" ]] && { - warn "MariaDB env file not found (${mariadb_env}) β€” skipping MariaDB TRUNCATE" - return 0 - } + local mariadb_env="/opt/compose/mariadb/.env/env" + [[ ! -f "${mariadb_env}" ]] && { + warn "MariaDB env file not found (${mariadb_env}) β€” skipping MariaDB TRUNCATE" + return 0 + } - local root_pw - root_pw="$(env_get "${mariadb_env}" MARIADB_ROOT_PASSWORD || true)" - [[ -z "${root_pw}" ]] && { - warn "MARIADB_ROOT_PASSWORD not found β€” skipping MariaDB TRUNCATE" - return 0 - } + local root_pw + root_pw="$(env_get "${mariadb_env}" MARIADB_ROOT_PASSWORD || true)" + [[ -z "${root_pw}" ]] && { + warn "MARIADB_ROOT_PASSWORD not found β€” skipping MariaDB TRUNCATE" + return 0 + } - log "Truncating all tables in MariaDB database '${db_name}'..." + log "Truncating all tables in MariaDB database '${db_name}'..." - set +e - truncates="$( - run_no_stdin docker exec mariadb mariadb -uroot -p"${root_pw}" -N -B "${db_name}" -e " + set +e + truncates="$( + run_no_stdin docker exec mariadb mariadb -uroot -p"${root_pw}" -N -B "${db_name}" -e " SELECT CONCAT('TRUNCATE TABLE \`', table_name, '\`;') FROM information_schema.tables WHERE table_schema = DATABASE(); " - )" - local gen_rc=$? - if [[ $gen_rc -ne 0 ]]; then - set -e - warn "MariaDB TRUNCATE statement generation failed for '${db_name}' (rc=${gen_rc})" - return 0 - fi + )" + local gen_rc=$? + if [[ $gen_rc -ne 0 ]]; then + set -e + warn "MariaDB TRUNCATE statement generation failed for '${db_name}' (rc=${gen_rc})" + return 0 + fi - { - echo "SET FOREIGN_KEY_CHECKS=0;" - echo "${truncates}" - echo "SET FOREIGN_KEY_CHECKS=1;" - } | run_no_stdin docker exec -i mariadb mariadb -uroot -p"${root_pw}" "${db_name}" - local rc=$? - set -e + { + echo "SET FOREIGN_KEY_CHECKS=0;" + echo "${truncates}" + echo "SET FOREIGN_KEY_CHECKS=1;" + } | run_no_stdin docker exec -i mariadb mariadb -uroot -p"${root_pw}" "${db_name}" + local rc=$? + set -e - [[ $rc -ne 0 ]] && warn "MariaDB TRUNCATE failed for '${db_name}' (rc=${rc})" + [[ $rc -ne 0 ]] && warn "MariaDB TRUNCATE failed for '${db_name}' (rc=${rc})" } purge_db_both_backends_best_effort() { - local db_name="$1" + local db_name="$1" - if [[ "${WIPE_DATA_ONLY}" == "true" ]]; then - truncate_postgres_db_best_effort "${db_name}" - truncate_mariadb_db_best_effort "${db_name}" - else - drop_postgres_db_best_effort "${db_name}" - drop_mariadb_db_best_effort "${db_name}" - fi + if [[ "${WIPE_DATA_ONLY}" == "true" ]]; then + truncate_postgres_db_best_effort "${db_name}" + truncate_mariadb_db_best_effort "${db_name}" + else + drop_postgres_db_best_effort "${db_name}" + drop_mariadb_db_best_effort "${db_name}" + fi } # --------------------------------------------------------------------------- @@ -232,52 +235,52 @@ purge_db_both_backends_best_effort() { overall_rc=0 for STACK_NAME in "$@"; do -( - set -euo pipefail + ( + set -euo pipefail - STACK_DIR="/opt/compose/${STACK_NAME}" - ENV_FILE="${STACK_DIR}/.env/env" + STACK_DIR="/opt/compose/${STACK_NAME}" + ENV_FILE="${STACK_DIR}/.env/env" - DB_NAME="${STACK_NAME}" - DB_BACKEND="" # informational only + DB_NAME="${STACK_NAME}" + DB_BACKEND="" # informational only - if [[ -f "${ENV_FILE}" ]]; then - KC_DB="$(env_get "${ENV_FILE}" KC_DB || true)" - KC_DB_URL="$(env_get "${ENV_FILE}" KC_DB_URL || true)" + if [[ -f "${ENV_FILE}" ]]; then + KC_DB="$(env_get "${ENV_FILE}" KC_DB || true)" + KC_DB_URL="$(env_get "${ENV_FILE}" KC_DB_URL || true)" - if [[ -n "${KC_DB}" ]]; then - echo "${KC_DB}" | grep -qi postgres && DB_BACKEND="postgres" || true - echo "${KC_DB}" | grep -qi mariadb && DB_BACKEND="mariadb" || true - fi + if [[ -n "${KC_DB}" ]]; then + echo "${KC_DB}" | grep -qi postgres && DB_BACKEND="postgres" || true + echo "${KC_DB}" | grep -qi mariadb && DB_BACKEND="mariadb" || true + fi - if [[ -n "${KC_DB_URL}" ]]; then - echo "${KC_DB_URL}" | grep -qi postgresql && DB_BACKEND="postgres" || true - echo "${KC_DB_URL}" | grep -qi mariadb && DB_BACKEND="mariadb" || true - DB_NAME="$(echo "${KC_DB_URL}" | sed -E 's|.*/([^/?#]+).*|\1|')" - fi + if [[ -n "${KC_DB_URL}" ]]; then + echo "${KC_DB_URL}" | grep -qi postgresql && DB_BACKEND="postgres" || true + echo "${KC_DB_URL}" | grep -qi mariadb && DB_BACKEND="mariadb" || true + DB_NAME="$(echo "${KC_DB_URL}" | sed -E 's|.*/([^/?#]+).*|\1|')" + fi - if [[ -z "${DB_BACKEND}" ]]; then - grep -qi postgres "${ENV_FILE}" && DB_BACKEND="postgres" || true - fi - if [[ -z "${DB_BACKEND}" ]]; then - grep -qi mariadb "${ENV_FILE}" && DB_BACKEND="mariadb" || true - fi - else - warn "Env file not found (${ENV_FILE}) β€” DB name defaults to stack name '${DB_NAME}'" - fi + if [[ -z "${DB_BACKEND}" ]]; then + grep -qi postgres "${ENV_FILE}" && DB_BACKEND="postgres" || true + fi + if [[ -z "${DB_BACKEND}" ]]; then + grep -qi mariadb "${ENV_FILE}" && DB_BACKEND="mariadb" || true + fi + else + warn "Env file not found (${ENV_FILE}) β€” DB name defaults to stack name '${DB_NAME}'" + fi - if [[ -n "${DB_BACKEND}" ]]; then - log "DB purge (informational backend=${DB_BACKEND}) | stack=${STACK_NAME} | db=${DB_NAME}" - else - log "DB purge (backend unknown; trying BOTH) | stack=${STACK_NAME} | db=${DB_NAME}" - fi + if [[ -n "${DB_BACKEND}" ]]; then + log "DB purge (informational backend=${DB_BACKEND}) | stack=${STACK_NAME} | db=${DB_NAME}" + else + log "DB purge (backend unknown; trying BOTH) | stack=${STACK_NAME} | db=${DB_NAME}" + fi - purge_db_both_backends_best_effort "${DB_NAME}" -) || { - rc=$? - overall_rc=1 - warn "DB purge failed for '${STACK_NAME}' (rc=${rc}) β€” continuing" -} + purge_db_both_backends_best_effort "${DB_NAME}" + ) || { + rc=$? + overall_rc=1 + warn "DB purge failed for '${STACK_NAME}' (rc=${rc}) β€” continuing" + } done exit "${overall_rc}" diff --git a/scripts/administration/purge/entity/dir.sh b/scripts/administration/purge/entity/dir.sh index 1544f72d93..cbfa837b5a 100755 --- a/scripts/administration/purge/entity/dir.sh +++ b/scripts/administration/purge/entity/dir.sh @@ -9,38 +9,38 @@ set -euo pipefail if [[ "$#" -lt 1 ]]; then - echo "ERROR: No stack names provided." >&2 - exit 2 + echo "ERROR: No stack names provided." >&2 + exit 2 fi -log() { echo ">>> $*"; } +log() { echo ">>> $*"; } warn() { echo "!!! WARNING: $*" >&2; } overall_rc=0 for STACK_NAME in "$@"; do -( - set -euo pipefail + ( + set -euo pipefail - STACK_DIR="/opt/compose/${STACK_NAME}" + STACK_DIR="/opt/compose/${STACK_NAME}" - if [[ ! -d "${STACK_DIR}" ]]; then - warn "Stack dir not found for '${STACK_NAME}' (${STACK_DIR}) β€” skipping filesystem cleanup" - exit 0 - fi + if [[ ! -d "${STACK_DIR}" ]]; then + warn "Stack dir not found for '${STACK_NAME}' (${STACK_DIR}) β€” skipping filesystem cleanup" + exit 0 + fi - if [[ -d "${STACK_DIR}/volumes" ]]; then - log "Removing volumes dir for '${STACK_NAME}'" - rm -rf "${STACK_DIR}/volumes" - fi + if [[ -d "${STACK_DIR}/volumes" ]]; then + log "Removing volumes dir for '${STACK_NAME}'" + rm -rf "${STACK_DIR}/volumes" + fi - log "Removing stack directory for '${STACK_NAME}'" - rm -rf "${STACK_DIR}" -) || { - rc=$? - overall_rc=1 - warn "Filesystem cleanup failed for '${STACK_NAME}' (rc=${rc}) β€” continuing" -} + log "Removing stack directory for '${STACK_NAME}'" + rm -rf "${STACK_DIR}" + ) || { + rc=$? + overall_rc=1 + warn "Filesystem cleanup failed for '${STACK_NAME}' (rc=${rc}) β€” continuing" + } done exit "${overall_rc}" diff --git a/scripts/administration/purge/web.sh b/scripts/administration/purge/web.sh index f90229a214..11d61af778 100755 --- a/scripts/administration/purge/web.sh +++ b/scripts/administration/purge/web.sh @@ -2,4 +2,4 @@ rm -rv /etc/nginx/ rm -rv /etc/infinito.nexus/ca rm -rv /etc/infinito.nexus/selfsigned -( cd /opt/compose/openresty/ && docker compose down -v ) +(cd /opt/compose/openresty/ && docker compose down -v) diff --git a/scripts/administration/trust_ca.sh b/scripts/administration/trust_ca.sh index 775d54f223..034b2e0e36 100644 --- a/scripts/administration/trust_ca.sh +++ b/scripts/administration/trust_ca.sh @@ -15,14 +15,14 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" WITH_CA_TRUST_SCRIPT="${SCRIPT_DIR}/../../roles/sys-ca-selfsigned/files/with-ca-trust.sh" log() { - echo "[trust-ca] $*" >&2 + echo "[trust-ca] $*" >&2 } require() { - if ! command -v "$1" >/dev/null 2>&1; then - echo "[trust-ca] ERROR: required command not found: $1" >&2 - exit 1 - fi + if ! command -v "$1" >/dev/null 2>&1; then + echo "[trust-ca] ERROR: required command not found: $1" >&2 + exit 1 + fi } # --- checks ------------------------------------------------------------------ @@ -31,13 +31,13 @@ require docker require sudo if [ -z "$CONTAINER_NAME" ]; then - echo "[trust-ca] ERROR: INFINITO_CONTAINER is not set" >&2 - exit 2 + echo "[trust-ca] ERROR: INFINITO_CONTAINER is not set" >&2 + exit 2 fi if [ ! -f "$WITH_CA_TRUST_SCRIPT" ]; then - echo "[trust-ca] ERROR: with-ca-trust.sh not found at $WITH_CA_TRUST_SCRIPT" >&2 - exit 3 + echo "[trust-ca] ERROR: with-ca-trust.sh not found at $WITH_CA_TRUST_SCRIPT" >&2 + exit 3 fi log "Using container: $CONTAINER_NAME" @@ -50,8 +50,8 @@ log "Extracting Root CA from container" sudo mkdir -p "$CA_DST_DIR" sudo docker cp \ - "${CONTAINER_NAME}:${CA_SRC_PATH}" \ - "$CA_DST_PATH" + "${CONTAINER_NAME}:${CA_SRC_PATH}" \ + "$CA_DST_PATH" sudo chmod 0644 "$CA_DST_PATH" @@ -60,10 +60,10 @@ sudo chmod 0644 "$CA_DST_PATH" log "Installing CA into host trust store" sudo \ - CA_TRUST_CERT="$CA_DST_PATH" \ - CA_TRUST_NAME="$CA_TRUST_NAME" \ - VERBOSE=1 \ - bash "$WITH_CA_TRUST_SCRIPT" + CA_TRUST_CERT="$CA_DST_PATH" \ + CA_TRUST_NAME="$CA_TRUST_NAME" \ + VERBOSE=1 \ + bash "$WITH_CA_TRUST_SCRIPT" log "CA trust installation completed successfully" diff --git a/scripts/dns/remove.sh b/scripts/dns/remove.sh index c846a4d0fe..f1955ecd4c 100755 --- a/scripts/dns/remove.sh +++ b/scripts/dns/remove.sh @@ -12,9 +12,9 @@ echo ">>> Removing local DNS for *.${DOMAIN}" # Remove NetworkManager dnsmasq setup if systemctl is-active --quiet NetworkManager 2>/dev/null; then - echo ">>> NetworkManager active -> removing NM dnsmasq config" - sudo rm -f "${NM_CONF}" "${NM_DNSMASQ_CONF}" - sudo systemctl restart NetworkManager + echo ">>> NetworkManager active -> removing NM dnsmasq config" + sudo rm -f "${NM_CONF}" "${NM_DNSMASQ_CONF}" + sudo systemctl restart NetworkManager fi # Remove system dnsmasq snippet (fallback setup) @@ -22,7 +22,7 @@ sudo rm -f "${SYS_DNSMASQ_CONF}" || true # If system dnsmasq is active, restart to apply if systemctl is-active --quiet dnsmasq 2>/dev/null; then - sudo systemctl restart dnsmasq || true + sudo systemctl restart dnsmasq || true fi echo ">>> Removed." diff --git a/scripts/dns/setup.sh b/scripts/dns/setup.sh index 9b36586dbe..19653ca0f3 100755 --- a/scripts/dns/setup.sh +++ b/scripts/dns/setup.sh @@ -12,88 +12,88 @@ SYS_DNSMASQ_CONF="/etc/dnsmasq.d/${DOMAIN}.conf" echo ">>> Setting up local DNS for *.${DOMAIN} -> 127.0.0.1" install_dnsmasq_if_missing() { - if command -v dnsmasq >/dev/null 2>&1; then - return 0 - fi + if command -v dnsmasq >/dev/null 2>&1; then + return 0 + fi - echo ">>> dnsmasq not found -> installing" + echo ">>> dnsmasq not found -> installing" - if command -v pacman >/dev/null 2>&1; then - sudo pacman -S --noconfirm --needed dnsmasq - elif command -v apt-get >/dev/null 2>&1; then - sudo apt-get update - sudo apt-get install -y dnsmasq - elif command -v dnf >/dev/null 2>&1; then - sudo dnf install -y dnsmasq - else - echo "ERROR: Unsupported distro/package manager. Install dnsmasq manually." - exit 1 - fi + if command -v pacman >/dev/null 2>&1; then + sudo pacman -S --noconfirm --needed dnsmasq + elif command -v apt-get >/dev/null 2>&1; then + sudo apt-get update + sudo apt-get install -y dnsmasq + elif command -v dnf >/dev/null 2>&1; then + sudo dnf install -y dnsmasq + else + echo "ERROR: Unsupported distro/package manager. Install dnsmasq manually." + exit 1 + fi } configure_via_networkmanager_dnsmasq() { - echo ">>> Detected NetworkManager -> configuring NM dnsmasq plugin (recommended)" - install_dnsmasq_if_missing + echo ">>> Detected NetworkManager -> configuring NM dnsmasq plugin (recommended)" + install_dnsmasq_if_missing - # Avoid port conflicts with a system-wide dnsmasq service - if systemctl is-enabled --quiet dnsmasq 2>/dev/null || systemctl is-active --quiet dnsmasq 2>/dev/null; then - echo ">>> Disabling system dnsmasq to avoid conflicts with NetworkManager dnsmasq" - sudo systemctl disable --now dnsmasq || true - fi + # Avoid port conflicts with a system-wide dnsmasq service + if systemctl is-enabled --quiet dnsmasq 2>/dev/null || systemctl is-active --quiet dnsmasq 2>/dev/null; then + echo ">>> Disabling system dnsmasq to avoid conflicts with NetworkManager dnsmasq" + sudo systemctl disable --now dnsmasq || true + fi - echo ">>> Writing NetworkManager dnsmasq config: ${NM_CONF}" - sudo mkdir -p "$(dirname "${NM_CONF}")" - cat </dev/null + echo ">>> Writing NetworkManager dnsmasq config: ${NM_CONF}" + sudo mkdir -p "$(dirname "${NM_CONF}")" + cat </dev/null [main] dns=dnsmasq EOF - echo ">>> Writing dnsmasq snippet for NetworkManager: ${NM_DNSMASQ_CONF}" - sudo mkdir -p "${NM_DNSMASQ_DIR}" - cat </dev/null + echo ">>> Writing dnsmasq snippet for NetworkManager: ${NM_DNSMASQ_CONF}" + sudo mkdir -p "${NM_DNSMASQ_DIR}" + cat </dev/null # Map the entire zone to localhost (wildcard) address=/${DOMAIN}/127.0.0.1 address=/${DOMAIN}/::1 EOF - echo ">>> Restarting NetworkManager" - sudo systemctl restart NetworkManager + echo ">>> Restarting NetworkManager" + sudo systemctl restart NetworkManager - echo ">>> Resolver status" - cat /etc/resolv.conf || true + echo ">>> Resolver status" + cat /etc/resolv.conf || true } configure_via_system_dnsmasq() { - echo ">>> NetworkManager not active -> configuring system dnsmasq (fallback)" - install_dnsmasq_if_missing + echo ">>> NetworkManager not active -> configuring system dnsmasq (fallback)" + install_dnsmasq_if_missing - echo ">>> Writing system dnsmasq config: ${SYS_DNSMASQ_CONF}" - sudo mkdir -p /etc/dnsmasq.d - cat </dev/null + echo ">>> Writing system dnsmasq config: ${SYS_DNSMASQ_CONF}" + sudo mkdir -p /etc/dnsmasq.d + cat </dev/null address=/${DOMAIN}/127.0.0.1 address=/${DOMAIN}/::1 EOF - echo ">>> Enabling and restarting dnsmasq service" - sudo systemctl enable dnsmasq --now - sudo systemctl restart dnsmasq + echo ">>> Enabling and restarting dnsmasq service" + sudo systemctl enable dnsmasq --now + sudo systemctl restart dnsmasq - # Optional: systemd-resolved integration if it exists, but NEVER fail the script - if command -v resolvectl >/dev/null 2>&1 && systemctl is-active --quiet systemd-resolved 2>/dev/null; then - echo ">>> Configuring systemd-resolved routing for ${DOMAIN}" - sudo resolvectl dns lo 127.0.0.1 || true - sudo resolvectl domain lo "~${DOMAIN}" || true - else - echo ">>> systemd-resolved not active -> skipping resolvectl integration" - echo ">>> NOTE: Ensure your system resolver uses 127.0.0.1 to query dnsmasq." - fi + # Optional: systemd-resolved integration if it exists, but NEVER fail the script + if command -v resolvectl >/dev/null 2>&1 && systemctl is-active --quiet systemd-resolved 2>/dev/null; then + echo ">>> Configuring systemd-resolved routing for ${DOMAIN}" + sudo resolvectl dns lo 127.0.0.1 || true + sudo resolvectl domain lo "~${DOMAIN}" || true + else + echo ">>> systemd-resolved not active -> skipping resolvectl integration" + echo ">>> NOTE: Ensure your system resolver uses 127.0.0.1 to query dnsmasq." + fi } # Prefer NetworkManager path if NM is present+active (your case) if systemctl is-active --quiet NetworkManager 2>/dev/null; then - configure_via_networkmanager_dnsmasq + configure_via_networkmanager_dnsmasq else - configure_via_system_dnsmasq + configure_via_system_dnsmasq fi echo diff --git a/scripts/docker/entry.sh b/scripts/docker/entry.sh index 46d74fa80b..acc0bd4395 100755 --- a/scripts/docker/entry.sh +++ b/scripts/docker/entry.sh @@ -3,8 +3,8 @@ set -euo pipefail echo "[docker-infinito] Starting infinito container" if [[ "${1:-}" == "/sbin/init" ]]; then - echo "[docker-infinito] Starting systemd as PID 1..." - exec /sbin/init + echo "[docker-infinito] Starting systemd as PID 1..." + exec /sbin/init fi # Compute dynamically if not provided from outside diff --git a/scripts/docker/healthcheck.sh b/scripts/docker/healthcheck.sh index 11aa9662d6..d2edf986af 100755 --- a/scripts/docker/healthcheck.sh +++ b/scripts/docker/healthcheck.sh @@ -3,37 +3,36 @@ set -euo pipefail # 1) systemd private socket must exist if [[ ! -S /run/systemd/private ]]; then - echo "systemd socket not ready" - exit 1 + echo "systemd socket not ready" + exit 1 fi # 2) systemd must be running or degraded state="$(systemctl is-system-running --wait 2>/dev/null || true)" case "$state" in - running|degraded) - ;; - *) - echo "systemd state: $state" - exit 1 - ;; +running | degraded) ;; +*) + echo "systemd state: $state" + exit 1 + ;; esac # 3) infinito command must exist and be executable if ! command -v infinito >/dev/null 2>&1; then - echo "infinito command not found" - exit 1 + echo "infinito command not found" + exit 1 fi if [[ ! -x "$(command -v infinito)" ]]; then - echo "infinito command not executable" - exit 1 + echo "infinito command not executable" + exit 1 fi # 4) infinito must return 0 (smoke test) if ! infinito --help >/dev/null 2>&1; then - echo "infinito command failed" - exit 1 + echo "infinito command failed" + exit 1 fi # all good diff --git a/scripts/image/build.sh b/scripts/image/build.sh index e73412ef8e..43cdffbc87 100755 --- a/scripts/image/build.sh +++ b/scripts/image/build.sh @@ -7,7 +7,7 @@ NO_CACHE=0 MISSING_ONLY=0 # New: build variant -VARIANT="full" # full | slim +VARIANT="full" # full | slim # Keep --target for advanced usage, but default is derived from VARIANT. TARGET="" @@ -81,12 +81,18 @@ while [[ $# -gt 0 ]]; do ;; --target) TARGET="${2:-}" - [[ -n "${TARGET}" ]] || { echo "ERROR: --target requires a value"; exit 2; } + [[ -n "${TARGET}" ]] || { + echo "ERROR: --target requires a value" + exit 2 + } shift 2 ;; --tag) IMAGE_TAG="${2:-}" - [[ -n "${IMAGE_TAG}" ]] || { echo "ERROR: --tag requires a value"; exit 2; } + [[ -n "${IMAGE_TAG}" ]] || { + echo "ERROR: --tag requires a value" + exit 2 + } shift 2 ;; --push) @@ -100,30 +106,45 @@ while [[ $# -gt 0 ]]; do ;; --registry) REGISTRY="${2:-}" - [[ -n "${REGISTRY}" ]] || { echo "ERROR: --registry requires a value"; exit 2; } + [[ -n "${REGISTRY}" ]] || { + echo "ERROR: --registry requires a value" + exit 2 + } shift 2 ;; --owner) OWNER="${2:-}" - [[ -n "${OWNER}" ]] || { echo "ERROR: --owner requires a value"; exit 2; } + [[ -n "${OWNER}" ]] || { + echo "ERROR: --owner requires a value" + exit 2 + } shift 2 ;; --repo-prefix) REPO_PREFIX="${2:-}" - [[ -n "${REPO_PREFIX}" ]] || { echo "ERROR: --repo-prefix requires a value"; exit 2; } + [[ -n "${REPO_PREFIX}" ]] || { + echo "ERROR: --repo-prefix requires a value" + exit 2 + } shift 2 ;; --version) VERSION="${2:-}" - [[ -n "${VERSION}" ]] || { echo "ERROR: --version requires a value"; exit 2; } + [[ -n "${VERSION}" ]] || { + echo "ERROR: --version requires a value" + exit 2 + } shift 2 ;; --stable) IS_STABLE="${2:-}" - [[ -n "${IS_STABLE}" ]] || { echo "ERROR: --stable requires a value (true|false)"; exit 2; } + [[ -n "${IS_STABLE}" ]] || { + echo "ERROR: --stable requires a value (true|false)" + exit 2 + } shift 2 ;; - -h|--help) + -h | --help) usage exit 0 ;; @@ -173,9 +194,18 @@ fi # Validate publish parameters if [[ "${PUBLISH}" == "1" ]]; then - [[ -n "${REGISTRY}" ]] || { echo "ERROR: --publish requires --registry"; exit 2; } - [[ -n "${OWNER}" ]] || { echo "ERROR: --publish requires --owner"; exit 2; } - [[ -n "${VERSION}" ]] || { echo "ERROR: --publish requires --version"; exit 2; } + [[ -n "${REGISTRY}" ]] || { + echo "ERROR: --publish requires --registry" + exit 2 + } + [[ -n "${OWNER}" ]] || { + echo "ERROR: --publish requires --owner" + exit 2 + } + [[ -n "${VERSION}" ]] || { + echo "ERROR: --publish requires --version" + exit 2 + } fi # Guard: --push without --publish requires fully-qualified --tag diff --git a/scripts/image/push.sh b/scripts/image/push.sh index e881276b06..2de518cb53 100755 --- a/scripts/image/push.sh +++ b/scripts/image/push.sh @@ -14,35 +14,35 @@ attempt=1 nix_arg=() if [[ "${USE_NIX_TOKEN}" == "true" ]]; then - : "${NIX_GITHUB_TOKEN:?Missing NIX_GITHUB_TOKEN}" - nix_arg=( --build-arg "NIX_CONFIG=access-tokens = github.com=${NIX_GITHUB_TOKEN}" ) + : "${NIX_GITHUB_TOKEN:?Missing NIX_GITHUB_TOKEN}" + nix_arg=(--build-arg "NIX_CONFIG=access-tokens = github.com=${NIX_GITHUB_TOKEN}") else - echo "pull_request_target on fork detected: skipping NIX_CONFIG token build-arg." + echo "pull_request_target on fork detected: skipping NIX_CONFIG token build-arg." fi while true; do - echo "=== Build & push attempt ${attempt}/${max_attempts} ===" + echo "=== Build & push attempt ${attempt}/${max_attempts} ===" - if docker buildx build \ - --file "${BUILD_CONTEXT_DIR}/Dockerfile" \ - --push \ - --tag "ghcr.io/${GITHUB_REPOSITORY_OWNER}/infinito-${MATRIX_DISTRO}:${IMAGE_TAG}" \ - --label "org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY}" \ - --build-arg "PKGMGR_IMAGE=ghcr.io/kevinveenbirkenbach/pkgmgr-${MATRIX_DISTRO}:stable" \ - "${nix_arg[@]}" \ - --cache-from "type=gha,scope=infinito-${MATRIX_DISTRO}" \ - --cache-to "type=gha,mode=max,scope=infinito-${MATRIX_DISTRO}" \ - "${BUILD_CONTEXT_DIR}"; then - echo "Build & push succeeded on attempt ${attempt}/${max_attempts}." - break - fi + if docker buildx build \ + --file "${BUILD_CONTEXT_DIR}/Dockerfile" \ + --push \ + --tag "ghcr.io/${GITHUB_REPOSITORY_OWNER}/infinito-${MATRIX_DISTRO}:${IMAGE_TAG}" \ + --label "org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY}" \ + --build-arg "PKGMGR_IMAGE=ghcr.io/kevinveenbirkenbach/pkgmgr-${MATRIX_DISTRO}:stable" \ + "${nix_arg[@]}" \ + --cache-from "type=gha,scope=infinito-${MATRIX_DISTRO}" \ + --cache-to "type=gha,mode=max,scope=infinito-${MATRIX_DISTRO}" \ + "${BUILD_CONTEXT_DIR}"; then + echo "Build & push succeeded on attempt ${attempt}/${max_attempts}." + break + fi - if [[ "${attempt}" -ge "${max_attempts}" ]]; then - echo "Build & push failed after ${max_attempts} attempts." - exit 1 - fi + if [[ "${attempt}" -ge "${max_attempts}" ]]; then + echo "Build & push failed after ${max_attempts} attempts." + exit 1 + fi - echo "Attempt ${attempt} failed. Retrying in ${retry_delay_seconds}s..." - sleep "${retry_delay_seconds}" - attempt=$((attempt + 1)) + echo "Attempt ${attempt} failed. Retrying in ${retry_delay_seconds}s..." + sleep "${retry_delay_seconds}" + attempt=$((attempt + 1)) done diff --git a/scripts/image/release.sh b/scripts/image/release.sh index 1365b7eb54..b94c324f49 100755 --- a/scripts/image/release.sh +++ b/scripts/image/release.sh @@ -4,7 +4,10 @@ set -euo pipefail # Retag already built CI images (ci-) to and latest (no rebuild). OWNER="${OWNER:-${GITHUB_REPOSITORY_OWNER:-}}" -[[ -n "${OWNER}" ]] || { echo "ERROR: OWNER not set"; exit 2; } +[[ -n "${OWNER}" ]] || { + echo "ERROR: OWNER not set" + exit 2 +} REGISTRY="${REGISTRY:-ghcr.io}" REPO_PREFIX="${REPO_PREFIX:-infinito}" @@ -13,11 +16,17 @@ DEFAULT_DISTRO="${DEFAULT_DISTRO:-debian}" # VERSION_TAG must be like "v1.2.3" VERSION_TAG="${VERSION_TAG:-${GITHUB_REF_NAME:-}}" -[[ -n "${VERSION_TAG}" ]] || { echo "ERROR: VERSION_TAG not set"; exit 2; } +[[ -n "${VERSION_TAG}" ]] || { + echo "ERROR: VERSION_TAG not set" + exit 2 +} # CI_TAG should be "ci-" CI_TAG="${CI_TAG:-ci-${GITHUB_SHA:-}}" -[[ -n "${CI_TAG}" ]] || { echo "ERROR: CI_TAG not set"; exit 2; } +[[ -n "${CI_TAG}" ]] || { + echo "ERROR: CI_TAG not set" + exit 2 +} echo "Retagging CI images:" echo " CI_TAG = ${CI_TAG}" @@ -25,36 +34,36 @@ echo " VERSION_TAG = ${VERSION_TAG}" echo " DISTROS = ${DISTROS}" retag_set() { - local src="$1" - local dst_ver="$2" - local dst_latest="$3" + local src="$1" + local dst_ver="$2" + local dst_latest="$3" - echo " source: ${src}" - echo " target: ${dst_ver}" - echo " target: ${dst_latest}" + echo " source: ${src}" + echo " target: ${dst_ver}" + echo " target: ${dst_latest}" - docker buildx imagetools create \ - -t "${dst_ver}" \ - -t "${dst_latest}" \ - "${src}" + docker buildx imagetools create \ + -t "${dst_ver}" \ + -t "${dst_latest}" \ + "${src}" } for distro in ${DISTROS}; do - echo - echo "==> ${distro}" + echo + echo "==> ${distro}" - # NORMAL - src="${REGISTRY}/${OWNER}/${REPO_PREFIX}-${distro}:${CI_TAG}" - dst_ver="${REGISTRY}/${OWNER}/${REPO_PREFIX}-${distro}:${VERSION_TAG}" - dst_latest="${REGISTRY}/${OWNER}/${REPO_PREFIX}-${distro}:latest" - retag_set "${src}" "${dst_ver}" "${dst_latest}" + # NORMAL + src="${REGISTRY}/${OWNER}/${REPO_PREFIX}-${distro}:${CI_TAG}" + dst_ver="${REGISTRY}/${OWNER}/${REPO_PREFIX}-${distro}:${VERSION_TAG}" + dst_latest="${REGISTRY}/${OWNER}/${REPO_PREFIX}-${distro}:latest" + retag_set "${src}" "${dst_ver}" "${dst_latest}" - # Alias for default distro - if [[ "${distro}" == "${DEFAULT_DISTRO}" ]]; then - alias_ver="${REGISTRY}/${OWNER}/${REPO_PREFIX}:${VERSION_TAG}" - alias_latest="${REGISTRY}/${OWNER}/${REPO_PREFIX}:latest" - docker buildx imagetools create -t "${alias_ver}" -t "${alias_latest}" "${src}" - fi + # Alias for default distro + if [[ "${distro}" == "${DEFAULT_DISTRO}" ]]; then + alias_ver="${REGISTRY}/${OWNER}/${REPO_PREFIX}:${VERSION_TAG}" + alias_latest="${REGISTRY}/${OWNER}/${REPO_PREFIX}:latest" + docker buildx imagetools create -t "${alias_ver}" -t "${alias_latest}" "${src}" + fi done echo diff --git a/scripts/install/README.md b/scripts/install/README.md new file mode 100644 index 0000000000..c09b82756c --- /dev/null +++ b/scripts/install/README.md @@ -0,0 +1,10 @@ +# Install Scripts + +This directory contains scripts that install and bootstrap host-side tooling used by the project. + +- πŸ“¦ Install Python, Ansible, and lint dependencies for supported environments +- 🐍 Bootstrap virtual environments and editable project dependencies +- πŸ› οΈ Keep host preparation separate from lint, build, and test execution + +The scope of this folder is installation and bootstrap. +Lint execution, build workflows, and test orchestration should stay in their dedicated script directories. diff --git a/scripts/install/ansible.sh b/scripts/install/ansible.sh index 790105eda8..58fe66ef23 100755 --- a/scripts/install/ansible.sh +++ b/scripts/install/ansible.sh @@ -16,42 +16,42 @@ GALAXY_REQ="requirements/requirements.galaxy.yml" GIT_REQ="requirements/requirements.git.yml" while true; do - echo "▢️ Attempt ${ATTEMPT}/${MAX_ATTEMPTS}" + echo "▢️ Attempt ${ATTEMPT}/${MAX_ATTEMPTS}" - echo "🌐 Trying Galaxy source (${GALAXY_REQ})…" - if "${PYTHON}" -m ansible.cli.galaxy collection install \ - -r "${GALAXY_REQ}" \ - -p "${ANSIBLE_COLLECTIONS_DIR}" \ - --force-with-deps; then + echo "🌐 Trying Galaxy source (${GALAXY_REQ})…" + if "${PYTHON}" -m ansible.cli.galaxy collection install \ + -r "${GALAXY_REQ}" \ + -p "${ANSIBLE_COLLECTIONS_DIR}" \ + --force-with-deps; then - echo "βœ… Collections installed successfully via Galaxy on attempt ${ATTEMPT}" - break - fi + echo "βœ… Collections installed successfully via Galaxy on attempt ${ATTEMPT}" + break + fi - echo "⚠️ Galaxy install failed on attempt ${ATTEMPT}" + echo "⚠️ Galaxy install failed on attempt ${ATTEMPT}" - echo "πŸ” Falling back to Git source (${GIT_REQ})…" - if "${PYTHON}" -m ansible.cli.galaxy collection install \ - -r "${GIT_REQ}" \ - -p "${ANSIBLE_COLLECTIONS_DIR}" \ - --force-with-deps; then + echo "πŸ” Falling back to Git source (${GIT_REQ})…" + if "${PYTHON}" -m ansible.cli.galaxy collection install \ + -r "${GIT_REQ}" \ + -p "${ANSIBLE_COLLECTIONS_DIR}" \ + --force-with-deps; then - echo "βœ… Collections installed successfully via Git fallback on attempt ${ATTEMPT}" - break - fi + echo "βœ… Collections installed successfully via Git fallback on attempt ${ATTEMPT}" + break + fi - if (( ATTEMPT >= MAX_ATTEMPTS )); then - echo "❌ Installation failed after ${MAX_ATTEMPTS} attempts." - echo " Galaxy and Git fallback both failed." - exit 1 - fi + if ((ATTEMPT >= MAX_ATTEMPTS)); then + echo "❌ Installation failed after ${MAX_ATTEMPTS} attempts." + echo " Galaxy and Git fallback both failed." + exit 1 + fi - SLEEP_TIME=$((60 + RANDOM % 61)) - echo "⏸️ Attempt ${ATTEMPT} failed for both sources." - echo " Waiting ${SLEEP_TIME}s before retry…" + SLEEP_TIME=$((60 + RANDOM % 61)) + echo "⏸️ Attempt ${ATTEMPT} failed for both sources." + echo " Waiting ${SLEEP_TIME}s before retry…" - sleep "${SLEEP_TIME}" - ((ATTEMPT++)) + sleep "${SLEEP_TIME}" + ((ATTEMPT++)) done echo "πŸŽ‰ All collections are ready" diff --git a/scripts/install/lint.sh b/scripts/install/lint.sh new file mode 100755 index 0000000000..6bea526cc8 --- /dev/null +++ b/scripts/install/lint.sh @@ -0,0 +1,263 @@ +#!/usr/bin/env bash +# shellcheck shell=bash + +set -euo pipefail + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd -- "${SCRIPT_DIR}/../.." && pwd)" + +run_privileged() { + if [[ "${EUID}" -eq 0 ]] || ! command -v sudo >/dev/null 2>&1; then + "$@" + else + sudo "$@" + fi +} + +log() { + printf '%s\n' "$*" +} + +warn() { + printf '%s\n' "$*" >&2 +} + +detect_package_manager() { + if command -v pacman >/dev/null 2>&1; then + printf 'pacman\n' + elif command -v apt-get >/dev/null 2>&1; then + printf 'apt-get\n' + elif command -v dnf >/dev/null 2>&1; then + printf 'dnf\n' + elif command -v yum >/dev/null 2>&1; then + printf 'yum\n' + elif command -v brew >/dev/null 2>&1; then + printf 'brew\n' + else + return 1 + fi +} + +install_package_candidates() { + local manager="$1" + shift + local package + + case "${manager}" in + apt-get) + run_privileged apt-get update + ;; + dnf) + run_privileged dnf -y install dnf-plugins-core || true + run_privileged dnf -y install epel-release || true + ;; + yum) + run_privileged yum -y install yum-utils || true + run_privileged yum -y install epel-release || true + ;; + esac + + for package in "$@"; do + log "Installing package '${package}' via ${manager}" + case "${manager}" in + pacman) + if run_privileged pacman -Syu --noconfirm --needed "${package}"; then + return 0 + fi + ;; + apt-get) + if run_privileged apt-get install -y --no-install-recommends "${package}"; then + return 0 + fi + ;; + dnf) + if run_privileged dnf -y install "${package}"; then + return 0 + fi + ;; + yum) + if run_privileged yum -y install "${package}"; then + return 0 + fi + ;; + brew) + if brew install "${package}"; then + return 0 + fi + ;; + *) + warn "Unsupported package manager: ${manager}" + return 1 + ;; + esac + done + + return 1 +} + +install_command() { + local manager="$1" + local command_name="$2" + + case "${command_name}:${manager}" in + actionlint:pacman | actionlint:apt-get | actionlint:dnf | actionlint:yum | actionlint:brew) + install_package_candidates "${manager}" actionlint + ;; + ansible-galaxy:pacman | ansible-galaxy:apt-get | ansible-galaxy:dnf | ansible-galaxy:yum | ansible-galaxy:brew | \ + ansible-playbook:pacman | ansible-playbook:apt-get | ansible-playbook:dnf | ansible-playbook:yum | ansible-playbook:brew) + if [[ "${manager}" == "brew" ]]; then + install_package_candidates "${manager}" ansible + else + install_package_candidates "${manager}" ansible-core ansible + fi + ;; + ruff:pacman | ruff:apt-get | ruff:dnf | ruff:yum | ruff:brew) + install_package_candidates "${manager}" ruff + ;; + shfmt:pacman | shfmt:apt-get | shfmt:dnf | shfmt:yum | shfmt:brew) + install_package_candidates "${manager}" shfmt + ;; + shellcheck:pacman | shellcheck:apt-get | shellcheck:dnf | shellcheck:yum | shellcheck:brew) + install_package_candidates "${manager}" shellcheck + ;; + *) + warn "No installer mapping defined for '${command_name}' on '${manager}'." + return 1 + ;; + esac +} + +ensure_command() { + local command_name="$1" + + if command -v "${command_name}" >/dev/null 2>&1; then + return 0 + fi + + local manager + manager="$(detect_package_manager)" || { + warn "No supported package manager found to install '${command_name}'." + return 1 + } + + log "Missing command '${command_name}'. Attempting installation via ${manager}." + install_command "${manager}" "${command_name}" || { + warn "Installation failed for '${command_name}' via ${manager}." + return 1 + } + + command -v "${command_name}" >/dev/null 2>&1 || { + warn "Command '${command_name}' is still unavailable after installation." + return 1 + } +} + +ensure_required_ansible_collections() { + local collections_base_dir="${HOME}/.ansible/collections" + local collections_dir="${collections_base_dir}/ansible_collections" + local missing=() + local max_attempts=5 + local attempt=1 + local sleep_time + + [[ -d "${collections_dir}/community/general" ]] || missing+=(community.general) + [[ -d "${collections_dir}/hetzner/hcloud" ]] || missing+=(hetzner.hcloud) + [[ -d "${collections_dir}/kewlfft/aur" ]] || missing+=(kewlfft.aur) + + if [[ "${#missing[@]}" -eq 0 ]]; then + return 0 + fi + + while true; do + log "Installing missing Ansible collections: ${missing[*]} (attempt ${attempt}/${max_attempts})" + + if ansible-galaxy collection install \ + -r "${REPO_ROOT}/requirements/requirements.galaxy.yml" \ + -p "${collections_base_dir}" \ + --force-with-deps; then + return 0 + fi + + warn "Galaxy install failed on attempt ${attempt}. Trying git fallback." + + if ansible-galaxy collection install \ + -r "${REPO_ROOT}/requirements/requirements.git.yml" \ + -p "${collections_base_dir}" \ + --force-with-deps; then + return 0 + fi + + if ((attempt >= max_attempts)); then + warn "Unable to install required Ansible collections." + return 1 + fi + + sleep_time=$((60 + RANDOM % 61)) + warn "Retrying collection installation in ${sleep_time}s." + sleep "${sleep_time}" + ((attempt++)) + done +} + +install_action_tools() { + ensure_command actionlint +} + +install_ansible_tools() { + ensure_command ansible-playbook + ensure_command ansible-galaxy + ensure_required_ansible_collections +} + +install_python_tools() { + ensure_command shfmt + ensure_command ruff +} + +install_shellcheck_tools() { + ensure_command shellcheck +} + +install_requested_group() { + local group="$1" + + case "${group}" in + all) + install_action_tools + install_ansible_tools + install_python_tools + install_shellcheck_tools + ;; + action) + install_action_tools + ;; + ansible) + install_ansible_tools + ;; + python) + install_python_tools + ;; + shellcheck) + install_shellcheck_tools + ;; + *) + warn "Usage: $0 [all|action|ansible|python|shellcheck]..." + return 2 + ;; + esac +} + +main() { + local groups=("$@") + local group + + if [[ "${#groups[@]}" -eq 0 ]]; then + groups=(all) + fi + + for group in "${groups[@]}"; do + install_requested_group "${group}" + done +} + +main "$@" diff --git a/scripts/install/python.sh b/scripts/install/python.sh index 3768e21f02..926c5778d3 100755 --- a/scripts/install/python.sh +++ b/scripts/install/python.sh @@ -6,38 +6,38 @@ set -euo pipefail EXTRA="${1:-}" retry() { - local attempts=7 - local delay=20 - local count=1 + local attempts=7 + local delay=20 + local count=1 - while true; do - if "$@"; then - return 0 - fi + while true; do + if "$@"; then + return 0 + fi - if [[ $count -ge $attempts ]]; then - echo "❌ Command failed after ${attempts} attempts." - return 1 - fi + if [[ $count -ge $attempts ]]; then + echo "❌ Command failed after ${attempts} attempts." + return 1 + fi - echo "⚠️ Attempt ${count}/${attempts} failed. Retrying in ${delay}s..." - sleep "${delay}" - ((count++)) - done + echo "⚠️ Attempt ${count}/${attempts} failed. Retrying in ${delay}s..." + sleep "${delay}" + ((count++)) + done } install_python_deps() { - echo "πŸ“¦ Installing Python dependencies" + echo "πŸ“¦ Installing Python dependencies" - retry "${PYTHON}" -m pip install --upgrade pip setuptools wheel + retry "${PYTHON}" -m pip install --upgrade pip setuptools wheel - if [[ -n "${EXTRA}" ]]; then - echo "β†’ Installing with extras: [${EXTRA}]" - retry "${PYTHON}" -m pip install -e ".[${EXTRA}]" - else - echo "β†’ Installing base package" - retry "${PYTHON}" -m pip install -e . - fi + if [[ -n "${EXTRA}" ]]; then + echo "β†’ Installing with extras: [${EXTRA}]" + retry "${PYTHON}" -m pip install -e ".[${EXTRA}]" + else + echo "β†’ Installing base package" + retry "${PYTHON}" -m pip install -e . + fi } install_python_deps diff --git a/scripts/install/venv.sh b/scripts/install/venv.sh index cf13944e41..e47251c9ae 100755 --- a/scripts/install/venv.sh +++ b/scripts/install/venv.sh @@ -27,40 +27,40 @@ REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" DEV_PYTHON_INSTALLER="${REPO_ROOT}/roles/dev-python/files/install.sh" install_venv() { - if [[ ! -f "${DEV_PYTHON_INSTALLER}" ]]; then - echo "❌ Missing installer: ${DEV_PYTHON_INSTALLER}" >&2 - return 1 - fi + if [[ ! -f "${DEV_PYTHON_INSTALLER}" ]]; then + echo "❌ Missing installer: ${DEV_PYTHON_INSTALLER}" >&2 + return 1 + fi - # πŸ›  Bootstrap interpreter (system Python, outside of venv) - # Used ONLY to CREATE the virtualenv. - local bootstrap_python - bootstrap_python="$(bash "${DEV_PYTHON_INSTALLER}" print)" + # πŸ›  Bootstrap interpreter (system Python, outside of venv) + # Used ONLY to CREATE the virtualenv. + local bootstrap_python + bootstrap_python="$(bash "${DEV_PYTHON_INSTALLER}" print)" - # πŸ“¦ Target interpreter inside the venv (may not exist yet!) - local venv_python="${VENV}/bin/python" + # πŸ“¦ Target interpreter inside the venv (may not exist yet!) + local venv_python="${VENV}/bin/python" - echo "🐍 Virtualenv target : ${VENV}" - echo "πŸ“ Virtualenv base : ${VENV_BASE}" - echo "πŸ›  Bootstrap python : ${bootstrap_python}" - echo "🎯 Venv python target : ${venv_python}" - echo + echo "🐍 Virtualenv target : ${VENV}" + echo "πŸ“ Virtualenv base : ${VENV_BASE}" + echo "πŸ›  Bootstrap python : ${bootstrap_python}" + echo "🎯 Venv python target : ${venv_python}" + echo - # Ensure base directory exists (e.g. /opt/venvs) - if [[ -z "${VIRTUAL_ENV:-}" ]]; then - mkdir -p "${VENV_BASE}" - fi + # Ensure base directory exists (e.g. /opt/venvs) + if [[ -z "${VIRTUAL_ENV:-}" ]]; then + mkdir -p "${VENV_BASE}" + fi - # ------------------------------------------------------------ - # Create venv if missing - # ------------------------------------------------------------ - if [[ ! -x "${venv_python}" ]]; then - echo "β†’ Creating virtualenv ${VENV}" - "${bootstrap_python}" -m venv "${VENV}" - echo "βœ… Virtualenv created" - else - echo "β†’ Virtualenv already exists" - fi + # ------------------------------------------------------------ + # Create venv if missing + # ------------------------------------------------------------ + if [[ ! -x "${venv_python}" ]]; then + echo "β†’ Creating virtualenv ${VENV}" + "${bootstrap_python}" -m venv "${VENV}" + echo "βœ… Virtualenv created" + else + echo "β†’ Virtualenv already exists" + fi } install_venv diff --git a/scripts/inventory/resolve.sh b/scripts/inventory/resolve.sh index 9e418f0c02..893dd15a0b 100644 --- a/scripts/inventory/resolve.sh +++ b/scripts/inventory/resolve.sh @@ -15,22 +15,22 @@ set -euo pipefail # (no mkdir, no side-effects) require_env() { - local name="$1" - if [[ -z "${!name:-}" ]]; then - echo "[FATAL] ${name} must be set by Makefile" >&2 - exit 2 - fi + local name="$1" + if [[ -z "${!name:-}" ]]; then + echo "[FATAL] ${name} must be set by Makefile" >&2 + exit 2 + fi } normalize_bool() { - local v="${1:-}" - case "${v}" in - true|false) printf '%s' "${v}" ;; - *) - echo "[FATAL] invalid boolean value: '${v}' (expected true|false)" >&2 - exit 2 - ;; - esac + local v="${1:-}" + case "${v}" in + true | false) printf '%s' "${v}" ;; + *) + echo "[FATAL] invalid boolean value: '${v}' (expected true|false)" >&2 + exit 2 + ;; + esac } require_env "RUNNING_ON_ACT" @@ -41,11 +41,11 @@ RUNNING_ON_ACT="$(normalize_bool "${RUNNING_ON_ACT}")" RUNNING_ON_GITHUB="$(normalize_bool "${RUNNING_ON_GITHUB}")" if [[ "${RUNNING_ON_ACT}" == "true" ]]; then - INVENTORY_DIR="${HOME}/inventories/act" + INVENTORY_DIR="${HOME}/inventories/act" elif [[ "${RUNNING_ON_GITHUB}" == "true" ]]; then - INVENTORY_DIR="${HOME}/inventories/github" + INVENTORY_DIR="${HOME}/inventories/github" else - INVENTORY_DIR="${HOME}/inventories/localhost" + INVENTORY_DIR="${HOME}/inventories/localhost" fi # IMPORTANT: single-line output for Makefile $(shell ...) diff --git a/scripts/lint/README.md b/scripts/lint/README.md new file mode 100644 index 0000000000..4a6f29322c --- /dev/null +++ b/scripts/lint/README.md @@ -0,0 +1,10 @@ +# Lint Scripts + +This directory contains scripts that run repository lint checks. + +- 🧹 Execute focused lint checks for workflows, Ansible, Python, and shell scripts +- πŸ”Ž Keep lint entry points small, explicit, and callable from `make` +- βœ… Separate lint execution from tool installation and environment bootstrap + +The scope of this folder is lint execution. +Tool installation belongs in `scripts/install`, while build and test workflows should stay in their dedicated script directories. diff --git a/scripts/lint/action.sh b/scripts/lint/action.sh new file mode 100755 index 0000000000..2aa82bcbf1 --- /dev/null +++ b/scripts/lint/action.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# shellcheck shell=bash + +set -euo pipefail + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd -- "${SCRIPT_DIR}/../.." && pwd)" + +cd "${REPO_ROOT}" + +actionlint diff --git a/scripts/lint/ansible.sh b/scripts/lint/ansible.sh new file mode 100755 index 0000000000..4f44173ebf --- /dev/null +++ b/scripts/lint/ansible.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# shellcheck shell=bash + +set -euo pipefail + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd -- "${SCRIPT_DIR}/../.." && pwd)" + +cd "${REPO_ROOT}" + +ANSIBLE_LOCAL_TEMP="${TMPDIR:-/tmp}/infinito-ansible-local-tmp" +mkdir -p "${ANSIBLE_LOCAL_TEMP}" +export ANSIBLE_LOCAL_TEMP + +ansible_args=(-i localhost -c local) +while IFS= read -r group_var_file; do + ansible_args+=(-e "@${group_var_file}") +done < <(find group_vars/all -type f -name '*.yml' | sort) +ansible_args+=(playbook.yml --syntax-check) + +ansible-playbook "${ansible_args[@]}" diff --git a/scripts/lint/python.sh b/scripts/lint/python.sh new file mode 100755 index 0000000000..b26e3a647e --- /dev/null +++ b/scripts/lint/python.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# shellcheck shell=bash + +set -euo pipefail + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd -- "${SCRIPT_DIR}/../.." && pwd)" + +cd "${REPO_ROOT}" + +shfmt -w scripts +ruff format . +ruff check . --fix diff --git a/scripts/lint/shellcheck.sh b/scripts/lint/shellcheck.sh new file mode 100755 index 0000000000..37a8637e29 --- /dev/null +++ b/scripts/lint/shellcheck.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# shellcheck shell=bash + +set -euo pipefail + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd -- "${SCRIPT_DIR}/../.." && pwd)" + +cd "${REPO_ROOT}" + +mapfile -t shellcheck_files < <(find . -type f -name '*.sh' 2>/dev/null | sort) +if [[ "${#shellcheck_files[@]}" -eq 0 ]]; then + printf 'No shell scripts found.\n' + exit 0 +fi + +diff_file="$(mktemp)" +cleanup() { + rm -f "${diff_file}" +} +trap cleanup EXIT + +set +e +shellcheck -f diff -x "${shellcheck_files[@]}" >"${diff_file}" 2>/dev/null +set -e + +if [[ -s "${diff_file}" ]]; then + printf 'Applying ShellCheck autofixes.\n' + git apply --whitespace=nowarn "${diff_file}" +fi + +shellcheck -x "${shellcheck_files[@]}" diff --git a/scripts/meta/env.sh b/scripts/meta/env.sh index 9262607038..6089348477 100644 --- a/scripts/meta/env.sh +++ b/scripts/meta/env.sh @@ -14,7 +14,7 @@ set -euo pipefail # Prevent double-loading if [[ "${INFINITO_ENV_LOADED:-}" == "1" ]]; then - return 0 + return 0 fi export INFINITO_ENV_LOADED="1" @@ -29,9 +29,9 @@ _is_true() { [[ "${1:-}" == "1" || "${1:-}" == "true" ]]; } _virtual_env="${VIRTUAL_ENV:-}" if [[ -n "${_virtual_env}" ]]; then - : "${VENV_BASE:=${VENV_BASE:-$(dirname "${_virtual_env}")/}}" + : "${VENV_BASE:=${VENV_BASE:-$(dirname "${_virtual_env}")/}}" else - : "${VENV_BASE:=${VENV_BASE:-/opt/venvs}}" + : "${VENV_BASE:=${VENV_BASE:-/opt/venvs}}" fi : "${VENV_NAME:=infinito}" @@ -40,9 +40,9 @@ fi _default_python="${VENV%/}/bin/python" if [[ -x "${_default_python}" ]]; then - : "${PYTHON:=${_default_python}}" + : "${PYTHON:=${_default_python}}" else - : "${PYTHON:=python3}" + : "${PYTHON:=python3}" fi : "${PIP:=${PYTHON} -m pip}" @@ -61,11 +61,11 @@ export PYTHONPATH : "${RUNNING_ON_GITHUB:=false}" if [[ "${GITHUB_ACTIONS:-}" == "true" ]]; then - RUNNING_ON_GITHUB="true" - if [[ "${ACT:-}" == "true" ]]; then - RUNNING_ON_ACT="true" - RUNNING_ON_GITHUB="false" - fi + RUNNING_ON_GITHUB="true" + if [[ "${ACT:-}" == "true" ]]; then + RUNNING_ON_ACT="true" + RUNNING_ON_GITHUB="false" + fi fi export RUNNING_ON_ACT RUNNING_ON_GITHUB @@ -91,12 +91,12 @@ export DISTROS # Inventory dir (needs resolve script) # ------------------------------------------------------------ if [[ -z "${INVENTORY_DIR:-}" ]]; then - INVENTORY_DIR="$( - RUNNING_ON_ACT="${RUNNING_ON_ACT}" \ - RUNNING_ON_GITHUB="${RUNNING_ON_GITHUB}" \ - HOME="${HOME:-}" \ - bash scripts/inventory/resolve.sh - )" + INVENTORY_DIR="$( + RUNNING_ON_ACT="${RUNNING_ON_ACT}" \ + RUNNING_ON_GITHUB="${RUNNING_ON_GITHUB}" \ + HOME="${HOME:-}" \ + bash scripts/inventory/resolve.sh + )" fi export INVENTORY_DIR @@ -104,27 +104,27 @@ export INVENTORY_DIR # GitHub CI overrides # ------------------------------------------------------------ if [[ "${RUNNING_ON_GITHUB}" == "true" ]]; then - : "${INFINITO_PULL_POLICY:=always}" - : "${INFINITO_IMAGE_TAG:=latest}" + : "${INFINITO_PULL_POLICY:=always}" + : "${INFINITO_IMAGE_TAG:=latest}" - # Owner can come from GitHub Actions or be provided explicitly (fallback). - _owner="${GITHUB_REPOSITORY_OWNER:-${OWNER:-}}" - : "${INFINITO_IMAGE:=ghcr.io/${_owner}/infinito-${INFINITO_DISTRO}:${INFINITO_IMAGE_TAG}}" + # Owner can come from GitHub Actions or be provided explicitly (fallback). + _owner="${GITHUB_REPOSITORY_OWNER:-${OWNER:-}}" + : "${INFINITO_IMAGE:=ghcr.io/${_owner}/infinito-${INFINITO_DISTRO}:${INFINITO_IMAGE_TAG}}" - : "${INFINITO_NO_BUILD:=1}" - : "${INFINITO_DOCKER_VOLUME:=/mnt/docker}" - : "${INFINITO_DOCKER_MOUNT:=/var/lib/docker}" - : "${INFINITO_COMPILE:=0}" + : "${INFINITO_NO_BUILD:=1}" + : "${INFINITO_DOCKER_VOLUME:=/mnt/docker}" + : "${INFINITO_DOCKER_MOUNT:=/var/lib/docker}" + : "${INFINITO_COMPILE:=0}" - export INFINITO_PULL_POLICY INFINITO_IMAGE_TAG INFINITO_IMAGE INFINITO_NO_BUILD - export INFINITO_DOCKER_VOLUME INFINITO_DOCKER_MOUNT - export INFINITO_COMPILE + export INFINITO_PULL_POLICY INFINITO_IMAGE_TAG INFINITO_IMAGE INFINITO_NO_BUILD + export INFINITO_DOCKER_VOLUME INFINITO_DOCKER_MOUNT + export INFINITO_COMPILE else - : "${INFINITO_COMPILE:=1}" - export INFINITO_COMPILE + : "${INFINITO_COMPILE:=1}" + export INFINITO_COMPILE fi # NIX_CONFIG is optional; export if set if [[ -n "${NIX_CONFIG:-}" ]]; then - export NIX_CONFIG + export NIX_CONFIG fi diff --git a/scripts/meta/resolve/apps.sh b/scripts/meta/resolve/apps.sh index 343e3f4e45..aa56347fc8 100755 --- a/scripts/meta/resolve/apps.sh +++ b/scripts/meta/resolve/apps.sh @@ -24,8 +24,8 @@ cd "$REPO_ROOT" # Load default environment (safe if already loaded via BASH_ENV) # ------------------------------------------------------------ if [[ -f "scripts/meta/env.sh" ]]; then - # shellcheck source=scripts/meta/env.sh - source "scripts/meta/env.sh" + # shellcheck source=scripts/meta/env.sh + source "scripts/meta/env.sh" fi # ------------------------------------------------------------ @@ -33,32 +33,32 @@ fi # ------------------------------------------------------------ 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' + # 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))' + # 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))' + # 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))' } # ------------------------------------------------------------ @@ -70,58 +70,58 @@ lifecycles_args=(--lifecycles alpha beta rc stable) # 1) Get JSON list from container (keep as JSON) # ------------------------------------------------------------ apps_json="$( - docker compose --profile ci exec -T infinito \ - "${PYTHON}" -m cli.meta.applications.type \ - --format json \ - --type "${TEST_DEPLOY_TYPE}" \ - "${lifecycles_args[@]}" \ - | json_compact_array + docker compose --profile ci exec -T infinito \ + "${PYTHON}" -m cli.meta.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)$' + 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" + 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) - docker compose --profile ci exec -T infinito \ - "${PYTHON}" -m cli.meta.applications.sufficient_storage \ - --roles "${roles[@]}" \ - --required-storage "${required_storage}" \ - --warnings \ - --format json \ - >/dev/null || true + # 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) + docker compose --profile ci exec -T infinito \ + "${PYTHON}" -m cli.meta.applications.sufficient_storage \ + --roles "${roles[@]}" \ + --required-storage "${required_storage}" \ + --warnings \ + --format json \ + >/dev/null || true - # Real filter (JSON output) - apps_json="$( - docker compose --profile ci exec -T infinito \ - "${PYTHON}" -m cli.meta.applications.sufficient_storage \ - --roles "${roles[@]}" \ - --required-storage "${required_storage}" \ - --format json \ - | json_compact_array - )" - fi + # Real filter (JSON output) + apps_json="$( + docker compose --profile ci exec -T infinito \ + "${PYTHON}" -m cli.meta.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:-}" + printf '%s\n' "${apps_json}" | + jq_whitelist_filter "${WHITELIST:-}" )" # ------------------------------------------------------------ diff --git a/scripts/meta/resolve/input.sh b/scripts/meta/resolve/input.sh index b3f04314a4..0354ce5af2 100755 --- a/scripts/meta/resolve/input.sh +++ b/scripts/meta/resolve/input.sh @@ -29,19 +29,19 @@ DISTROS="${DISTROS:-${INPUT_DISTROS:-}}" # WHITELIST must always exist, but may be empty WHITELIST="${WHITELIST:-${INPUT_WHITELIST:-}}" -WHITELIST="${WHITELIST:-}" # force defined even if still empty +WHITELIST="${WHITELIST:-}" # force defined even if still empty # Hard requirements : "${TEST_DEPLOY_TYPE:?TEST_DEPLOY_TYPE must be set (server|workstation|universal)}" : "${DISTROS:?DISTROS must be set (e.g. \"arch debian ubuntu\")}" case "${TEST_DEPLOY_TYPE}" in - server|workstation|universal) ;; - *) - echo "Invalid TEST_DEPLOY_TYPE: ${TEST_DEPLOY_TYPE}" >&2 - echo "Allowed: server | workstation | universal" >&2 - exit 2 - ;; +server | workstation | universal) ;; +*) + echo "Invalid TEST_DEPLOY_TYPE: ${TEST_DEPLOY_TYPE}" >&2 + echo "Allowed: server | workstation | universal" >&2 + exit 2 + ;; esac echo "Resolved inputs:" @@ -51,14 +51,14 @@ echo " WHITELIST=${WHITELIST}" # Export outputs for workflow { - echo "test_deploy_type=${TEST_DEPLOY_TYPE}" - echo "distros=${DISTROS}" - echo "whitelist=${WHITELIST}" -} >> "${GITHUB_OUTPUT}" + echo "test_deploy_type=${TEST_DEPLOY_TYPE}" + echo "distros=${DISTROS}" + echo "whitelist=${WHITELIST}" +} >>"${GITHUB_OUTPUT}" # Export env for subsequent steps { - echo "TEST_DEPLOY_TYPE=${TEST_DEPLOY_TYPE}" - echo "DISTROS=${DISTROS}" - echo "WHITELIST=${WHITELIST}" -} >> "${GITHUB_ENV}" + echo "TEST_DEPLOY_TYPE=${TEST_DEPLOY_TYPE}" + echo "DISTROS=${DISTROS}" + echo "WHITELIST=${WHITELIST}" +} >>"${GITHUB_ENV}" diff --git a/scripts/meta/resolve/pr_merge_ref.sh b/scripts/meta/resolve/pr_merge_ref.sh index ac9e00501d..0c3431b7f9 100755 --- a/scripts/meta/resolve/pr_merge_ref.sh +++ b/scripts/meta/resolve/pr_merge_ref.sh @@ -12,33 +12,33 @@ remote_sha="$(git ls-remote "${repo_url}" "${ref}" | awk 'NR==1 {print $1}')" sha="" if [[ -n "${payload_sha}" && ! "${payload_sha}" =~ ^[0-9a-f]{40}$ ]]; then - echo "Invalid PR_MERGE_SHA '${payload_sha}', ignoring event payload." >&2 - payload_sha="" + echo "Invalid PR_MERGE_SHA '${payload_sha}', ignoring event payload." >&2 + payload_sha="" fi if [[ -n "${remote_sha}" && ! "${remote_sha}" =~ ^[0-9a-f]{40}$ ]]; then - echo "Invalid remote merge SHA '${remote_sha}' for ${ref}, ignoring live ref." >&2 - remote_sha="" + echo "Invalid remote merge SHA '${remote_sha}' for ${ref}, ignoring live ref." >&2 + remote_sha="" fi if [[ -n "${remote_sha}" ]]; then - sha="${remote_sha}" - if [[ -n "${payload_sha}" && "${payload_sha}" != "${remote_sha}" ]]; then - echo "Event merge SHA ${payload_sha} differs from live ${ref} (${remote_sha}); using live ref." >&2 - fi + sha="${remote_sha}" + if [[ -n "${payload_sha}" && "${payload_sha}" != "${remote_sha}" ]]; then + echo "Event merge SHA ${payload_sha} differs from live ${ref} (${remote_sha}); using live ref." >&2 + fi elif [[ -n "${payload_sha}" ]]; then - sha="${payload_sha}" - echo "Falling back to event merge SHA ${payload_sha} because ${ref} could not be resolved live." >&2 + sha="${payload_sha}" + echo "Falling back to event merge SHA ${payload_sha} because ${ref} could not be resolved live." >&2 else - echo "Failed to resolve merge SHA for ${ref}" >&2 - exit 1 + echo "Failed to resolve merge SHA for ${ref}" >&2 + exit 1 fi checkout_ref="${sha}" { - echo "checkout_ref=${checkout_ref}" - echo "image_tag=ci-${sha}" -} >> "${GITHUB_OUTPUT}" + echo "checkout_ref=${checkout_ref}" + echo "image_tag=ci-${sha}" +} >>"${GITHUB_OUTPUT}" echo "Resolved fork PR merge ref ${ref} -> ${sha} (checkout_ref=${checkout_ref})" diff --git a/scripts/meta/wait/image.sh b/scripts/meta/wait/image.sh index 51347153f1..62a3042a97 100755 --- a/scripts/meta/wait/image.sh +++ b/scripts/meta/wait/image.sh @@ -16,26 +16,26 @@ echo "Fork pull_request detected; waiting for image built via pull_request_targe echo " ${image}" if [[ -n "${pr_number}" && -n "${GITHUB_REPOSITORY:-}" ]]; then - ref="refs/pull/${pr_number}/merge" - repo_url="https://github.com/${GITHUB_REPOSITORY}.git" - current_sha="$(git ls-remote "${repo_url}" "${ref}" | awk 'NR==1 {print $1}')" - if [[ "${current_sha}" =~ ^[0-9a-f]{40}$ ]]; then - current_tag="ci-${current_sha}" - if [[ "${current_tag}" != "${IMAGE_TAG}" ]]; then - echo "This pull_request run is stale: expected ${IMAGE_TAG}, but current ${ref} resolves to ${current_tag}." >&2 - echo "Re-run the latest pull_request workflow for this PR instead of re-running an older run." >&2 - exit 1 - fi - fi + ref="refs/pull/${pr_number}/merge" + repo_url="https://github.com/${GITHUB_REPOSITORY}.git" + current_sha="$(git ls-remote "${repo_url}" "${ref}" | awk 'NR==1 {print $1}')" + if [[ "${current_sha}" =~ ^[0-9a-f]{40}$ ]]; then + current_tag="ci-${current_sha}" + if [[ "${current_tag}" != "${IMAGE_TAG}" ]]; then + echo "This pull_request run is stale: expected ${IMAGE_TAG}, but current ${ref} resolves to ${current_tag}." >&2 + echo "Re-run the latest pull_request workflow for this PR instead of re-running an older run." >&2 + exit 1 + fi + fi fi for attempt in $(seq 1 "${max_attempts}"); do - if docker buildx imagetools inspect "${image}" >/dev/null 2>&1; then - echo "Image is available: ${image}" - exit 0 - fi - echo "[${attempt}/${max_attempts}] Waiting for image..." - sleep "${sleep_seconds}" + if docker buildx imagetools inspect "${image}" >/dev/null 2>&1; then + echo "Image is available: ${image}" + exit 0 + fi + echo "[${attempt}/${max_attempts}] Waiting for image..." + sleep "${sleep_seconds}" done echo "Timed out waiting for prebuilt image: ${image}" >&2 diff --git a/scripts/meta/wait/mirrors.sh b/scripts/meta/wait/mirrors.sh index f4452108b1..07354db651 100755 --- a/scripts/meta/wait/mirrors.sh +++ b/scripts/meta/wait/mirrors.sh @@ -11,10 +11,10 @@ max_attempts="${IMAGE_WAIT_ATTEMPTS}" sleep_seconds="${IMAGE_WAIT_SLEEP_SECONDS}" mapfile -t mirror_refs < <( - GHCR_NAMESPACE="${GHCR_NAMESPACE}" \ - GHCR_PREFIX="${GHCR_PREFIX}" \ - REPO_ROOT="${REPO_ROOT}" \ - python - <<'PY' + GHCR_NAMESPACE="${GHCR_NAMESPACE}" \ + GHCR_PREFIX="${GHCR_PREFIX}" \ + REPO_ROOT="${REPO_ROOT}" \ + python - <<'PY' import os from pathlib import Path from cli.mirror.providers import GHCRProvider @@ -38,8 +38,8 @@ PY total="${#mirror_refs[@]}" if [[ "${total}" -eq 0 ]]; then - echo "No mirror refs found. Nothing to wait for." - exit 0 + echo "No mirror refs found. Nothing to wait for." + exit 0 fi echo "Fork pull_request detected; waiting for mirrored images from pull_request_target." @@ -47,26 +47,26 @@ echo "Need ${total} mirror refs." missing=() for attempt in $(seq 1 "${max_attempts}"); do - missing=() - for ref in "${mirror_refs[@]}"; do - if ! skopeo inspect "docker://${ref}" >/dev/null 2>&1; then - missing+=("${ref}") - fi - done + missing=() + for ref in "${mirror_refs[@]}"; do + if ! skopeo inspect "docker://${ref}" >/dev/null 2>&1; then + missing+=("${ref}") + fi + done - if [[ "${#missing[@]}" -eq 0 ]]; then - echo "All mirrored images are available." - exit 0 - fi + if [[ "${#missing[@]}" -eq 0 ]]; then + echo "All mirrored images are available." + exit 0 + fi - echo "[${attempt}/${max_attempts}] Missing ${#missing[@]}/${total} mirror refs. Waiting ${sleep_seconds}s..." - echo "Example missing: ${missing[0]}" - sleep "${sleep_seconds}" + echo "[${attempt}/${max_attempts}] Missing ${#missing[@]}/${total} mirror refs. Waiting ${sleep_seconds}s..." + echo "Example missing: ${missing[0]}" + sleep "${sleep_seconds}" done echo "Timed out waiting for mirrored images." >&2 echo "Still missing (first 20):" >&2 for ref in "${missing[@]:0:20}"; do - echo " - ${ref}" >&2 + echo " - ${ref}" >&2 done exit 1 diff --git a/scripts/setup.sh b/scripts/setup.sh index 31335814d5..fb4e12ec77 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -13,7 +13,7 @@ echo "πŸ”§ Running project setup (no installation)" # Optional: show interpreter for debugging echo "🐍 Using PYTHON=${PYTHON}" if command -v "${PYTHON}" >/dev/null 2>&1; then - "${PYTHON}" -c 'import sys; print("sys.executable=", sys.executable)' || true + "${PYTHON}" -c 'import sys; print("sys.executable=", sys.executable)' || true fi ROLES_DIR="./roles" @@ -31,17 +31,26 @@ INCLUDES_OUT_DIR="./tasks/groups" # Validation # ------------------------------------------------------------ require_file() { - local path="$1" - [[ -f "$path" ]] || { echo "❌ File not found: $path" >&2; exit 1; } + local path="$1" + [[ -f "$path" ]] || { + echo "❌ File not found: $path" >&2 + exit 1 + } } require_dir() { - local path="$1" - [[ -d "$path" ]] || { echo "❌ Directory not found: $path" >&2; exit 1; } + local path="$1" + [[ -d "$path" ]] || { + echo "❌ Directory not found: $path" >&2 + exit 1 + } } require_cmd() { - command -v "$1" >/dev/null || { echo "❌ Command not found: $1" >&2; exit 1; } + command -v "$1" >/dev/null || { + echo "❌ Command not found: $1" >&2 + exit 1 + } } require_cmd "${PYTHON}" @@ -54,18 +63,18 @@ require_file "${INCLUDES_SCRIPT}" # Helpers # ------------------------------------------------------------ log_section() { - echo - echo "------------------------------------------------------------" - echo "$1" - echo "------------------------------------------------------------" + echo + echo "------------------------------------------------------------" + echo "$1" + echo "------------------------------------------------------------" } compute_reserved_usernames() { - find "${ROLES_DIR}" -maxdepth 1 -mindepth 1 -type d -printf '%f\n' \ - | sed -E 's/.*-//' \ - | grep -E -x '[a-z0-9]+' \ - | sort -u \ - | paste -sd, - + find "${ROLES_DIR}" -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | + sed -E 's/.*-//' | + grep -E -x '[a-z0-9]+' | + sort -u | + paste -sd, - } # ------------------------------------------------------------ @@ -80,9 +89,9 @@ echo "Reserved usernames: ${RESERVED_USERNAMES:-}" # ------------------------------------------------------------ log_section "πŸ‘₯ Generating users defaults β†’ ${USERS_OUT}" "${PYTHON}" "${USERS_SCRIPT}" \ - --roles-dir "${ROLES_DIR}" \ - --output "${USERS_OUT}" \ - --reserved-usernames "${RESERVED_USERNAMES}" + --roles-dir "${ROLES_DIR}" \ + --output "${USERS_OUT}" \ + --reserved-usernames "${RESERVED_USERNAMES}" echo "βœ… Users defaults written to ${USERS_OUT}" @@ -91,8 +100,8 @@ echo "βœ… Users defaults written to ${USERS_OUT}" # ------------------------------------------------------------ log_section "πŸ“¦ Generating applications defaults β†’ ${APPLICATIONS_OUT}" "${PYTHON}" "${APPLICATIONS_SCRIPT}" \ - --roles-dir "${ROLES_DIR}" \ - --output-file "${APPLICATIONS_OUT}" + --roles-dir "${ROLES_DIR}" \ + --output-file "${APPLICATIONS_OUT}" echo "βœ… Applications defaults written to ${APPLICATIONS_OUT}" @@ -105,11 +114,11 @@ mkdir -p "${INCLUDES_OUT_DIR}" mapfile -t INCLUDE_GROUPS < <("${PYTHON}" -m cli.meta.categories.invokable -s "-") for grp in "${INCLUDE_GROUPS[@]}"; do - [[ -z "${grp}" ]] && continue - out="${INCLUDES_OUT_DIR}/${grp}roles.yml" - echo "β†’ Building ${out} (pattern: '${grp}')" - "${PYTHON}" "${INCLUDES_SCRIPT}" "${ROLES_DIR}" -p "${grp}" -o "${out}" - echo " βœ… ${out}" + [[ -z "${grp}" ]] && continue + out="${INCLUDES_OUT_DIR}/${grp}roles.yml" + echo "β†’ Building ${out} (pattern: '${grp}')" + "${PYTHON}" "${INCLUDES_SCRIPT}" "${ROLES_DIR}" -p "${grp}" -o "${out}" + echo " βœ… ${out}" done echo diff --git a/scripts/tests/code.sh b/scripts/tests/code.sh index 829a9ace66..1d289d98d1 100755 --- a/scripts/tests/code.sh +++ b/scripts/tests/code.sh @@ -11,12 +11,12 @@ echo "============================================================" # Execute directly inside the already running infinito container INFINITO_DISTRO="${INFINITO_DISTRO}" \ -docker compose --profile ci exec -T \ - -e TEST_PATTERN="${TEST_PATTERN}" \ - -e TEST_TYPE="${TEST_TYPE}" \ - --workdir /opt/src/infinito \ - infinito \ - bash -lc ' + docker compose --profile ci exec -T \ + -e TEST_PATTERN="${TEST_PATTERN}" \ + -e TEST_TYPE="${TEST_TYPE}" \ + --workdir /opt/src/infinito \ + infinito \ + bash -lc ' set -euo pipefail NIX_CONFIG_EFFECTIVE="$( diff --git a/scripts/tests/deploy/act/all.sh b/scripts/tests/deploy/act/all.sh index 4166644775..1bcef8e6f0 100755 --- a/scripts/tests/deploy/act/all.sh +++ b/scripts/tests/deploy/act/all.sh @@ -10,20 +10,20 @@ set -euo pipefail : "${INFINITO_DISTRO:?INFINITO_DISTRO is not set (e.g. arch, debian, ubuntu)}" case "${TEST_DEPLOY_TYPE}" in - server|workstation|universal) ;; - *) - echo "Invalid TEST_DEPLOY_TYPE: ${TEST_DEPLOY_TYPE}" >&2 - echo "Allowed: server | workstation | universal" >&2 - exit 2 - ;; +server | workstation | universal) ;; +*) + echo "Invalid TEST_DEPLOY_TYPE: ${TEST_DEPLOY_TYPE}" >&2 + echo "Allowed: server | workstation | universal" >&2 + exit 2 + ;; esac echo "=== act: deploy local (type=${TEST_DEPLOY_TYPE}, distros=${INFINITO_DISTRO}) ===" act workflow_dispatch \ - -W .github/workflows/test-deploy-local.yml \ - --input test_deploy_type="${TEST_DEPLOY_TYPE}" \ - --input distros="${INFINITO_DISTRO}" \ - --input whitelist="" \ - --container-options "--privileged" \ - --network host + -W .github/workflows/test-deploy-local.yml \ + --input test_deploy_type="${TEST_DEPLOY_TYPE}" \ + --input distros="${INFINITO_DISTRO}" \ + --input whitelist="" \ + --container-options "--privileged" \ + --network host diff --git a/scripts/tests/deploy/act/app.sh b/scripts/tests/deploy/act/app.sh index bec778a715..fb818a25e6 100755 --- a/scripts/tests/deploy/act/app.sh +++ b/scripts/tests/deploy/act/app.sh @@ -12,20 +12,20 @@ set -euo pipefail : "${INFINITO_DISTRO:?INFINITO_DISTRO is not set (e.g. arch, debian, ubuntu)}" case "${TEST_DEPLOY_TYPE}" in - server|workstation|universal) ;; - *) - echo "Invalid TEST_DEPLOY_TYPE: ${TEST_DEPLOY_TYPE}" >&2 - echo "Allowed: server | workstation | universal" >&2 - exit 2 - ;; +server | workstation | universal) ;; +*) + echo "Invalid TEST_DEPLOY_TYPE: ${TEST_DEPLOY_TYPE}" >&2 + echo "Allowed: server | workstation | universal" >&2 + exit 2 + ;; esac echo "=== act: deploy local (type=${TEST_DEPLOY_TYPE}, app=${APP}, distros=${INFINITO_DISTRO}) ===" act workflow_dispatch \ - -W .github/workflows/test-deploy-local.yml \ - --input test_deploy_type="${TEST_DEPLOY_TYPE}" \ - --input distros="${INFINITO_DISTRO}" \ - --input whitelist="${APP}" \ - --container-options "--privileged" \ - --network host + -W .github/workflows/test-deploy-local.yml \ + --input test_deploy_type="${TEST_DEPLOY_TYPE}" \ + --input distros="${INFINITO_DISTRO}" \ + --input whitelist="${APP}" \ + --container-options "--privileged" \ + --network host diff --git a/scripts/tests/deploy/ci/all_distros.sh b/scripts/tests/deploy/ci/all_distros.sh index e6fa79f3b0..0b6216f924 100755 --- a/scripts/tests/deploy/ci/all_distros.sh +++ b/scripts/tests/deploy/ci/all_distros.sh @@ -28,102 +28,102 @@ PYTHON="${PYTHON:-python3}" MAX_TOTAL_SECONDS="${MAX_TOTAL_SECONDS:-}" if [[ -n "${MAX_TOTAL_SECONDS}" ]]; then - if ! [[ "${MAX_TOTAL_SECONDS}" =~ ^[0-9]+$ ]]; then - echo "[ERROR] MAX_TOTAL_SECONDS must be an integer (seconds), got: '${MAX_TOTAL_SECONDS}'" >&2 - exit 2 - fi + if ! [[ "${MAX_TOTAL_SECONDS}" =~ ^[0-9]+$ ]]; then + echo "[ERROR] MAX_TOTAL_SECONDS must be an integer (seconds), got: '${MAX_TOTAL_SECONDS}'" >&2 + exit 2 + fi fi SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "${SCRIPT_DIR}/../../../.." && pwd)" cd "${REPO_ROOT}" -read -r -a distro_arr <<< "${DISTROS}" +read -r -a distro_arr <<<"${DISTROS}" mapfile -t distro_arr < <(printf '%s\n' "${distro_arr[@]}" | shuf) echo "=== Distro execution order: ${distro_arr[*]} ===" global_start="$(date +%s)" deadline="" if [[ -n "${MAX_TOTAL_SECONDS}" ]]; then - deadline="$((global_start + MAX_TOTAL_SECONDS))" - echo "=== Global time budget enabled: ${MAX_TOTAL_SECONDS}s (deadline epoch=${deadline}) ===" + deadline="$((global_start + MAX_TOTAL_SECONDS))" + echo "=== Global time budget enabled: ${MAX_TOTAL_SECONDS}s (deadline epoch=${deadline}) ===" else - echo "=== Global time budget disabled (set MAX_TOTAL_SECONDS to enable) ===" + echo "=== Global time budget disabled (set MAX_TOTAL_SECONDS to enable) ===" fi max_seen=0 skipped=0 ran=0 failed=0 -durations=() # store "distro=seconds" lines +durations=() # store "distro=seconds" lines sync_ci_image_for_distro() { - local owner tag + local owner tag - owner="${GITHUB_REPOSITORY_OWNER:-${OWNER:-}}" - tag="${INFINITO_IMAGE_TAG:-latest}" + owner="${GITHUB_REPOSITORY_OWNER:-${OWNER:-}}" + tag="${INFINITO_IMAGE_TAG:-latest}" - # Keep local/dev workflows untouched; only adjust image when CI owner context exists. - if [[ -z "${owner}" ]]; then - return 0 - fi + # Keep local/dev workflows untouched; only adjust image when CI owner context exists. + if [[ -z "${owner}" ]]; then + return 0 + fi - export INFINITO_IMAGE="ghcr.io/${owner}/infinito-${INFINITO_DISTRO}:${tag}" - echo ">>> CI image synced: ${INFINITO_IMAGE}" + export INFINITO_IMAGE="ghcr.io/${owner}/infinito-${INFINITO_DISTRO}:${tag}" + echo ">>> CI image synced: ${INFINITO_IMAGE}" } for distro in "${distro_arr[@]}"; do - now="$(date +%s)" - remaining="" + now="$(date +%s)" + remaining="" - if [[ -n "${deadline}" ]]; then - remaining="$((deadline - now))" + if [[ -n "${deadline}" ]]; then + remaining="$((deadline - now))" - if (( remaining <= 0 )); then - echo "[WARN] Global budget exhausted (remaining=${remaining}s). Stopping further distro runs." - break - fi + if ((remaining <= 0)); then + echo "[WARN] Global budget exhausted (remaining=${remaining}s). Stopping further distro runs." + break + fi - # Skip logic: only if we already have a max_seen from a prior run - if (( max_seen > 0 && remaining < max_seen )); then - echo "[WARN] Skipping distro=${distro}: remaining=${remaining}s < max_seen=${max_seen}s (fast-fail heuristic)" - skipped=$((skipped + 1)) - continue - fi - fi + # Skip logic: only if we already have a max_seen from a prior run + if ((max_seen > 0 && remaining < max_seen)); then + echo "[WARN] Skipping distro=${distro}: remaining=${remaining}s < max_seen=${max_seen}s (fast-fail heuristic)" + skipped=$((skipped + 1)) + continue + fi + fi - echo "=== Running dedicated distro deploy: distro=${distro} app=${APP} type=${TEST_DEPLOY_TYPE} ===" - if [[ -n "${remaining}" ]]; then - echo ">>> Time budget: remaining=${remaining}s max_seen=${max_seen}s" - fi + echo "=== Running dedicated distro deploy: distro=${distro} app=${APP} type=${TEST_DEPLOY_TYPE} ===" + if [[ -n "${remaining}" ]]; then + echo ">>> Time budget: remaining=${remaining}s max_seen=${max_seen}s" + fi - export INFINITO_DISTRO="${distro}" - sync_ci_image_for_distro + export INFINITO_DISTRO="${distro}" + sync_ci_image_for_distro - distro_start="$(date +%s)" + distro_start="$(date +%s)" - set +e - scripts/tests/deploy/ci/dedicated_distro.sh \ - --app "${APP}" - rc=$? - set -e + set +e + scripts/tests/deploy/ci/dedicated_distro.sh \ + --app "${APP}" + rc=$? + set -e - distro_end="$(date +%s)" - dur="$((distro_end - distro_start))" - durations+=("${distro}=${dur}s") - ran=$((ran + 1)) + distro_end="$(date +%s)" + dur="$((distro_end - distro_start))" + durations+=("${distro}=${dur}s") + ran=$((ran + 1)) - if (( dur > max_seen )); then - max_seen="$dur" - fi + if ((dur > max_seen)); then + max_seen="$dur" + fi - echo ">>> Duration: distro=${distro} took ${dur}s (max_seen=${max_seen}s)" + echo ">>> Duration: distro=${distro} took ${dur}s (max_seen=${max_seen}s)" - if [[ $rc -ne 0 ]]; then - echo "[ERROR] Deploy failed for distro=${distro} app=${APP} (rc=${rc})" >&2 - failed=$((failed + 1)) - exit "$rc" - fi + if [[ $rc -ne 0 ]]; then + echo "[ERROR] Deploy failed for distro=${distro} app=${APP} (rc=${rc})" >&2 + failed=$((failed + 1)) + exit "$rc" + fi done global_end="$(date +%s)" @@ -135,11 +135,11 @@ echo "app=${APP} type=${TEST_DEPLOY_TYPE}" echo "ran=${ran} skipped=${skipped} failed=${failed}" echo "total_runtime=${total}s max_seen_distro=${max_seen}s" if [[ -n "${deadline}" ]]; then - now="$(date +%s)" - remaining="$((deadline - now))" - echo "budget=${MAX_TOTAL_SECONDS}s remaining=${remaining}s" + now="$(date +%s)" + remaining="$((deadline - now))" + echo "budget=${MAX_TOTAL_SECONDS}s remaining=${remaining}s" fi echo "per-distro:" for line in "${durations[@]}"; do - echo " - ${line}" + echo " - ${line}" done diff --git a/scripts/tests/deploy/ci/dedicated_distro.sh b/scripts/tests/deploy/ci/dedicated_distro.sh index 32e55ac41c..de02bda67f 100755 --- a/scripts/tests/deploy/ci/dedicated_distro.sh +++ b/scripts/tests/deploy/ci/dedicated_distro.sh @@ -32,7 +32,7 @@ REPO_ROOT="$(cd "${SCRIPT_DIR}/../../../.." && pwd)" APP="" usage() { - cat <<'EOF' + cat <<'EOF' Usage: INFINITO_DISTRO= INVENTORY_DIR= INFINITO_DOCKER_VOLUME= \ scripts/tests/deploy/ci/dedicated_distro.sh \ @@ -41,85 +41,95 @@ EOF } while [[ $# -gt 0 ]]; do - case "$1" in - --app) APP="${2:-}"; shift 2 ;; - -h|--help) usage; exit 0 ;; - *) - echo "[ERROR] Unknown argument: $1" >&2 - usage - exit 2 - ;; - esac + case "$1" in + --app) + APP="${2:-}" + shift 2 + ;; + -h | --help) + usage + exit 0 + ;; + *) + echo "[ERROR] Unknown argument: $1" >&2 + usage + exit 2 + ;; + esac done -[[ -n "${APP}" ]] || { echo "[ERROR] --app is required" >&2; usage; exit 2; } +[[ -n "${APP}" ]] || { + echo "[ERROR] --app is required" >&2 + usage + exit 2 +} cd "${REPO_ROOT}" echo "=== distro=${INFINITO_DISTRO} app=${APP} (debug always on) ===" cleanup() { - rc=$? + rc=$? - echo ">>> Removing stack for distro ${INFINITO_DISTRO} (fresh start for next distro)" - "${PYTHON}" -m cli.deploy.development down --distro "${INFINITO_DISTRO}" || true + echo ">>> Removing stack for distro ${INFINITO_DISTRO} (fresh start for next distro)" + "${PYTHON}" -m cli.deploy.development down --distro "${INFINITO_DISTRO}" || true - echo ">>> HARD cleanup (containers/volumes/networks/images/build-cache)" - echo ">>> Docker disk usage before HARD cleanup" - docker system df || true + echo ">>> HARD cleanup (containers/volumes/networks/images/build-cache)" + echo ">>> Docker disk usage before HARD cleanup" + docker system df || true - # 1) Remove ALL containers (including running ones) - mapfile -t ids < <(docker ps -aq || true) - if (( ${#ids[@]} > 0 )); then - docker rm -f "${ids[@]}" >/dev/null 2>&1 || true - fi + # 1) Remove ALL containers (including running ones) + mapfile -t ids < <(docker ps -aq || true) + if ((${#ids[@]} > 0)); then + docker rm -f "${ids[@]}" >/dev/null 2>&1 || true + fi - # 2) Remove networks (except default ones) - docker network prune -f >/dev/null 2>&1 || true + # 2) Remove networks (except default ones) + docker network prune -f >/dev/null 2>&1 || true - # 3) Remove ALL volumes - docker volume prune -f >/dev/null 2>&1 || true + # 3) Remove ALL volumes + docker volume prune -f >/dev/null 2>&1 || true - # 4) Optional: leftover stopped containers (usually redundant after rm -f) - docker container prune -f >/dev/null 2>&1 || true + # 4) Optional: leftover stopped containers (usually redundant after rm -f) + docker container prune -f >/dev/null 2>&1 || true - # 5) Remove ALL images and build cache. - # Important for serial multi-distro CI runs on the same runner. - docker image prune -af >/dev/null 2>&1 || true - docker buildx prune -af >/dev/null 2>&1 || true - docker builder prune -af >/dev/null 2>&1 || true + # 5) Remove ALL images and build cache. + # Important for serial multi-distro CI runs on the same runner. + docker image prune -af >/dev/null 2>&1 || true + docker buildx prune -af >/dev/null 2>&1 || true + docker builder prune -af >/dev/null 2>&1 || true - # 6) Remove host-mounted Docker data dir (CI runner only) - # IMPORTANT: - # - In CI, Docker/DIND/buildx may create root-owned files under this directory. - # - A plain 'rm -rf' can fail with "Permission denied" and poison the next distro run. - # - Use sudo for a hard reset, then recreate the directory. - if [[ -n "${INFINITO_DOCKER_VOLUME:-}" ]]; then - if [[ "${INFINITO_DOCKER_VOLUME}" == /* ]]; then - echo ">>> CI cleanup: wiping Docker root: ${INFINITO_DOCKER_VOLUME}" + # 6) Remove host-mounted Docker data dir (CI runner only) + # IMPORTANT: + # - In CI, Docker/DIND/buildx may create root-owned files under this directory. + # - A plain 'rm -rf' can fail with "Permission denied" and poison the next distro run. + # - Use sudo for a hard reset, then recreate the directory. + if [[ -n "${INFINITO_DOCKER_VOLUME:-}" ]]; then + if [[ "${INFINITO_DOCKER_VOLUME}" == /* ]]; then + echo ">>> CI cleanup: wiping Docker root: ${INFINITO_DOCKER_VOLUME}" - echo ">>> Pre-clean ownership/permissions (best-effort)" - ls -ld "${INFINITO_DOCKER_VOLUME}" || true - sudo ls -ld "${INFINITO_DOCKER_VOLUME}" || true + echo ">>> Pre-clean ownership/permissions (best-effort)" + ls -ld "${INFINITO_DOCKER_VOLUME}" || true + sudo ls -ld "${INFINITO_DOCKER_VOLUME}" || true - echo ">>> Removing host docker volume dir: ${INFINITO_DOCKER_VOLUME}" - sudo rm -rf "${INFINITO_DOCKER_VOLUME}" || true - sudo mkdir -vp "${INFINITO_DOCKER_VOLUME}" || true + echo ">>> Removing host docker volume dir: ${INFINITO_DOCKER_VOLUME}" + sudo rm -rf "${INFINITO_DOCKER_VOLUME}" || true + sudo mkdir -vp "${INFINITO_DOCKER_VOLUME}" || true - # Optional: keep it writable for the runner user - sudo chown -R "$(id -u):$(id -g)" "${INFINITO_DOCKER_VOLUME}" || true + # Optional: keep it writable for the runner user + sudo chown -R "$(id -u):$(id -g)" "${INFINITO_DOCKER_VOLUME}" || true - echo ">>> Post-clean ownership/permissions (best-effort)" - ls -ld "${INFINITO_DOCKER_VOLUME}" || true - sudo ls -ld "${INFINITO_DOCKER_VOLUME}" || true - else - echo "[WARN] INFINITO_DOCKER_VOLUME is not an absolute path: '${INFINITO_DOCKER_VOLUME}' (skipping)" - fi - fi + echo ">>> Post-clean ownership/permissions (best-effort)" + ls -ld "${INFINITO_DOCKER_VOLUME}" || true + sudo ls -ld "${INFINITO_DOCKER_VOLUME}" || true + else + echo "[WARN] INFINITO_DOCKER_VOLUME is not an absolute path: '${INFINITO_DOCKER_VOLUME}' (skipping)" + fi + fi - echo ">>> Docker disk usage after HARD cleanup" - docker system df || true - echo ">>> HARD cleanup finished" - return $rc + echo ">>> Docker disk usage after HARD cleanup" + docker system df || true + echo ">>> HARD cleanup finished" + return $rc } trap cleanup EXIT @@ -127,13 +137,13 @@ echo ">>> Ensuring stack is up for distro ${INFINITO_DISTRO}" # Always reconcile the stack to the requested distro. # This avoids reusing a pre-started stack with a different INFINITO_DISTRO. "${PYTHON}" -m cli.deploy.development up \ - --distro "${INFINITO_DISTRO}" + --distro "${INFINITO_DISTRO}" deploy_args=( - --distro "${INFINITO_DISTRO}" - --app "${APP}" - --inventory-dir "${INVENTORY_DIR}" - --debug + --distro "${INFINITO_DISTRO}" + --app "${APP}" + --inventory-dir "${INVENTORY_DIR}" + --debug ) echo ">>> DISK / DOCKER STATE BEFORE DEPLOY (distro=${INFINITO_DISTRO})" @@ -143,20 +153,20 @@ echo ">>> END STATE BEFORE DEPLOY" echo ">>> PASS 1: init inventory (ASYNC_ENABLED=false)" "${PYTHON}" -m cli.deploy.development init \ - --distro "${INFINITO_DISTRO}" \ - --app "${APP}" \ - --inventory-dir "${INVENTORY_DIR}" \ - --vars '{"ASYNC_ENABLED": false}' + --distro "${INFINITO_DISTRO}" \ + --app "${APP}" \ + --inventory-dir "${INVENTORY_DIR}" \ + --vars '{"ASYNC_ENABLED": false}' echo ">>> PASS 1: deploy" "${PYTHON}" -m cli.deploy.development deploy "${deploy_args[@]}" echo ">>> PASS 2: re-init inventory (ASYNC_ENABLED=true)" "${PYTHON}" -m cli.deploy.development init \ - --distro "${INFINITO_DISTRO}" \ - --app "${APP}" \ - --inventory-dir "${INVENTORY_DIR}" \ - --vars '{"ASYNC_ENABLED": true}' + --distro "${INFINITO_DISTRO}" \ + --app "${APP}" \ + --inventory-dir "${INVENTORY_DIR}" \ + --vars '{"ASYNC_ENABLED": true}' echo ">>> PASS 2: deploy (skip wrapper cleanup)" "${PYTHON}" -m cli.deploy.development deploy "${deploy_args[@]}" -- --skip-cleanup diff --git a/scripts/tests/deploy/local/all.sh b/scripts/tests/deploy/local/all.sh index bed04af627..b016b44a00 100755 --- a/scripts/tests/deploy/local/all.sh +++ b/scripts/tests/deploy/local/all.sh @@ -28,8 +28,8 @@ echo # --------------------------------------------------------------------------- echo ">>> Starting development compose stack (no build)" "${PYTHON}" -m cli.deploy.development up \ - --distro "${INFINITO_DISTRO}" \ - --skip-entry-init + --distro "${INFINITO_DISTRO}" \ + --skip-entry-init # --------------------------------------------------------------------------- # 2) Discover apps on HOST (needs docker compose) @@ -41,22 +41,22 @@ echo ">>> Discovering apps on host via scripts/meta/resolve/apps.sh (TEST_DEPLOY # - we must guarantee JSON-only output for downstream parsing # - PYTHON from host venv must NOT be used inside container exec calls discover_out="$( - set +e - TEST_DEPLOY_TYPE="${TEST_DEPLOY_TYPE}" \ - WHITELIST="${WHITELIST}" \ - PYTHON=python3 \ - scripts/meta/resolve/apps.sh 2> >(cat >&2) \ - | jq -c 'if type=="array" then . else [] end' 2>/dev/null - echo "rc=$?" >&2 + set +e + TEST_DEPLOY_TYPE="${TEST_DEPLOY_TYPE}" \ + WHITELIST="${WHITELIST}" \ + PYTHON=python3 \ + scripts/meta/resolve/apps.sh 2> >(cat >&2) | + jq -c 'if type=="array" then . else [] end' 2>/dev/null + echo "rc=$?" >&2 )" # Now discover_out should be compact JSON array or empty. if [[ -z "${discover_out}" ]]; then - echo "ERROR: apps discovery produced empty output" >&2 - echo "DEBUG: raw apps.sh output (first 50 lines):" >&2 - TEST_DEPLOY_TYPE="${TEST_DEPLOY_TYPE}" WHITELIST="${WHITELIST}" PYTHON=python3 \ - scripts/meta/resolve/apps.sh 2>&1 | sed -n '1,50p' >&2 - exit 2 + echo "ERROR: apps discovery produced empty output" >&2 + echo "DEBUG: raw apps.sh output (first 50 lines):" >&2 + TEST_DEPLOY_TYPE="${TEST_DEPLOY_TYPE}" WHITELIST="${WHITELIST}" PYTHON=python3 \ + scripts/meta/resolve/apps.sh 2>&1 | sed -n '1,50p' >&2 + exit 2 fi apps_json="${discover_out}" @@ -64,27 +64,27 @@ echo "apps_json=${apps_json}" # Validate JSON list + compute count apps_count="$( - "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); assert isinstance(a,list); print(len(a))' \ - "${apps_json}" + "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); assert isinstance(a,list); print(len(a))' \ + "${apps_json}" )" if [[ "${apps_count}" == "0" ]]; then - echo "ERROR: discovered apps list has length 0" - exit 2 + echo "ERROR: discovered apps list has length 0" + exit 2 fi # Convert JSON list -> CSV apps_csv="$( - "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); print(",".join(map(str,a)))' \ - "${apps_json}" + "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); print(",".join(map(str,a)))' \ + "${apps_json}" )" if [[ -z "${apps_csv}" ]]; then - echo "ERROR: apps_csv ended up empty even though apps_count=${apps_count}" - echo "----- apps_json -----" - printf '%s\n' "${apps_json}" - echo "---------------------" - exit 2 + echo "ERROR: apps_csv ended up empty even though apps_count=${apps_count}" + echo "----- apps_json -----" + printf '%s\n' "${apps_json}" + echo "---------------------" + exit 2 fi echo "apps_count=${apps_count}" @@ -96,8 +96,8 @@ echo echo ">>> Running entry/init + inventory + deploy inside infinito container via development exec" "${PYTHON}" -m cli.deploy.development exec \ - --distro "${INFINITO_DISTRO}" -- \ - bash -c " + --distro "${INFINITO_DISTRO}" -- \ + bash -c " set -euo pipefail cd /opt/src/infinito diff --git a/scripts/tests/deploy/local/app.sh b/scripts/tests/deploy/local/app.sh index bada02e25f..fef22dc1c7 100755 --- a/scripts/tests/deploy/local/app.sh +++ b/scripts/tests/deploy/local/app.sh @@ -20,17 +20,17 @@ REPO_ROOT="$(cd "${SCRIPT_DIR}/../../../.." && pwd)" cd "${REPO_ROOT}" if [[ -f "scripts/meta/env.sh" ]]; then - # shellcheck source=scripts/meta/env.sh - source "scripts/meta/env.sh" + # shellcheck source=scripts/meta/env.sh + source "scripts/meta/env.sh" else - echo "ERROR: missing scripts/meta/env.sh" >&2 - exit 2 + echo "ERROR: missing scripts/meta/env.sh" >&2 + exit 2 fi : "${PYTHON:=python3}" usage() { - cat <<'EOF' + cat <<'EOF' Usage: app.sh @@ -44,35 +44,35 @@ EOF } normalize_bool() { - case "${1:-}" in - true|True|TRUE|1) echo "true" ;; - false|False|FALSE|0) echo "false" ;; - *) - echo "ERROR: invalid boolean value '${1:-}' (expected true|false)" >&2 - exit 2 - ;; - esac + case "${1:-}" in + true | True | TRUE | 1) echo "true" ;; + false | False | FALSE | 0) echo "false" ;; + *) + echo "ERROR: invalid boolean value '${1:-}' (expected true|false)" >&2 + exit 2 + ;; + esac } if [[ "${1:-}" == "-h" || "${1:-}" == "--help" || $# -eq 0 ]]; then - usage - exit 0 + usage + exit 0 fi APP_ID="${1:-}" shift if [[ -z "${APP_ID}" ]]; then - echo "ERROR: app-id is required" >&2 - usage - exit 2 + echo "ERROR: app-id is required" >&2 + usage + exit 2 fi if [[ $# -gt 0 ]]; then - echo "ERROR: unknown argument(s): $*" >&2 - echo "Pass config via ENV (INFINITO_DISTRO, INVENTORY_DIR, LIMIT_HOST, DEBUG)." >&2 - usage - exit 2 + echo "ERROR: unknown argument(s): $*" >&2 + echo "Pass config via ENV (INFINITO_DISTRO, INVENTORY_DIR, LIMIT_HOST, DEBUG)." >&2 + usage + exit 2 fi INFINITO_DISTRO="${INFINITO_DISTRO:-debian}" @@ -81,16 +81,16 @@ LIMIT_HOST="${LIMIT_HOST:-localhost}" DEBUG="${DEBUG:-true}" if [[ -z "${INVENTORY_DIR}" ]]; then - echo "ERROR: INVENTORY_DIR is empty after loading scripts/meta/env.sh" >&2 - exit 2 + echo "ERROR: INVENTORY_DIR is empty after loading scripts/meta/env.sh" >&2 + exit 2 fi case "${INFINITO_DISTRO}" in - arch|debian|ubuntu|fedora|centos) ;; - *) - echo "ERROR: invalid distro '${INFINITO_DISTRO}'" >&2 - exit 2 - ;; +arch | debian | ubuntu | fedora | centos) ;; +*) + echo "ERROR: invalid distro '${INFINITO_DISTRO}'" >&2 + exit 2 + ;; esac DEBUG="$(normalize_bool "${DEBUG}")" @@ -105,30 +105,30 @@ echo echo ">>> Ensuring development stack is up (when-down)" "${PYTHON}" -m cli.deploy.development up \ - --distro "${INFINITO_DISTRO}" \ - --when-down + --distro "${INFINITO_DISTRO}" \ + --when-down echo ">>> Running entry.sh bootstrap inside container" "${PYTHON}" -m cli.deploy.development exec \ - --distro "${INFINITO_DISTRO}" -- \ - bash -lc "set -euo pipefail; cd /opt/src/infinito; ./scripts/docker/entry.sh true" + --distro "${INFINITO_DISTRO}" -- \ + bash -lc "set -euo pipefail; cd /opt/src/infinito; ./scripts/docker/entry.sh true" echo ">>> Creating inventory for app '${APP_ID}'" "${PYTHON}" -m cli.deploy.development init \ - --distro "${INFINITO_DISTRO}" \ - --app "${APP_ID}" \ - --inventory-dir "${INVENTORY_DIR}" \ - --vars '{"ASYNC_ENABLED": false}' + --distro "${INFINITO_DISTRO}" \ + --app "${APP_ID}" \ + --inventory-dir "${INVENTORY_DIR}" \ + --vars '{"ASYNC_ENABLED": false}' deploy_cmd=( - "${PYTHON}" -m cli.deploy.development deploy - --distro "${INFINITO_DISTRO}" - --app "${APP_ID}" - --inventory-dir "${INVENTORY_DIR}" + "${PYTHON}" -m cli.deploy.development deploy + --distro "${INFINITO_DISTRO}" + --app "${APP_ID}" + --inventory-dir "${INVENTORY_DIR}" ) if [[ "${DEBUG}" == "true" ]]; then - deploy_cmd+=(--debug) + deploy_cmd+=(--debug) fi # NOTE: --skip-cleanup keeps cleanup routines disabled during this local test run. diff --git a/scripts/tests/deploy/local/dedicated_distro.sh b/scripts/tests/deploy/local/dedicated_distro.sh index abbee67894..2b755b3e3d 100755 --- a/scripts/tests/deploy/local/dedicated_distro.sh +++ b/scripts/tests/deploy/local/dedicated_distro.sh @@ -24,11 +24,11 @@ PYTHON="${PYTHON:-python3}" LIMIT_HOST="${LIMIT_HOST:-localhost}" case "${TEST_DEPLOY_TYPE}" in - server|workstation|universal) ;; - *) - echo "[ERROR] Invalid TEST_DEPLOY_TYPE: ${TEST_DEPLOY_TYPE}" >&2 - exit 2 - ;; +server | workstation | universal) ;; +*) + echo "[ERROR] Invalid TEST_DEPLOY_TYPE: ${TEST_DEPLOY_TYPE}" >&2 + exit 2 + ;; esac SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -42,13 +42,13 @@ echo echo ">>> Ensuring stack is up for distro ${INFINITO_DISTRO}" "${PYTHON}" -m cli.deploy.development up \ - --distro "${INFINITO_DISTRO}" \ - --when-down + --distro "${INFINITO_DISTRO}" \ + --when-down echo ">>> Running everything inside container via development exec (no logic changes)" "${PYTHON}" -m cli.deploy.development exec \ - --distro "${INFINITO_DISTRO}" -- \ - bash -lc " + --distro "${INFINITO_DISTRO}" -- \ + bash -lc " set -euo pipefail cd /opt/src/infinito diff --git a/scripts/tests/deploy/local/rapid.sh b/scripts/tests/deploy/local/rapid.sh index d5486124e8..7d3cee4dd1 100755 --- a/scripts/tests/deploy/local/rapid.sh +++ b/scripts/tests/deploy/local/rapid.sh @@ -16,21 +16,21 @@ set -euo pipefail : "${INVENTORY_DIR:?INVENTORY_DIR is not set (e.g. INVENTORY_DIR=/etc/inventories/local-full-server)}" case "${TEST_DEPLOY_TYPE}" in - server|workstation|universal) ;; - *) - echo "Invalid TEST_DEPLOY_TYPE: ${TEST_DEPLOY_TYPE}" >&2 - echo "Allowed: server | workstation | universal" >&2 - exit 2 - ;; +server | workstation | universal) ;; +*) + echo "Invalid TEST_DEPLOY_TYPE: ${TEST_DEPLOY_TYPE}" >&2 + echo "Allowed: server | workstation | universal" >&2 + exit 2 + ;; esac case "${DEBUG}" in - true|false) ;; - *) - echo "Invalid DEBUG: ${DEBUG}" >&2 - echo "Allowed: true | false" >&2 - exit 2 - ;; +true | false) ;; +*) + echo "Invalid DEBUG: ${DEBUG}" >&2 + echo "Allowed: true | false" >&2 + exit 2 + ;; esac echo "=== rapid deploy: type=${TEST_DEPLOY_TYPE} app=${APP} container=${INFINITO_CONTAINER} debug=${DEBUG} ===" diff --git a/scripts/tests/deploy/local/run-all.sh b/scripts/tests/deploy/local/run-all.sh index 65e973f600..a3723d1ca5 100755 --- a/scripts/tests/deploy/local/run-all.sh +++ b/scripts/tests/deploy/local/run-all.sh @@ -24,11 +24,14 @@ LIMIT_HOST="${LIMIT_HOST:-localhost}" DEBUG="${DEBUG:-false}" normalize_bool() { - case "${1:-}" in - true|True|TRUE|1) echo "true" ;; - false|False|FALSE|0|"") echo "false" ;; - *) echo "ERROR: invalid boolean: ${1}" >&2; exit 2 ;; - esac + case "${1:-}" in + true | True | TRUE | 1) echo "true" ;; + false | False | FALSE | 0 | "") echo "false" ;; + *) + echo "ERROR: invalid boolean: ${1}" >&2 + exit 2 + ;; + esac } DEBUG="$(normalize_bool "${DEBUG}")" @@ -38,14 +41,14 @@ inv_file="${inv_dir}/servers.yml" pw_file="${inv_dir}/.password" if [[ ! -f "${inv_file}" ]]; then - echo "ERROR: inventory not found: ${inv_file}" >&2 - echo "Run: make test-local-init" >&2 - exit 2 + echo "ERROR: inventory not found: ${inv_file}" >&2 + echo "Run: make test-local-init" >&2 + exit 2 fi if [[ ! -f "${pw_file}" ]]; then - echo "ERROR: password file not found: ${pw_file}" >&2 - exit 2 + echo "ERROR: password file not found: ${pw_file}" >&2 + exit 2 fi echo "=== local run (ALL apps) ===" @@ -59,37 +62,37 @@ echo # Ensure stack is up "${PYTHON}" -m cli.deploy.development up \ - --distro "${INFINITO_DISTRO}" \ - --when-down \ - --skip-entry-init + --distro "${INFINITO_DISTRO}" \ + --when-down \ + --skip-entry-init # Recompute apps list (optional, but keeps filters consistent) apps_json="$( - TEST_DEPLOY_TYPE="${TEST_DEPLOY_TYPE}" \ - WHITELIST="${WHITELIST:-}" \ - scripts/meta/resolve/apps.sh + TEST_DEPLOY_TYPE="${TEST_DEPLOY_TYPE}" \ + WHITELIST="${WHITELIST:-}" \ + scripts/meta/resolve/apps.sh )" apps_count="$( - "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); assert isinstance(a,list); print(len(a))' \ - "${apps_json}" + "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); assert isinstance(a,list); print(len(a))' \ + "${apps_json}" )" if [[ "${apps_count}" == "0" ]]; then - echo "ERROR: discovered apps list has length 0" >&2 - exit 2 + echo "ERROR: discovered apps list has length 0" >&2 + exit 2 fi echo "apps_count=${apps_count}" echo "apps_sample=$( - "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); print(",".join(a[:8]) + ("..." if len(a)>8 else ""))' \ - "${apps_json}" + "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); print(",".join(a[:8]) + ("..." if len(a)>8 else ""))' \ + "${apps_json}" )" echo # Run deploy inside container "${PYTHON}" -m cli.deploy.development exec \ - --distro "${INFINITO_DISTRO}" -- \ - bash -c " + --distro "${INFINITO_DISTRO}" -- \ + bash -c " set -euo pipefail cd /opt/src/infinito diff --git a/scripts/tests/deploy/local/utils/reset.sh b/scripts/tests/deploy/local/utils/reset.sh index 83127d638f..cd0521b352 100755 --- a/scripts/tests/deploy/local/utils/reset.sh +++ b/scripts/tests/deploy/local/utils/reset.sh @@ -23,56 +23,56 @@ echo # 1) Discover apps on HOST (same as local/all.sh) apps_json="$( - TEST_DEPLOY_TYPE="${TEST_DEPLOY_TYPE}" \ - WHITELIST="${WHITELIST:-}" \ - scripts/meta/resolve/apps.sh + TEST_DEPLOY_TYPE="${TEST_DEPLOY_TYPE}" \ + WHITELIST="${WHITELIST:-}" \ + scripts/meta/resolve/apps.sh )" if [[ -z "${apps_json}" ]]; then - echo "ERROR: app matrix is empty" >&2 - exit 2 + echo "ERROR: app matrix is empty" >&2 + exit 2 fi apps_count="$( - "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); assert isinstance(a,list); print(len(a))' \ - "${apps_json}" + "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); assert isinstance(a,list); print(len(a))' \ + "${apps_json}" )" if [[ "${apps_count}" == "0" ]]; then - echo "ERROR: discovered apps list has length 0" >&2 - echo "apps_json=${apps_json}" >&2 - exit 2 + echo "ERROR: discovered apps list has length 0" >&2 + echo "apps_json=${apps_json}" >&2 + exit 2 fi apps_csv="$( - "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); print(",".join(map(str,a)))' \ - "${apps_json}" + "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); print(",".join(map(str,a)))' \ + "${apps_json}" )" if [[ -z "${apps_csv}" ]]; then - echo "ERROR: apps_csv ended up empty even though apps_count=${apps_count}" >&2 - exit 2 + echo "ERROR: apps_csv ended up empty even though apps_count=${apps_count}" >&2 + exit 2 fi echo "apps_count=${apps_count}" echo "apps_sample=$( - "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); print(",".join(a[:8]) + ("..." if len(a)>8 else ""))' \ - "${apps_json}" + "${PYTHON}" -c 'import json,sys; a=json.loads(sys.argv[1]); print(",".join(a[:8]) + ("..." if len(a)>8 else ""))' \ + "${apps_json}" )" echo # 2) Bring up development stack (no build) echo ">>> Starting development compose stack (no build)" "${PYTHON}" -m cli.deploy.development up \ - --distro "${INFINITO_DISTRO}" \ - --skip-entry-init + --distro "${INFINITO_DISTRO}" \ + --skip-entry-init # 3) Run entry.sh + create inventory INSIDE container echo ">>> Initializing inventory inside container" "${PYTHON}" -m cli.deploy.development exec \ - --distro "${INFINITO_DISTRO}" -- \ - bash -c " + --distro "${INFINITO_DISTRO}" -- \ + bash -c " set -euo pipefail cd /opt/src/infinito diff --git a/scripts/tests/dns.sh b/scripts/tests/dns.sh index a62dfbe31a..03b9c1c36e 100755 --- a/scripts/tests/dns.sh +++ b/scripts/tests/dns.sh @@ -7,8 +7,8 @@ set -euo pipefail ENV_FILE="${ENV_FILE:-env.ci}" if [ ! -f "${ENV_FILE}" ]; then - echo "ERROR: env file not found: ${ENV_FILE}" - exit 1 + echo "ERROR: env file not found: ${ENV_FILE}" + exit 1 fi # Export all variables from env file @@ -32,15 +32,18 @@ IP4_EXPECTED="${IP4}" # Output helpers # ------------------------------------------------------------ section() { - echo - echo "------------------------------------------------------------" - echo "$1" - echo "------------------------------------------------------------" + echo + echo "------------------------------------------------------------" + echo "$1" + echo "------------------------------------------------------------" } -ok() { echo "OK: $*"; } +ok() { echo "OK: $*"; } warn() { echo "WARN: $*"; } -fail() { echo "FAIL: $*"; exit 1; } +fail() { + echo "FAIL: $*" + exit 1 +} # ------------------------------------------------------------ # Banner @@ -62,22 +65,22 @@ echo section "Host -> CoreDNS (direct queries)" if command -v dig >/dev/null 2>&1; then - a1="$(dig @"${DNS_IP}" "${DOMAIN}" A +short | head -n1 || true)" - a2="$(dig @"${DNS_IP}" "${SUBDOMAIN}" A +short | head -n1 || true)" + a1="$(dig @"${DNS_IP}" "${DOMAIN}" A +short | head -n1 || true)" + a2="$(dig @"${DNS_IP}" "${SUBDOMAIN}" A +short | head -n1 || true)" - if [ "${a1}" = "${IP4_EXPECTED}" ]; then - ok "${DOMAIN} A -> ${a1}" - else - fail "${DOMAIN} A failed (got '${a1}')" - fi + if [ "${a1}" = "${IP4_EXPECTED}" ]; then + ok "${DOMAIN} A -> ${a1}" + else + fail "${DOMAIN} A failed (got '${a1}')" + fi - if [ "${a2}" = "${IP4_EXPECTED}" ]; then - ok "${SUBDOMAIN} A -> ${a2}" - else - fail "${SUBDOMAIN} A failed (got '${a2}')" - fi + if [ "${a2}" = "${IP4_EXPECTED}" ]; then + ok "${SUBDOMAIN} A -> ${a2}" + else + fail "${SUBDOMAIN} A failed (got '${a2}')" + fi else - warn "dig not found on host β€” skipping host direct DNS tests" + warn "dig not found on host β€” skipping host direct DNS tests" fi # ------------------------------------------------------------ @@ -86,30 +89,30 @@ fi section "Host -> CoreDNS (AAAA sanity check)" if command -v dig >/dev/null 2>&1; then - aaaa1="$(dig @"${DNS_IP}" "${DOMAIN}" AAAA +comments +noall +answer || true)" - aaaa2="$(dig @"${DNS_IP}" "${SUBDOMAIN}" AAAA +comments +noall +answer || true)" + aaaa1="$(dig @"${DNS_IP}" "${DOMAIN}" AAAA +comments +noall +answer || true)" + aaaa2="$(dig @"${DNS_IP}" "${SUBDOMAIN}" AAAA +comments +noall +answer || true)" - echo "AAAA ${DOMAIN}:" - echo "${aaaa1:-}" - echo + echo "AAAA ${DOMAIN}:" + echo "${aaaa1:-}" + echo - echo "AAAA ${SUBDOMAIN}:" - echo "${aaaa2:-}" - echo + echo "AAAA ${SUBDOMAIN}:" + echo "${aaaa2:-}" + echo - # dig exits 0 even on NXDOMAIN, so we check for SERVFAIL explicitly - status1="$(dig @"${DNS_IP}" "${DOMAIN}" AAAA +comments 2>&1 | grep -i status || true)" - status2="$(dig @"${DNS_IP}" "${SUBDOMAIN}" AAAA +comments 2>&1 | grep -i status || true)" + # dig exits 0 even on NXDOMAIN, so we check for SERVFAIL explicitly + status1="$(dig @"${DNS_IP}" "${DOMAIN}" AAAA +comments 2>&1 | grep -i status || true)" + status2="$(dig @"${DNS_IP}" "${SUBDOMAIN}" AAAA +comments 2>&1 | grep -i status || true)" - echo "${status1}" - echo "${status2}" + echo "${status1}" + echo "${status2}" - echo "${status1}" | grep -qi "SERVFAIL" && fail "AAAA lookup returned SERVFAIL for ${DOMAIN}" - echo "${status2}" | grep -qi "SERVFAIL" && fail "AAAA lookup returned SERVFAIL for ${SUBDOMAIN}" + echo "${status1}" | grep -qi "SERVFAIL" && fail "AAAA lookup returned SERVFAIL for ${DOMAIN}" + echo "${status2}" | grep -qi "SERVFAIL" && fail "AAAA lookup returned SERVFAIL for ${SUBDOMAIN}" - ok "AAAA sanity check passed (no SERVFAIL)" + ok "AAAA sanity check passed (no SERVFAIL)" else - warn "dig not found on host β€” skipping AAAA sanity test" + warn "dig not found on host β€” skipping AAAA sanity test" fi # ------------------------------------------------------------ @@ -118,11 +121,11 @@ fi section "CoreDNS container status" if docker ps --filter name=infinito-coredns --format '{{.Names}}' | grep -q infinito-coredns; then - docker ps --filter name=infinito-coredns --format 'table {{.Names}}\t{{.Status}}\t{{.Image}}' - container logs --tail=10 infinito-coredns || true - ok "CoreDNS container is running" + docker ps --filter name=infinito-coredns --format 'table {{.Names}}\t{{.Status}}\t{{.Image}}' + container logs --tail=10 infinito-coredns || true + ok "CoreDNS container is running" else - fail "CoreDNS container not running" + fail "CoreDNS container not running" fi # ------------------------------------------------------------