scripts/deploy: when deploying all machines, dont let one failed deployment abort the whole job

This commit is contained in:
Colin 2024-06-12 20:00:28 +00:00
parent 4fdaacf8ad
commit b5fc8cfd4e

View File

@ -1,8 +1,6 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nettools
set -e
usage() {
echo "deploy: deploy a nix config to a remote machine, possibly activating it"
echo ""
@ -71,7 +69,7 @@ deployOneHost() {
local host="$1"
local variant="$2"
nix-build -A "hosts.$host$variant" --out-link "./build/result-$host$variant" "${nixArgs[@]}"
nix-build -A "hosts.$host$variant.toplevel" --out-link "./build/result-$host$variant" "${nixArgs[@]}" || return 1
storePath="$(readlink ./build/result-$host$variant)"
# mimic `nixos-rebuild --target-host`, in effect:
@ -92,27 +90,41 @@ deployOneHost() {
# add more `-v` for more verbosity (up to 5).
# builders-use-substitutes false: optimizes so that the remote machine doesn't try to get paths from its substituters.
# we already have all paths here, and the remote substitution is slow to check and SERIOUSLY flaky on moby in particular.
nix copy -vv --option builders-use-substitutes false --to "ssh-ng://$host" "$storePath"
nix copy -vv --option builders-use-substitutes false --to "ssh-ng://$host" "$storePath" || return 1
fi
if [ -n "$action" ] && [ "$action" != "copy" ]; then
runOnTarget sudo nix-env -p /nix/var/nix/profiles/system --set "$storePath"
runOnTarget sudo "$storePath/bin/switch-to-configuration" "$action"
runOnTarget sudo nix-env -p /nix/var/nix/profiles/system --set "$storePath" || return 1
runOnTarget sudo "$storePath/bin/switch-to-configuration" "$action" || return 1
fi
}
parseArgs "$@"
failedDeploys=()
if [ "$host" = "all" ]; then
for host in moby lappy crappy servo desko; do
if [ "$variant" = "all" ]; then
for variant in -min -light ""; do
deployOneHost "$host" "$variant"
deployOneHost "$host" "$variant" || \
failedDeploys+=("$host$variant")
done
else
deployOneHost "$host" "$variant"
deployOneHost "$host" "$variant" || \
failedDeploys+=("$host$variant")
fi
done
else
deployOneHost "$host" "variant"
deployOneHost "$host" "$variant" || \
failedDeploys+=("$host$variant")
fi
if [ "${#failedDeploys[@]}" -ne 0 ]; then
echo "FAILED DEPLOYMENT:"
for d in "${failedDeploys[@]}"; do
echo "- $d"
done
exit 1
else
echo "SUCCESS"
fi