forked from fediversity/fediversity
factor out TF run.sh
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
parent
7a890ccd44
commit
4a24bf3681
7 changed files with 65 additions and 91 deletions
|
|
@ -59,8 +59,6 @@ in
|
||||||
_class = "nixosTest";
|
_class = "nixosTest";
|
||||||
name = "deployment-model";
|
name = "deployment-model";
|
||||||
sourceFileset = lib.fileset.unions [
|
sourceFileset = lib.fileset.unions [
|
||||||
../../run/tf-proxmox-template/run.sh
|
|
||||||
../../run/tf-proxmox-vm/run.sh
|
|
||||||
../../run/tf-proxmox-vm/await-ssh.sh
|
../../run/tf-proxmox-vm/await-ssh.sh
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,6 @@ in
|
||||||
{
|
{
|
||||||
_class = "nixosTest";
|
_class = "nixosTest";
|
||||||
name = "deployment-model";
|
name = "deployment-model";
|
||||||
sourceFileset = lib.fileset.unions [
|
|
||||||
../../run/tf-single-host/run.sh
|
|
||||||
];
|
|
||||||
|
|
||||||
nodes.deployer =
|
nodes.deployer =
|
||||||
{ ... }:
|
{ ... }:
|
||||||
|
|
|
||||||
|
|
@ -19,15 +19,7 @@ let
|
||||||
str
|
str
|
||||||
submodule
|
submodule
|
||||||
;
|
;
|
||||||
inherit (pkgs.callPackage ./utils.nix { }) toBash;
|
inherit (pkgs.callPackage ./utils.nix { }) toBash withPackages tfApply;
|
||||||
withPackages = packages: {
|
|
||||||
makeWrapperArgs = [
|
|
||||||
"--prefix"
|
|
||||||
"PATH"
|
|
||||||
":"
|
|
||||||
"${lib.makeBinPath packages}"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
writeConfig =
|
writeConfig =
|
||||||
{
|
{
|
||||||
system,
|
system,
|
||||||
|
|
@ -246,6 +238,10 @@ let
|
||||||
key-file
|
key-file
|
||||||
sshOpts
|
sshOpts
|
||||||
;
|
;
|
||||||
|
in
|
||||||
|
tfApply {
|
||||||
|
inherit httpBackend;
|
||||||
|
directory = "tf-single-host";
|
||||||
environment = {
|
environment = {
|
||||||
key_file = key-file;
|
key_file = key-file;
|
||||||
ssh_opts = sshOpts;
|
ssh_opts = sshOpts;
|
||||||
|
|
@ -264,22 +260,7 @@ let
|
||||||
deployment-type = "tf-host";
|
deployment-type = "tf-host";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
tf-env = pkgs.callPackage ./run/tf-env.nix {
|
};
|
||||||
inherit httpBackend;
|
|
||||||
tfPackage = pkgs.callPackage ./run/tf-single-host/tf.nix { };
|
|
||||||
tfDirs = [ "deployment/run/tf-single-host" ];
|
|
||||||
};
|
|
||||||
in
|
|
||||||
pkgs.writers.writeBashBin "deploy-tf.sh"
|
|
||||||
(withPackages [
|
|
||||||
pkgs.jq
|
|
||||||
(pkgs.callPackage ./run/tf-single-host/tf.nix { })
|
|
||||||
])
|
|
||||||
''
|
|
||||||
env ${toString (lib.mapAttrsToList (k: v: "TF_VAR_${k}=\"${toBash v}\"") environment)} \
|
|
||||||
${toString (lib.mapAttrsToList (k: v: "${k}=\"${toBash v}\"") httpBackend)} \
|
|
||||||
tf_env=${tf-env} bash ./deployment/run/tf-single-host/run.sh
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
@ -344,19 +325,10 @@ let
|
||||||
node_name = node-name;
|
node_name = node-name;
|
||||||
image_datastore_id = imageDatastoreId;
|
image_datastore_id = imageDatastoreId;
|
||||||
};
|
};
|
||||||
tf-env = pkgs.callPackage ./run/tf-env.nix {
|
|
||||||
inherit httpBackend;
|
|
||||||
tfPackage = pkgs.callPackage ./run/tf-proxmox-template/tf.nix { };
|
|
||||||
tfDirs = [
|
|
||||||
"deployment/run/tf-proxmox-template"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
lib.trace (lib.strings.toJSON environment) pkgs.writers.writeBashBin "deploy-tf-proxmox-template.sh"
|
lib.trace (lib.strings.toJSON environment) pkgs.writers.writeBashBin "deploy-tf-proxmox-template.sh"
|
||||||
(withPackages [
|
(withPackages [
|
||||||
pkgs.jq
|
|
||||||
pkgs.qemu
|
pkgs.qemu
|
||||||
(pkgs.callPackage ./run/tf-proxmox-vm/tf.nix { })
|
|
||||||
])
|
])
|
||||||
''
|
''
|
||||||
set -e
|
set -e
|
||||||
|
|
@ -369,11 +341,13 @@ let
|
||||||
ls -l /tmp/${name}.qcow2 >&2
|
ls -l /tmp/${name}.qcow2 >&2
|
||||||
checksum="$(sha256sum /tmp/${name}.qcow2 | cut -d " " -f1)"
|
checksum="$(sha256sum /tmp/${name}.qcow2 | cut -d " " -f1)"
|
||||||
|
|
||||||
env ${toString (lib.mapAttrsToList (k: v: "TF_VAR_${k}=\"${toBash v}\"") environment)} \
|
env \
|
||||||
${toString (lib.mapAttrsToList (k: v: "${k}=\"${toBash v}\"") httpBackend)} \
|
|
||||||
TF_VAR_image=/tmp/${name}.qcow2 \
|
TF_VAR_image=/tmp/${name}.qcow2 \
|
||||||
TF_VAR_checksum="$checksum" \
|
TF_VAR_checksum="$checksum" \
|
||||||
tf_env=${tf-env} bash ./deployment/run/tf-proxmox-template/run.sh
|
${lib.getExe (tfApply {
|
||||||
|
inherit httpBackend environment;
|
||||||
|
directory = "tf-proxmox-template";
|
||||||
|
})}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -531,33 +505,12 @@ let
|
||||||
ipv6_gateway = ipv6Gateway;
|
ipv6_gateway = ipv6Gateway;
|
||||||
ipv6_address = ipv6Address;
|
ipv6_address = ipv6Address;
|
||||||
};
|
};
|
||||||
tf-env = pkgs.callPackage ./run/tf-env.nix {
|
|
||||||
inherit httpBackend;
|
|
||||||
tfPackage = pkgs.callPackage ./run/tf-proxmox-vm/tf.nix { };
|
|
||||||
tfDirs = [
|
|
||||||
"deployment/run/tf-single-host"
|
|
||||||
"deployment/run/tf-proxmox-vm"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
lib.trace (lib.strings.toJSON environment) pkgs.writers.writeBashBin "deploy-tf-proxmox-vm.sh"
|
lib.trace (lib.strings.toJSON environment) (tfApply {
|
||||||
(withPackages [
|
inherit httpBackend environment;
|
||||||
pkgs.jq
|
directory = "tf-proxmox-vm";
|
||||||
pkgs.qemu
|
dependentDirs = [ "tf-single-host" ];
|
||||||
(pkgs.callPackage ./run/tf-proxmox-vm/tf.nix { })
|
});
|
||||||
])
|
|
||||||
''
|
|
||||||
set -e
|
|
||||||
env ${
|
|
||||||
toString (
|
|
||||||
lib.mapAttrsToList (k: v: "TF_VAR_${k}=\"${toBash v}\"") (
|
|
||||||
lib.filterAttrs (_: v: v != null) environment
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} \
|
|
||||||
${toString (lib.mapAttrsToList (k: v: "${k}=\"${toBash v}\"") httpBackend)} \
|
|
||||||
tf_env=${tf-env} bash ./deployment/run/tf-proxmox-vm/run.sh
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
#! /usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
declare tf_env
|
|
||||||
|
|
||||||
cd "${tf_env}/deployment/run/tf-proxmox-template"
|
|
||||||
tofu apply --auto-approve -input=false -parallelism=1 >&2
|
|
||||||
tofu output -json
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
#! /usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
declare tf_env
|
|
||||||
|
|
||||||
cd "${tf_env}/deployment/run/tf-proxmox-vm"
|
|
||||||
# parallelism=1: limit OOM risk
|
|
||||||
tofu apply --auto-approve -input=false -parallelism=1 >&2
|
|
||||||
tofu output -json
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
#! /usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
declare tf_env
|
|
||||||
|
|
||||||
cd "${tf_env}/deployment/run/tf-single-host"
|
|
||||||
# parallelism=1: limit OOM risk
|
|
||||||
tofu apply --auto-approve -parallelism=1
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
inputs ? null,
|
inputs ? null,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
rec {
|
||||||
evalModel =
|
evalModel =
|
||||||
module:
|
module:
|
||||||
(lib.evalModules {
|
(lib.evalModules {
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
module
|
module
|
||||||
];
|
];
|
||||||
}).config;
|
}).config;
|
||||||
|
|
||||||
toBash =
|
toBash =
|
||||||
v:
|
v:
|
||||||
lib.replaceStrings [ "\"" ] [ "\\\"" ] (
|
lib.replaceStrings [ "\"" ] [ "\\\"" ] (
|
||||||
|
|
@ -27,4 +28,51 @@
|
||||||
else
|
else
|
||||||
lib.strings.toJSON v
|
lib.strings.toJSON v
|
||||||
);
|
);
|
||||||
|
|
||||||
|
withPackages = packages: {
|
||||||
|
makeWrapperArgs = [
|
||||||
|
"--prefix"
|
||||||
|
"PATH"
|
||||||
|
":"
|
||||||
|
"${lib.makeBinPath packages}"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
tfApply =
|
||||||
|
{
|
||||||
|
directory,
|
||||||
|
httpBackend,
|
||||||
|
dependentDirs ? [ ],
|
||||||
|
environment ? { },
|
||||||
|
# limit OOM risk
|
||||||
|
parallelism ? 1,
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
env-vars = ''
|
||||||
|
${
|
||||||
|
toString (
|
||||||
|
lib.mapAttrsToList (k: v: "TF_VAR_${k}=\"${toBash v}\"") (
|
||||||
|
lib.filterAttrs (_: v: v != null) environment
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} \
|
||||||
|
${toString (lib.mapAttrsToList (k: v: "${k}=\"${toBash v}\"") httpBackend)} \
|
||||||
|
'';
|
||||||
|
tfPackage = pkgs.callPackage ./run/${directory}/tf.nix { };
|
||||||
|
tf-env = pkgs.callPackage ./run/tf-env.nix {
|
||||||
|
inherit httpBackend tfPackage;
|
||||||
|
tfDirs = lib.lists.map (dir: "deployment/run/${dir}") ([ directory ] ++ dependentDirs);
|
||||||
|
};
|
||||||
|
in
|
||||||
|
pkgs.writers.writeBashBin "tf-apply.sh"
|
||||||
|
(withPackages [
|
||||||
|
tfPackage
|
||||||
|
pkgs.jq
|
||||||
|
])
|
||||||
|
''
|
||||||
|
set -e
|
||||||
|
dir="${tf-env}/deployment/run/${directory}"
|
||||||
|
env ${env-vars} tofu -chdir="$dir" apply --auto-approve -parallelism=${builtins.toString parallelism} >&2
|
||||||
|
env ${env-vars} tofu -chdir="$dir" output -json
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue