kubernetes-deployments/applyset-deploy.sh

44 lines
977 B
Bash
Raw Normal View History

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%% *}"
previous_manifest=$(ssh -T "root@$first_server" << EOF
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
2024-10-12 23:02:15 +00:00
if [ $? -eq 0 ]; then
exit 0
fi
fi
set -e
read -r -p "Continue? " response
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...
2024-09-07 10:35:02 +00:00
export KUBECTL_APPLYSET=true
vals eval -fail-on-missing-key-in-map <$MANIFEST | \
kubectl apply -f - \
--prune \
--applyset applyset-$NAME \
--namespace $NAMESPACE