This commit is contained in:
parent
e3cacda356
commit
2b1266f249
5 changed files with 101 additions and 20 deletions
46
packages/auto-deploy-vms/default.nix
Normal file
46
packages/auto-deploy-vms/default.nix
Normal 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
|
||||
'';
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue