big update
This commit is contained in:
53
server/deploy/README.md
Normal file
53
server/deploy/README.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Robot Clash – Deploy auf den Hetzner-Server
|
||||
|
||||
Spiel + API laufen auf **einem** Server unter `https://roboclash.michael-media.de/` (Caddy macht TLS automatisch,
|
||||
reverse-proxyt auf den Node-Dienst). Kein Ansible nötig – ein Setup-Skript + ein PowerShell-Push.
|
||||
|
||||
## 0) DNS (einmal)
|
||||
Beim DNS-Anbieter von `michael-media.de` einen **A-Record** anlegen:
|
||||
`roboclash` → `91.99.166.238` (die Server-IP). Kurz warten, bis er aktiv ist.
|
||||
|
||||
## 1) Server einrichten (einmal, von Windows PowerShell)
|
||||
```powershell
|
||||
scp server\deploy\setup.sh root@91.99.166.238:/root/
|
||||
ssh root@91.99.166.238 "bash /root/setup.sh roboclash.michael-media.de"
|
||||
```
|
||||
Das installiert Node + Caddy, legt den systemd-Dienst, die Firewall (ufw) und ein tägliches DB-Backup an und
|
||||
schreibt `/opt/robotclash/server/.env` mit zufälligem `JWT_SECRET`.
|
||||
|
||||
## 2) Code hochladen + starten
|
||||
```powershell
|
||||
.\server\deploy\push.ps1
|
||||
ssh root@91.99.166.238 "systemctl start robotclash"
|
||||
```
|
||||
Fertig → **https://roboclash.michael-media.de/** (TLS kommt beim ersten Aufruf automatisch; ein paar Sekunden).
|
||||
|
||||
## 3) Updates später
|
||||
Einfach erneut:
|
||||
```powershell
|
||||
.\server\deploy\push.ps1
|
||||
```
|
||||
(lädt Spiel + Server neu hoch, `npm ci`, startet den Dienst neu). `.env` und die Datenbank bleiben erhalten.
|
||||
|
||||
## Admin werden (für die Live-Steuerung / `/db/live`)
|
||||
Im Spiel registrieren, dann auf dem Server die uid holen und in die `.env` eintragen:
|
||||
```
|
||||
ssh root@91.99.166.238
|
||||
sqlite3 /opt/robotclash/server/data.sqlite "select uid,email from users"
|
||||
nano /opt/robotclash/server/.env # ADMIN_UID=<deine uid>
|
||||
systemctl restart robotclash
|
||||
```
|
||||
|
||||
## Anti-Cheat scharf schalten (nach Schritt 3 der Umsetzung)
|
||||
In `.env` `ANTICHEAT=1` setzen + `systemctl restart robotclash`. Dann entfernt der Server `money`/`fame` aus
|
||||
`saves/` und Geld läuft nur noch über die Server-Endpunkte. **Vorher** muss der Client-Geldfluss umgestellt sein,
|
||||
sonst steht das Geld auf 0.
|
||||
|
||||
## Logs / Status
|
||||
```
|
||||
systemctl status robotclash
|
||||
journalctl -u robotclash -f
|
||||
```
|
||||
|
||||
Schneller (optional, aus WSL statt PowerShell): `rsync -az --delete game server root@91.99.166.238:/opt/robotclash/`
|
||||
statt `scp` – nur Änderungen, kein erneutes Hochladen der ~13 MB Assets.
|
||||
31
server/deploy/deploy-all.ps1
Normal file
31
server/deploy/deploy-all.ps1
Normal file
@@ -0,0 +1,31 @@
|
||||
# Komplett-Deploy in einem: Server einrichten, Code hochladen, starten, Status prüfen.
|
||||
# Aus dem Projektordner in Windows PowerShell: .\server\deploy\deploy-all.ps1
|
||||
# Beim ersten Mal fragt SSH nach dem Hetzner-Root-Passwort (mehrfach) und einmal nach dem Fingerprint (yes).
|
||||
param(
|
||||
[string]$Server = "root@91.99.166.238",
|
||||
[string]$Domain = "roboclash.michael-media.de",
|
||||
[string]$App = "/opt/robotclash"
|
||||
)
|
||||
$ErrorActionPreference = "Stop"
|
||||
$repo = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).Path
|
||||
|
||||
Write-Host "== 1/4 Server einrichten (Node, Caddy, Dienst, Firewall) ==" -ForegroundColor Cyan
|
||||
scp "$repo\server\deploy\setup.sh" "${Server}:/root/setup.sh"
|
||||
ssh $Server "bash /root/setup.sh $Domain"
|
||||
|
||||
Write-Host "== 2/4 Code hochladen (Spiel + Server) ==" -ForegroundColor Cyan
|
||||
ssh $Server "mkdir -p $App/game $App/server"
|
||||
scp -r -q "$repo\game" "${Server}:$App/"
|
||||
Get-ChildItem "$repo\server" -File |
|
||||
Where-Object { $_.Name -ne ".env" -and $_.Name -notlike "*.sqlite*" } |
|
||||
ForEach-Object { scp -q $_.FullName "${Server}:$App/server/" }
|
||||
|
||||
Write-Host "== 3/4 Abhaengigkeiten installieren + Dienst starten ==" -ForegroundColor Cyan
|
||||
ssh $Server "cd $App/server && (npm ci --omit=dev 2>/dev/null || npm install --omit=dev) && systemctl restart robotclash"
|
||||
|
||||
Write-Host "== 4/4 Status ==" -ForegroundColor Cyan
|
||||
ssh $Server "sleep 1; systemctl --no-pager --lines=6 status robotclash; echo '--- lokal (Node) ---'; curl -s -o /dev/null -w 'node:8080 -> HTTP %{http_code}\n' http://localhost:8080/; echo -n '--- caddy: '; systemctl is-active caddy"
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Fertig. Oeffne: https://$Domain/ (Browser: Strg+F5 oder Inkognito)" -ForegroundColor Green
|
||||
Write-Host "Beim ersten Aufruf holt Caddy automatisch das TLS-Zertifikat (ein paar Sekunden)." -ForegroundColor Green
|
||||
29
server/deploy/push.ps1
Normal file
29
server/deploy/push.ps1
Normal file
@@ -0,0 +1,29 @@
|
||||
# Push the game + server to the Hetzner box and restart. Run from Windows PowerShell (needs OpenSSH: ssh/scp).
|
||||
# .\server\deploy\push.ps1
|
||||
# .\server\deploy\push.ps1 -Server root@91.99.166.238
|
||||
param(
|
||||
[string]$Server = "root@91.99.166.238",
|
||||
[string]$App = "/opt/robotclash"
|
||||
)
|
||||
$ErrorActionPreference = "Stop"
|
||||
$repo = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).Path
|
||||
Write-Host "Deploy from $repo -> ${Server}:$App"
|
||||
|
||||
# make sure target dirs exist
|
||||
ssh $Server "mkdir -p $App/game $App/server"
|
||||
|
||||
# game/ (no node_modules inside) - full tree incl. assets
|
||||
Write-Host "Uploading game/ ..."
|
||||
scp -r -q "$repo\game" "${Server}:$App/"
|
||||
|
||||
# server source only: skip .env, node_modules and the live DB
|
||||
Write-Host "Uploading server/ source ..."
|
||||
Get-ChildItem "$repo\server" -File |
|
||||
Where-Object { $_.Name -ne ".env" -and $_.Name -notlike "*.sqlite*" } |
|
||||
ForEach-Object { scp -q $_.FullName "${Server}:$App/server/" }
|
||||
|
||||
# install deps + restart
|
||||
Write-Host "Installing deps + restarting ..."
|
||||
ssh $Server "cd $App/server && (npm ci --omit=dev 2>/dev/null || npm install --omit=dev) && systemctl restart robotclash && sleep 1 && systemctl --no-pager --lines=5 status robotclash"
|
||||
|
||||
Write-Host "Done. https://roboclash.michael-media.de/"
|
||||
87
server/deploy/setup.sh
Normal file
87
server/deploy/setup.sh
Normal file
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env bash
|
||||
# One-time server setup for Robot Clash. Run ON the Hetzner box as root:
|
||||
# bash setup.sh # uses roboclash.michael-media.de
|
||||
# bash setup.sh my.domain.tld # custom domain
|
||||
# Installs Node + Caddy (auto-TLS), creates the systemd service, firewall and a daily DB backup.
|
||||
# Then push the code (deploy/push.ps1 from Windows) and: systemctl start robotclash
|
||||
set -euo pipefail
|
||||
DOMAIN="${1:-roboclash.michael-media.de}"
|
||||
APP=/opt/robotclash
|
||||
|
||||
echo ">> Robot Clash setup for $DOMAIN"
|
||||
|
||||
# --- Node LTS -------------------------------------------------------------------------------------
|
||||
if ! command -v node >/dev/null 2>&1; then
|
||||
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
||||
apt-get install -y nodejs
|
||||
fi
|
||||
apt-get install -y build-essential python3 git ufw sqlite3 curl
|
||||
|
||||
# --- Caddy (reverse proxy + automatic HTTPS) ------------------------------------------------------
|
||||
if ! command -v caddy >/dev/null 2>&1; then
|
||||
apt-get install -y debian-keyring debian-archive-keyring apt-transport-https
|
||||
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
|
||||
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list >/dev/null
|
||||
apt-get update
|
||||
apt-get install -y caddy
|
||||
fi
|
||||
|
||||
mkdir -p "$APP/game" "$APP/server" "$APP/backups"
|
||||
|
||||
# --- .env (random JWT secret, kept across deploys) ------------------------------------------------
|
||||
if [ ! -f "$APP/server/.env" ]; then
|
||||
cat > "$APP/server/.env" <<EOF
|
||||
PORT=8080
|
||||
JWT_SECRET=$(head -c 32 /dev/urandom | base64 | tr -d '\n')
|
||||
ADMIN_UID=
|
||||
DB_FILE=$APP/server/data.sqlite
|
||||
ANTICHEAT=0
|
||||
EOF
|
||||
echo ">> wrote $APP/server/.env (random JWT_SECRET)"
|
||||
fi
|
||||
|
||||
# --- systemd service ------------------------------------------------------------------------------
|
||||
cat > /etc/systemd/system/robotclash.service <<EOF
|
||||
[Unit]
|
||||
Description=Robot Clash server
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=$APP/server
|
||||
EnvironmentFile=$APP/server/.env
|
||||
ExecStart=/usr/bin/node app.js
|
||||
Restart=always
|
||||
RestartSec=2
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
systemctl daemon-reload
|
||||
systemctl enable robotclash
|
||||
|
||||
# --- Caddy site -----------------------------------------------------------------------------------
|
||||
cat > /etc/caddy/Caddyfile <<EOF
|
||||
$DOMAIN {
|
||||
encode gzip
|
||||
reverse_proxy localhost:8080
|
||||
}
|
||||
EOF
|
||||
systemctl reload caddy 2>/dev/null || systemctl restart caddy
|
||||
|
||||
# --- firewall -------------------------------------------------------------------------------------
|
||||
ufw allow 22 >/dev/null; ufw allow 80 >/dev/null; ufw allow 443 >/dev/null
|
||||
ufw --force enable >/dev/null
|
||||
|
||||
# --- daily SQLite backup (keep 14) ----------------------------------------------------------------
|
||||
cat > /etc/cron.daily/robotclash-backup <<EOF
|
||||
#!/usr/bin/env bash
|
||||
D=$APP/backups
|
||||
sqlite3 $APP/server/data.sqlite ".backup '\$D/data-\$(date +%F).sqlite'" 2>/dev/null || cp $APP/server/data.sqlite "\$D/data-\$(date +%F).sqlite" 2>/dev/null || true
|
||||
ls -1t "\$D"/data-*.sqlite 2>/dev/null | tail -n +15 | xargs -r rm
|
||||
EOF
|
||||
chmod +x /etc/cron.daily/robotclash-backup
|
||||
|
||||
echo ">> Setup done."
|
||||
echo ">> DNS: point $DOMAIN A-record to this server's IP."
|
||||
echo ">> Next: push the code (deploy/push.ps1 from Windows), then: systemctl start robotclash"
|
||||
Reference in New Issue
Block a user