scripts/deploy: when deploying all machines, dont let one failed deployment abort the whole job
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
#!/usr/bin/env nix-shell
|
#!/usr/bin/env nix-shell
|
||||||
#!nix-shell -i bash -p nettools
|
#!nix-shell -i bash -p nettools
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "deploy: deploy a nix config to a remote machine, possibly activating it"
|
echo "deploy: deploy a nix config to a remote machine, possibly activating it"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -71,7 +69,7 @@ deployOneHost() {
|
|||||||
local host="$1"
|
local host="$1"
|
||||||
local variant="$2"
|
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)"
|
storePath="$(readlink ./build/result-$host$variant)"
|
||||||
|
|
||||||
# mimic `nixos-rebuild --target-host`, in effect:
|
# mimic `nixos-rebuild --target-host`, in effect:
|
||||||
@@ -92,27 +90,41 @@ deployOneHost() {
|
|||||||
# add more `-v` for more verbosity (up to 5).
|
# 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.
|
# 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.
|
# 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
|
fi
|
||||||
|
|
||||||
if [ -n "$action" ] && [ "$action" != "copy" ]; then
|
if [ -n "$action" ] && [ "$action" != "copy" ]; then
|
||||||
runOnTarget sudo nix-env -p /nix/var/nix/profiles/system --set "$storePath"
|
runOnTarget sudo nix-env -p /nix/var/nix/profiles/system --set "$storePath" || return 1
|
||||||
runOnTarget sudo "$storePath/bin/switch-to-configuration" "$action"
|
runOnTarget sudo "$storePath/bin/switch-to-configuration" "$action" || return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
parseArgs "$@"
|
parseArgs "$@"
|
||||||
|
|
||||||
|
failedDeploys=()
|
||||||
if [ "$host" = "all" ]; then
|
if [ "$host" = "all" ]; then
|
||||||
for host in moby lappy crappy servo desko; do
|
for host in moby lappy crappy servo desko; do
|
||||||
if [ "$variant" = "all" ]; then
|
if [ "$variant" = "all" ]; then
|
||||||
for variant in -min -light ""; do
|
for variant in -min -light ""; do
|
||||||
deployOneHost "$host" "$variant"
|
deployOneHost "$host" "$variant" || \
|
||||||
|
failedDeploys+=("$host$variant")
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
deployOneHost "$host" "$variant"
|
deployOneHost "$host" "$variant" || \
|
||||||
|
failedDeploys+=("$host$variant")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
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
|
fi
|
||||||
|
Reference in New Issue
Block a user