Pārlūkot izejas kodu

refactor: update .gitignore for deploy secrets and add redeploy scripts

avinash 1 nedēļu atpakaļ
vecāks
revīzija
7620300ef7
5 mainītis faili ar 177 papildinājumiem un 2 dzēšanām
  1. 2
    2
      .gitignore
  2. 109
    0
      DEPLOY.md
  3. 0
    0
      deploy.sh
  4. 27
    0
      redeploy.bat
  5. 39
    0
      redeploy.sh

+ 2
- 2
.gitignore Parādīt failu

@@ -21,8 +21,8 @@ npm-debug.log*
21 21
 .env.*
22 22
 !.env.example
23 23
 
24
-# Deploy secrets (server password / host) — keep the .example tracked
25
-deploy.config
24
+# Local deploy trigger password (never commit)
25
+deploy.secret
26 26
 
27 27
 # Build output
28 28
 dist/

+ 109
- 0
DEPLOY.md Parādīt failu

@@ -0,0 +1,109 @@
1
+# Deploying BizGaze Support
2
+
3
+The app runs as a Docker container behind the existing **Nginx Proxy Manager**,
4
+which terminates TLS and proxies `https://remote.bizgaze.com` → `bizgaze-support:8090`
5
+on the shared `nginx_proxy_manager_default` network. No host ports are published.
6
+
7
+Deployment model: **the server holds a git clone of this repo.** Each deploy is a
8
+`git pull` + rebuild via [`deploy.sh`](deploy.sh). Two files are *not* in git and
9
+live only on the server — they survive every pull:
10
+
11
+| File | Purpose |
12
+|------|---------|
13
+| `.env` | Secrets — TURN credentials, optional `SSO_SECRET`, `BIZGAZE_WEBHOOK_URL`. See [.env.example](.env.example). |
14
+| `server/cert.pem`, `server/key.pem` | Self-signed cert for the app's *optional* direct-HTTPS listener (8443). Not needed behind NPM, but harmless. |
15
+
16
+Server facts:
17
+- Host: `root@118.95.33.89` port `61`
18
+- App path: `/opt/bizgaze-support`
19
+- Data: Docker named volume `bizgaze_support_data` → `/data/data.db` (persists across rebuilds)
20
+- Backups: `/opt/bizgaze-support.backups/` (newest 3 `.tgz` snapshots, auto-rotated)
21
+
22
+---
23
+
24
+## One-time bootstrap (server → git clone)
25
+
26
+Run **once** to convert the existing folder into a git checkout without losing the
27
+secrets. Prerequisite: the deployment files (Dockerfile, docker-compose.yml,
28
+deploy.sh, etc.) are committed and pushed to `origin/master` first.
29
+
30
+```bash
31
+ssh -p 61 root@118.95.33.89          # or: plink -ssh -P 61 -pw '<pw>' root@118.95.33.89
32
+
33
+# 1. Store git credentials so pulls are non-interactive (once per server).
34
+git config --global credential.helper store
35
+printf 'https://devops%%40bizgaze.com:Bizgaze%%40123@code.bizgaze.com\n' > ~/.git-credentials
36
+chmod 600 ~/.git-credentials
37
+
38
+# 2. Stash the live secrets.
39
+cd /opt
40
+cp -a bizgaze-support /opt/bizgaze-support.preclone.bak
41
+mkdir -p /tmp/bzsecrets
42
+cp bizgaze-support/.env                /tmp/bzsecrets/ 2>/dev/null || true
43
+cp bizgaze-support/server/cert.pem     /tmp/bzsecrets/ 2>/dev/null || true
44
+cp bizgaze-support/server/key.pem      /tmp/bzsecrets/ 2>/dev/null || true
45
+
46
+# 3. Replace the folder with a fresh clone.
47
+rm -rf bizgaze-support
48
+git clone https://code.bizgaze.com/Sravan/BizGaze_Remote.git bizgaze-support
49
+cd bizgaze-support
50
+
51
+# 4. Restore the secrets the clone doesn't carry.
52
+cp /tmp/bzsecrets/.env       ./.env
53
+cp /tmp/bzsecrets/cert.pem   ./server/cert.pem 2>/dev/null || true
54
+cp /tmp/bzsecrets/key.pem    ./server/key.pem  2>/dev/null || true
55
+rm -rf /tmp/bzsecrets
56
+
57
+# 5. Build & launch.
58
+chmod +x deploy.sh
59
+docker compose up -d --build
60
+docker compose ps
61
+```
62
+
63
+If `.env` did not exist yet, create it from the template and fill in the TURN secret:
64
+
65
+```bash
66
+cp .env.example .env && nano .env
67
+```
68
+
69
+---
70
+
71
+## Routine deploy
72
+
73
+After pushing changes to `origin/master`:
74
+
75
+```bash
76
+ssh -p 61 root@118.95.33.89 'cd /opt/bizgaze-support && ./deploy.sh'
77
+```
78
+
79
+`deploy.sh` snapshots the current tree (keeping 3 backups), `git reset --hard`s to
80
+`origin/master`, rebuilds, and verifies `/api/ice`. Flags:
81
+
82
+- `./deploy.sh --no-pull` — rebuild the current checkout without pulling
83
+- `./deploy.sh --rollback` — restore the newest backup snapshot and rebuild
84
+
85
+---
86
+
87
+## Verify
88
+
89
+```bash
90
+curl https://remote.bizgaze.com/api/ice
91
+```
92
+
93
+Response must list the public STUN entry **and** a TURN entry at
94
+`global.relay.metered.ca`. If only STUN appears, `.env` isn't reaching the
95
+container — check `docker exec bizgaze-support env | grep TURN`.
96
+
97
+---
98
+
99
+## Rollback
100
+
101
+```bash
102
+cd /opt/bizgaze-support && ./deploy.sh --rollback   # newest snapshot
103
+# or restore a specific snapshot:
104
+ls -1t /opt/bizgaze-support.backups/*.tgz
105
+tar -xzf /opt/bizgaze-support.backups/<stamp>.tgz -C /opt/bizgaze-support && docker compose up -d --build
106
+```
107
+
108
+The `data.db` volume is never overwritten by a rebuild, so data is retained
109
+regardless of code version.

+ 0
- 0
deploy.sh Parādīt failu


+ 27
- 0
redeploy.bat Parādīt failu

@@ -0,0 +1,27 @@
1
+@echo off
2
+setlocal enabledelayedexpansion
3
+REM redeploy.bat - trigger a remote deploy FROM YOUR LAPTOP (Windows).
4
+REM Double-click, or run from a terminal. Pass deploy.sh flags through:
5
+REM   redeploy.bat               pull latest + rebuild
6
+REM   redeploy.bat --no-pull     rebuild current checkout
7
+REM   redeploy.bat --rollback    restore newest backup on the server
8
+REM
9
+REM Password order: %DEPLOY_PASS%  ->  deploy.secret file  ->  prompt.
10
+
11
+set "HOST=118.95.33.89"
12
+set "PORT=61"
13
+set "USER=root"
14
+set "APPDIR=/opt/bizgaze-support"
15
+
16
+REM Locate plink
17
+set "PLINK=plink"
18
+where plink >nul 2>nul || set "PLINK=C:\Program Files\PuTTY\plink.exe"
19
+
20
+REM Resolve password
21
+set "PW=%DEPLOY_PASS%"
22
+if "!PW!"=="" if exist "%~dp0deploy.secret" set /p PW=<"%~dp0deploy.secret"
23
+if "!PW!"=="" set /p "PW=Server password for %USER%@%HOST%: "
24
+
25
+echo ==^> Triggering deploy on %USER%@%HOST% (%APPDIR%) ...
26
+"%PLINK%" -ssh -batch -P %PORT% -pw "!PW!" %USER%@%HOST% "cd %APPDIR% && bash deploy.sh %*"
27
+endlocal

+ 39
- 0
redeploy.sh Parādīt failu

@@ -0,0 +1,39 @@
1
+#!/usr/bin/env bash
2
+#
3
+# redeploy.sh — trigger a remote deploy FROM YOUR LAPTOP (Git Bash).
4
+# It SSHes into the server and runs the server-side ./deploy.sh.
5
+#
6
+# Usage:
7
+#   ./redeploy.sh              # pull latest + rebuild
8
+#   ./redeploy.sh --no-pull    # rebuild current checkout
9
+#   ./redeploy.sh --rollback   # restore newest backup on the server
10
+#
11
+# Password (in priority order):
12
+#   1. $DEPLOY_PASS environment variable
13
+#   2. a gitignored `deploy.secret` file next to this script (one line = the pw)
14
+#   3. hidden prompt
15
+set -euo pipefail
16
+
17
+HOST=118.95.33.89
18
+PORT=61
19
+USER=root
20
+APPDIR=/opt/bizgaze-support
21
+
22
+DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
23
+
24
+# Locate plink (PuTTY).
25
+PLINK="$(command -v plink 2>/dev/null || true)"
26
+[ -n "$PLINK" ] || PLINK="/c/Program Files/PuTTY/plink"
27
+[ -x "$PLINK" ] || { echo "ERROR: plink not found (install PuTTY or add to PATH)"; exit 1; }
28
+
29
+# Resolve password.
30
+PW="${DEPLOY_PASS:-}"
31
+if [ -z "$PW" ] && [ -f "$DIR/deploy.secret" ]; then
32
+  PW="$(tr -d '\r\n' < "$DIR/deploy.secret")"
33
+fi
34
+if [ -z "$PW" ]; then
35
+  read -rsp "Server password for $USER@$HOST: " PW; echo
36
+fi
37
+
38
+echo "==> Triggering deploy on $USER@$HOST ($APPDIR) …"
39
+exec "$PLINK" -ssh -batch -P "$PORT" -pw "$PW" "$USER@$HOST" "cd $APPDIR && bash deploy.sh $*"

Notiek ielāde…
Atcelt
Saglabāt