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

This commit is contained in:
Fabian Hauser 2025-04-12 20:39:55 +03:00
parent e3cacda356
commit 2b1266f249
5 changed files with 101 additions and 20 deletions

View file

@ -0,0 +1,46 @@
{
deploy-rs,
gitMinimal,
writeShellApplication,
...
}:
writeShellApplication {
name = "qois-auto-deploy-vms";
meta.description = "Deploy VMs automatically as part of CI process.";
runtimeInputs = [
deploy-rs
gitMinimal
];
text = ''
set -x
FLAKE_ROOT="$(git rev-parse --show-toplevel)"
export PROFILE="system-vm"
# shellcheck disable=SC2016
HOSTS=$(nix eval --raw .#deploy.nodes --apply 'nodes: let
names = builtins.attrNames nodes;
profile = "$PROFILE";
filteredNames = builtins.filter (name: nodes.''${name}.profiles ? ''${profile}) names;
in
builtins.concatStringsSep "\n" filteredNames')
retry() {
local -r -i max_attempts="$1"; shift
local -i attempt_num=1
until "$@"
do
if ((attempt_num==max_attempts))
then
echo "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
}
for HOST in $HOSTS; do
retry 3 deploy --skip-checks --targets "$FLAKE_ROOT#''${HOST}.system-vm"
done
'';
}