scripts/deploy: allow specifying multiple hosts or multiple variants
This commit is contained in:
@@ -6,14 +6,17 @@ SELF=$(hostname)
|
|||||||
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 ""
|
||||||
echo "usage: deploy [options] [host]"
|
echo "usage: deploy [options] [host] [host2 ...]"
|
||||||
echo "options:"
|
echo "options:"
|
||||||
echo "- --action copy|switch|test (default: 'switch')"
|
echo "- --action copy|switch|test (default: 'switch')"
|
||||||
echo "- --variant light|min|''|all (default: '')"
|
echo "- --variant light|min|''|all (default: '')"
|
||||||
echo "- --pre: alias for --action copy --variant all all"
|
echo "- --pre: alias for --action copy --variant all all"
|
||||||
echo ""
|
echo ""
|
||||||
echo "common idioms:"
|
echo "common idioms:"
|
||||||
echo "deploy all: deploy all hosts, sequentially"
|
echo "- deploy all: deploy all hosts, sequentially"
|
||||||
|
echo "- deploy --pre: build and copy all hosts"
|
||||||
|
exho "- deploy desko lappy: build and deploy just those hosts"
|
||||||
|
echo "- deploy: deploy the local host"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,9 +25,29 @@ info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
action=switch
|
action=switch
|
||||||
host="$SELF"
|
hosts=()
|
||||||
variant=
|
defaultHost="$SELF"
|
||||||
|
variants=()
|
||||||
|
defaultVariant=
|
||||||
nixArgs=()
|
nixArgs=()
|
||||||
|
addHost() {
|
||||||
|
if [ "$1" = all ]; then
|
||||||
|
# order matters:
|
||||||
|
hosts+=(moby lappy desko servo crappy)
|
||||||
|
else
|
||||||
|
hosts+=("$1")
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
addVariant() {
|
||||||
|
if [ "$1" = all ]; then
|
||||||
|
variants+=("-min" "-light" "" "-min-next" "-light-next" "-next")
|
||||||
|
elif [ -n "$1" ]; then
|
||||||
|
variants+=("-$1")
|
||||||
|
else
|
||||||
|
# "full" variant
|
||||||
|
variants+=("")
|
||||||
|
fi
|
||||||
|
}
|
||||||
parseArgs() {
|
parseArgs() {
|
||||||
while [ "$#" -ne 0 ]; do
|
while [ "$#" -ne 0 ]; do
|
||||||
local arg=$1
|
local arg=$1
|
||||||
@@ -38,26 +61,29 @@ parseArgs() {
|
|||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
(--variant)
|
(--variant)
|
||||||
if [ -n "$1" ]; then
|
addVariant "$1"
|
||||||
variant=-$1
|
|
||||||
else
|
|
||||||
variant=
|
|
||||||
fi
|
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
(crappy|desko|lappy|moby|servo)
|
(all|crappy|desko|lappy|moby|servo)
|
||||||
host="$arg"
|
addHost "$arg"
|
||||||
;;
|
;;
|
||||||
(--pre)
|
(--pre)
|
||||||
action=copy
|
action=copy
|
||||||
host=all
|
defaultVariant=all
|
||||||
variant=all
|
defaultHost=all
|
||||||
;;
|
;;
|
||||||
(*)
|
(*)
|
||||||
nixArgs+=("$arg")
|
nixArgs+=("$arg")
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ "${#hosts[@]}" -eq 0 ] && [ -n "$defaultHost" ]; then
|
||||||
|
addHost "$defaultHost"
|
||||||
|
fi
|
||||||
|
if [ "${#variants[@]}" -eq 0 ]; then
|
||||||
|
addVariant "$defaultVariant"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
runOnTarget() {
|
runOnTarget() {
|
||||||
@@ -111,31 +137,16 @@ deployOneHost() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
parseArgs "$@"
|
parseArgs "$@"
|
||||||
|
|
||||||
failedDeploys=()
|
failedDeploys=()
|
||||||
# deployHelper is like `deployOneHost`,
|
for h in "${hosts[@]}"; do
|
||||||
# but it handles the special cases of `host=all` or `variant=all`,
|
for v in "${variants[@]}"; do
|
||||||
# and aggregates failed deployments into the `failedDeploys` var.
|
deployOneHost "$h" "$v" || \
|
||||||
deployHelper() {
|
failedDeploys+=("$h$v")
|
||||||
local host="$1"
|
done
|
||||||
local variant="$2"
|
done
|
||||||
|
|
||||||
if [ "$variant" = "all" ]; then
|
|
||||||
for variant in -min -light "" "-min-next" "-light-next" "-next"; do
|
|
||||||
deployHelper "$host" "$variant"
|
|
||||||
done
|
|
||||||
elif [ "$host" = "all" ]; then
|
|
||||||
for host in moby lappy crappy servo desko; do
|
|
||||||
deployHelper "$host" "$variant"
|
|
||||||
done
|
|
||||||
else
|
|
||||||
deployOneHost "$host" "$variant" || \
|
|
||||||
failedDeploys+=("$host$variant")
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
deployHelper "$host" "$variant"
|
|
||||||
|
|
||||||
if [ "${#failedDeploys[@]}" -ne 0 ]; then
|
if [ "${#failedDeploys[@]}" -ne 0 ]; then
|
||||||
echo "FAILED DEPLOYMENT:"
|
echo "FAILED DEPLOYMENT:"
|
||||||
|
Reference in New Issue
Block a user