game-village-politics-backend/scripts/deploy-edgerealm.sh

50 lines
1.9 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
# Deploys the pushed master to server-village.blax.at (edgerealm) and checks HTTP and WS.
# Touches only the game-village-politics-backend checkout and its containers on that shared host.
# On Windows, put the Windows OpenSSH client first: PATH="/c/Windows/System32/OpenSSH:$PATH".
set -euo pipefail
HOST=root@static.64.40.140.128.clients.your-server.de
DIR=/mnt/HC_Volume_102040804/srv/game-village-politics-backend
REPO=ssh://git@git.blax.at:222/blax-software/game-village-politics-backend.git
URL=https://server-village.blax.at
WS=https://ws-server-village.blax.at/app/village-politics
cd "$(dirname "$0")/.."
if [ -n "$(git status --porcelain)" ]; then
echo "Uncommitted changes: commit and push first." >&2
exit 1
fi
git fetch -q origin
LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse origin/master)
if [ "$LOCAL" != "$REMOTE" ]; then
echo "HEAD ${LOCAL:0:7} is not origin/master ${REMOTE:0:7}: push (or pull) first." >&2
exit 1
fi
echo "==> Deploying ${LOCAL:0:7} to edgerealm"
ssh -o BatchMode=yes "$HOST" "[ -d $DIR ] || git clone -q $REPO $DIR"
ssh -o BatchMode=yes "$HOST" "cd $DIR && ./deploy.sh 2>&1" | { grep -E '^==>|ERROR|Error|FAIL' || true; }
DEPLOYED=$(ssh -o BatchMode=yes "$HOST" "cd $DIR && git rev-parse HEAD")
if [ "$DEPLOYED" != "$LOCAL" ]; then
echo "Server is on ${DEPLOYED:0:7}, expected ${LOCAL:0:7}." >&2
exit 1
fi
# /up is Laravel's health route; the WS server answers an upgrade with 101.
for _ in $(seq 1 20); do
UP=$(curl -s -o /dev/null -w '%{http_code}' "$URL/up" || true)
WSCODE=$(curl -s -o /dev/null -w '%{http_code}' --http1.1 --max-time 3 \
-H 'Connection: Upgrade' -H 'Upgrade: websocket' -H 'Sec-WebSocket-Version: 13' \
-H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' "$WS" || true)
if [ "$UP" = 200 ] && [ "$WSCODE" = 101 ]; then
echo "Live: $URL at ${LOCAL:0:7}"
exit 0
fi
sleep 3
done
echo "Deployed ${LOCAL:0:7}, but $URL/up answers $UP and the WS upgrade $WSCODE." >&2
exit 1