Files
Robot-Clash/server/deploy/deploy.sh

32 lines
1.4 KiB
Bash

#!/usr/bin/env bash
# Deploy a committed git ref to the server. Run from the repo root (Git Bash on Windows, or Linux/CI):
# bash server/deploy/deploy.sh deploy HEAD
# bash server/deploy/deploy.sh --reset-db ... and reset the DB (test system: seed accounts michi/benni)
# bash server/deploy/deploy.sh --ref <sha|tag> --host root@<server>
# Only committed code is deployed (git archive), never the working tree. The server side (remote-release.sh)
# installs the release, backs up the DB, switches the `current` link, checks /healthz and rolls back on failure.
set -euo pipefail
HOST="root@roboclash.michael-media.de"
REF="HEAD"
RESET=0
while [ $# -gt 0 ]; do
case "$1" in
--host) HOST="$2"; shift 2 ;;
--ref) REF="$2"; shift 2 ;;
--reset-db) RESET=1; shift ;;
*) echo "unknown option: $1"; exit 2 ;;
esac
done
cd "$(git rev-parse --show-toplevel)"
git diff --quiet HEAD -- game server admin tools || echo "!! uncommitted changes in game/server/admin are NOT deployed (only $REF)"
SHA=$(git rev-parse --short "$REF")
REL="$(date -u +%Y%m%d-%H%M%S)-$SHA"
TAR="$(mktemp -t rc-XXXXXX).tgz"
trap 'rm -f "$TAR"' EXIT
echo ">> release $REL -> $HOST"
git archive --format=tar.gz -o "$TAR" "$REF" game server admin tools
scp -q "$TAR" "$HOST:/tmp/rc-$REL.tgz"
tr -d '\r' < server/deploy/remote-release.sh | ssh "$HOST" bash -s -- "$REL" "$SHA" "$RESET"