This commit is contained in:
parent
e3cacda356
commit
2b1266f249
5 changed files with 101 additions and 20 deletions
27
deploy/system-physical/default.nix
Normal file
27
deploy/system-physical/default.nix
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
deployPkgs,
|
||||||
|
pkgs,
|
||||||
|
self,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (pkgs.lib) pipe filterAttrs mapAttrs;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
nodes = pipe self.nixosConfigurations [
|
||||||
|
(filterAttrs (_n: v: v.config.services.qemuGuest.enable == false))
|
||||||
|
(mapAttrs (
|
||||||
|
host: config: {
|
||||||
|
hostname = "${host}.backplane.net.qo.is";
|
||||||
|
profiles.system-physical = {
|
||||||
|
sshUser = "root";
|
||||||
|
user = "root";
|
||||||
|
activationTimeout = 600;
|
||||||
|
confirmTimeout = 120;
|
||||||
|
remoteBuild = true;
|
||||||
|
path = deployPkgs.deploy-rs.lib.activate.nixos config;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
))
|
||||||
|
];
|
||||||
|
}
|
27
deploy/system-vm/default.nix
Normal file
27
deploy/system-vm/default.nix
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
deployPkgs,
|
||||||
|
pkgs,
|
||||||
|
self,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (pkgs.lib) pipe filterAttrs mapAttrs;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
nodes = pipe self.nixosConfigurations [
|
||||||
|
(filterAttrs (_n: v: v.config.services.qemuGuest.enable))
|
||||||
|
(mapAttrs (
|
||||||
|
host: config: {
|
||||||
|
hostname = "${host}.backplane.net.qo.is";
|
||||||
|
profiles.system-vm = {
|
||||||
|
sshUser = "root";
|
||||||
|
user = "root";
|
||||||
|
activationTimeout = 300;
|
||||||
|
confirmTimeout = 60;
|
||||||
|
remoteBuild = true;
|
||||||
|
path = deployPkgs.deploy-rs.lib.activate.nixos config;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
))
|
||||||
|
];
|
||||||
|
}
|
|
@ -1,20 +0,0 @@
|
||||||
{
|
|
||||||
deployPkgs,
|
|
||||||
pkgs,
|
|
||||||
self,
|
|
||||||
system,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
nodes = pkgs.lib.mapAttrs (host: config: {
|
|
||||||
hostname = "${host}.backplane.net.qo.is";
|
|
||||||
profiles.system = {
|
|
||||||
sshUser = "root";
|
|
||||||
user = "root";
|
|
||||||
activationTimeout = 420;
|
|
||||||
confirmTimeout = 120;
|
|
||||||
|
|
||||||
path = deployPkgs.deploy-rs.lib.activate.nixos config;
|
|
||||||
};
|
|
||||||
}) self.nixosConfigurations;
|
|
||||||
}
|
|
|
@ -32,6 +32,7 @@ in
|
||||||
deploy-qois
|
deploy-qois
|
||||||
sops
|
sops
|
||||||
sops-rekey
|
sops-rekey
|
||||||
|
auto-deploy-vms
|
||||||
])
|
])
|
||||||
++ (with pkgs; [
|
++ (with pkgs; [
|
||||||
attic-client
|
attic-client
|
||||||
|
|
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
Reference in a new issue