Files
computer-playbook/scripts/tests/deploy-local-full.sh
T
kevinveenbirkenbach df31230871 diff --git a/scripts/tests/deploy-local-full.sh b/scripts/tests/deploy-local-full.sh
index 9bcfc96c8..2c5b6d930 100755
--- a/scripts/tests/deploy-local-full.sh
+++ b/scripts/tests/deploy-local-full.sh
@@ -66,54 +66,53 @@ echo
 # ---------------------------------------------------------------------------
 # 2) Run entry.sh + create inventory + deploy INSIDE container
 # ---------------------------------------------------------------------------
-docker exec -t "${INFINITO_CONTAINER}" bash -lc "
+docker exec -t "${INFINITO_CONTAINER}" bash -lc '
   set -euo pipefail
   cd /opt/src/infinito

-  echo '>>> Running entry.sh bootstrap'
+  echo ">>> Running entry.sh bootstrap"
   ./scripts/docker/entry.sh true

-  inv_dir='${INVENTORY_BASE_DIR}/local-full-${TEST_DEPLOY_TYPE}'
-  inv_file=\"\${inv_dir}/servers.yml\"
-  pw_file=\"\${inv_dir}/.password\"
+  inv_dir="'"${INVENTORY_BASE_DIR}"'/local-full-'"${TEST_DEPLOY_TYPE}"'"
+  inv_file="${inv_dir}/servers.yml"
+  pw_file="${inv_dir}/.password"

-  mkdir -p \"\${inv_dir}\"
+  mkdir -p "${inv_dir}"

-  if [[ ! -f \"\${pw_file}\" ]]; then
-    printf '%s\n' 'local-vault-password' > \"\${pw_file}\"
-    chmod 600 \"\${pw_file}\" || true
+  if [[ ! -f "${pw_file}" ]]; then
+    printf "%s\n" "local-vault-password" > "${pw_file}"
+    chmod 600 "${pw_file}" || true
   fi

-  echo '>>> Creating inventory at' \"\${inv_file}\"
-  echo '>>> Include apps count: ${apps_count}'
-  # Avoid printing the full CSV (it is huge); show first few instead:
-  echo '>>> Include sample:' \"\$(python3 - <<'PY'
-import sys
fix(tests): stabilize deploy-local-full.sh quoting and sample generation

- Fix broken heredoc usage inside docker exec bash -lc block
- Prevent apps CSV from being interpreted as a shell command
- Make sample generation robust using python -c
- Ensure --include argument is expanded correctly
- Improve errexit reliability by avoiding command substitution inside echo
- Normalize quoting for host/container variable expansion

https://chatgpt.com/share/696c928c-38a4-800f-a45b-d5f3bba908ff
2026-01-18 08:57:59 +01:00

119 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# ---------------------------------------------------------------------------
# Required environment
# ---------------------------------------------------------------------------
: "${INFINITO_CONTAINER:?INFINITO_CONTAINER must be set (e.g. infinito_nexus_arch)}"
: "${TEST_DEPLOY_TYPE:?TEST_DEPLOY_TYPE must be set (server|workstation|universal)}"
# Optional overrides
INVENTORY_BASE_DIR="${INVENTORY_BASE_DIR:-/etc/inventories}"
LIMIT_HOST="${LIMIT_HOST:-localhost}"
echo "=== local full deploy ==="
echo "container = ${INFINITO_CONTAINER}"
echo "type = ${TEST_DEPLOY_TYPE}"
echo "limit = ${LIMIT_HOST}"
echo
# ---------------------------------------------------------------------------
# 1) Discover apps on HOST (needs docker compose)
# ---------------------------------------------------------------------------
echo ">>> Discovering apps on host via make ci-deploy-discover (TEST_DEPLOY_TYPE=${TEST_DEPLOY_TYPE})"
discover_out="$(
TEST_DEPLOY_TYPE="${TEST_DEPLOY_TYPE}" \
make -s --no-print-directory ci-deploy-discover
)"
if [[ -z "${discover_out}" ]]; then
echo "ERROR: ci-deploy-discover returned empty output"
exit 2
fi
apps_json="${discover_out}"
echo "apps_json=${apps_json}"
# Validate JSON list + compute count
apps_count="$(
python3 -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
fi
# Convert JSON list -> CSV
apps_csv="$(
python3 -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
fi
echo "apps_count=${apps_count}"
echo
# ---------------------------------------------------------------------------
# 2) Run entry.sh + create inventory + deploy INSIDE container
# ---------------------------------------------------------------------------
docker exec -t "${INFINITO_CONTAINER}" bash -lc '
set -euo pipefail
cd /opt/src/infinito
echo ">>> Running entry.sh bootstrap"
./scripts/docker/entry.sh true
inv_dir="'"${INVENTORY_BASE_DIR}"'/local-full-'"${TEST_DEPLOY_TYPE}"'"
inv_file="${inv_dir}/servers.yml"
pw_file="${inv_dir}/.password"
mkdir -p "${inv_dir}"
if [[ ! -f "${pw_file}" ]]; then
printf "%s\n" "local-vault-password" > "${pw_file}"
chmod 600 "${pw_file}" || true
fi
echo ">>> Creating inventory at ${inv_file}"
echo ">>> Include apps count: '"${apps_count}"'"
# Compute a short sample safely (no heredoc, no command-substitution inside echo)
sample="$(
python3 -c '"'"'import sys; items=sys.argv[1].split(","); print(",".join(items[:8]) + ("..." if len(items)>8 else ""))'"'"' \
"'"${apps_csv}"'"
)"
echo ">>> Include sample: ${sample}"
python3 -m cli.create.inventory "${inv_dir}" \
--host "'"${LIMIT_HOST}"'" \
--ssl-disabled \
--vars-file inventory.sample.yml \
--include "'"${apps_csv}"'"
echo ">>> Deploying against ${inv_file}"
infinito deploy dedicated "${inv_file}" \
-T "'"${TEST_DEPLOY_TYPE}"'" \
--skip-update \
--skip-backup \
--no-signal \
--log /opt/src/infinito/logs \
-l "'"${LIMIT_HOST}"'" \
--diff \
-vv \
--password-file "${pw_file}"
'
echo
echo "=== local full deploy finished ==="