WIP: Create script to deploy in CI
All checks were successful
CI / build (push) Successful in 5m3s

This commit is contained in:
Fabian Hauser 2025-04-12 20:39:55 +03:00
parent e3cacda356
commit cb25445e23
10 changed files with 136 additions and 49 deletions

View file

@ -0,0 +1,45 @@
#!/usr/bin/env bash
#### Environment
FLAKE_ROOT="$(git rev-parse --show-toplevel)"
export PROFILE=""
case "${1:-''}" in
vm | physical)
PROFILE="system-$1"
;;
*)
echo "🛑 Error: Please use 'vm' or 'physical' as first parameter."
exit 1
;;
esac
HOSTS=$(nix eval --raw "$FLAKE_ROOT"#deploy.nodes --apply "
nodes: let
inherit (builtins) attrNames filter concatStringsSep;
names = attrNames nodes;
profile = \"$PROFILE\";
filteredNames = filter (name: nodes.\${name}.profiles ? \${profile}) names;
in concatStringsSep \"\\n\" filteredNames
")
#### Helpers
retry() {
local -r -i max_attempts="$1"
shift
local -i attempt_num=1
until "$@"; do
if ((attempt_num == max_attempts)); then
echo "⚠️ Warning: Attempt $attempt_num failed and there are no more attempts left!"
return 1
else
echo "⚠️ Attempt $attempt_num failed! Trying again in $attempt_num seconds..."
sleep $((attempt_num++))
fi
done
}
#### Execution
for HOST in $HOSTS; do
retry 3 deploy --skip-checks --targets "${FLAKE_ROOT}#${HOST}.${PROFILE}"
done