kubernetes-deployments/applyset-deploy.sh
2025-01-11 22:00:22 +01:00

40 lines
956 B
Bash

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