infrastructure/packages/auto-deploy/script.bash
Fabian Hauser cb25445e23
All checks were successful
CI / build (push) Successful in 5m3s
WIP: Create script to deploy in CI
2025-04-19 16:22:20 +03:00

45 lines
1.1 KiB
Bash

#!/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