2024-09-07 10:35:02 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2024-10-12 23:02:15 +00:00
|
|
|
first_server="${SERVERS%% *}"
|
2025-01-11 21:00:22 +00:00
|
|
|
previous_manifest=$(
|
|
|
|
envsubst <<EOF | ssh -T "root@$first_server"
|
|
|
|
if [[ -f "$GCROOTDIR/$NAME.yml" ]]; then
|
|
|
|
cat "$GCROOTDIR/$NAME.yml"
|
2024-10-12 23:02:15 +00:00
|
|
|
fi
|
|
|
|
EOF
|
|
|
|
)
|
|
|
|
|
|
|
|
set +e
|
|
|
|
if [ -z "$previous_manifest" ]; then
|
|
|
|
echo No previous manifest found!
|
|
|
|
else
|
2025-01-11 21:00:22 +00:00
|
|
|
$DYFF between <(echo "$previous_manifest") "$MANIFEST" \
|
2024-10-17 19:01:12 +00:00
|
|
|
--exclude-regexp metadata.labels.kubenix/hash \
|
|
|
|
--exclude-regexp labels.kubenix/hash \
|
2025-01-11 21:00:22 +00:00
|
|
|
--set-exit-code
|
2024-10-12 23:02:15 +00:00
|
|
|
fi
|
|
|
|
set -e
|
|
|
|
|
2025-01-11 21:00:22 +00:00
|
|
|
read -r -p "Continue? " _
|
2024-10-12 23:02:15 +00:00
|
|
|
|
2024-09-24 21:00:55 +00:00
|
|
|
echo Uploading closure...
|
|
|
|
for server in $SERVERS; do
|
2025-01-11 21:00:22 +00:00
|
|
|
echo Uploading closure to "$server"...
|
|
|
|
nix copy --to "ssh://root@$server.dmz" "$MANIFEST"
|
2024-09-24 21:00:55 +00:00
|
|
|
ssh "root@$server.dmz" "mkdir -p $GCROOTDIR && ln -sf $MANIFEST $GCROOTDIR/${NAME}.yml"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo Applying Kubernetes manifest...
|
2024-09-07 10:35:02 +00:00
|
|
|
export KUBECTL_APPLYSET=true
|
2025-01-11 21:00:22 +00:00
|
|
|
vals eval -fail-on-missing-key-in-map <"$MANIFEST" |
|
|
|
|
kubectl apply -f - \
|
|
|
|
--prune \
|
|
|
|
--applyset applyset-"$NAME" \
|
|
|
|
--namespace "$NAMESPACE"
|