build(deploy): release-based deploy with health check and rollback, node 24, service user (P3-1b, P3-2, P3-3)
This commit is contained in:
31
server/deploy/deploy.sh
Normal file
31
server/deploy/deploy.sh
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/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 || 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
|
||||
scp -q "$TAR" "$HOST:/tmp/rc-$REL.tgz"
|
||||
tr -d '\r' < server/deploy/remote-release.sh | ssh "$HOST" bash -s -- "$REL" "$SHA" "$RESET"
|
||||
Reference in New Issue
Block a user