-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
62 lines (53 loc) Β· 2.23 KB
/
Copy pathdeploy.sh
File metadata and controls
62 lines (53 loc) Β· 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
# Push the bridge to your VPS: package -> upload -> install -> build -> restart.
# Configure the target via env vars (e.g. put them in a local deploy.env you don't commit):
# DEPLOY_HOST your.server.ip.or.host (required)
# SSH_KEY path to your private key (default: ~/.ssh/id_ed25519)
# REMOTE_USER ssh user (default: root)
# REMOTE_DIR app dir on the server (default: /opt/relay)
# APP_USER service user on the server (default: relay)
#
# Usage: DEPLOY_HOST=1.2.3.4 bash deploy.sh (restart bridge only)
# DEPLOY_HOST=1.2.3.4 bash deploy.sh --n8n (also restart n8n)
set -euo pipefail
IP="${DEPLOY_HOST:-}"
KEY="${SSH_KEY:-$HOME/.ssh/id_ed25519}"
USER_REMOTE="${REMOTE_USER:-root}"
REMOTE_DIR="${REMOTE_DIR:-/opt/relay}"
APP_USER="${APP_USER:-relay}"
if [ -z "$IP" ]; then
echo "error: set DEPLOY_HOST (your server IP or hostname). See header for options." >&2
exit 1
fi
RESTART_N8N=0
for a in "$@"; do [ "$a" = "--n8n" ] && RESTART_N8N=1; done
cd "$(dirname "$0")"
# Files to ship (never the remote .env, node_modules, dist, data, or local cruft).
FILES=(src web deploy tools package.json tsconfig.json .env.example README.md DEPLOY.md .gitignore)
[ -f package-lock.json ] && FILES+=(package-lock.json)
TGZ="$(mktemp).tgz"
echo "==> packaging $(printf '%s ' "${FILES[@]}")"
tar -czf "$TGZ" "${FILES[@]}"
echo "==> uploading to $USER_REMOTE@$IP"
scp -i "$KEY" -o StrictHostKeyChecking=accept-new "$TGZ" "$USER_REMOTE@$IP:/tmp/relay-deploy.tgz"
rm -f "$TGZ"
echo "==> install + build + restart on $IP (n8n restart: $RESTART_N8N)"
ssh -i "$KEY" -o StrictHostKeyChecking=accept-new "$USER_REMOTE@$IP" 'bash -s' -- "$RESTART_N8N" "$REMOTE_DIR" "$APP_USER" <<'REMOTE'
set -e
restart_n8n="${1:-0}"; dir="${2:-/opt/relay}"; appuser="${3:-relay}"
cd "$dir"
tar -xzf /tmp/relay-deploy.tgz -C "$dir"
rm -f /tmp/relay-deploy.tgz
npm install --no-audit --no-fund
npm run build
chown -R "$appuser":"$appuser" "$dir"
systemctl restart relay
sleep 3
echo "relay: $(systemctl is-active relay) | health: $(curl -s http://127.0.0.1:3100/health)"
if [ "$restart_n8n" = "1" ]; then
systemctl restart n8n
sleep 2
echo "n8n: $(systemctl is-active n8n)"
fi
REMOTE
echo "==> done"