forked from EvolutionAPI/evolution-go
-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (85 loc) · 2.72 KB
/
publish_docker_image.yml
File metadata and controls
102 lines (85 loc) · 2.72 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Deploy Evolution Go
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
concurrency:
group: deploy-evolution-go-main
cancel-in-progress: false
jobs:
deploy:
name: Deploy VPS
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Prepare SSH key
shell: bash
env:
VPS_SSH_KEY: ${{ secrets.VPS_SSH_KEY }}
run: |
set -euo pipefail
install -m 700 -d ~/.ssh
python3 - <<'PY'
import os
from pathlib import Path
raw_key = os.environ["VPS_SSH_KEY"]
normalized_key = raw_key.replace("\\n", "\n").replace("\r", "")
if not normalized_key.endswith("\n"):
normalized_key += "\n"
key_path = Path.home() / ".ssh" / "id_deploy"
key_path.write_text(normalized_key, encoding="utf-8")
PY
chmod 600 ~/.ssh/id_deploy
ssh-keygen -y -f ~/.ssh/id_deploy >/dev/null
- name: Run remote deploy script with retry
shell: bash
env:
VPS_HOST: ${{ secrets.VPS_HOST }}
VPS_USER: ${{ secrets.VPS_USER }}
VPS_PORT: ${{ secrets.VPS_PORT }}
run: |
set -euo pipefail
run_remote_deploy() {
ssh \
-i ~/.ssh/id_deploy \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
-o ConnectTimeout=90 \
-o BatchMode=yes \
-p "$VPS_PORT" \
"$VPS_USER@$VPS_HOST" '
set -euo pipefail
REPO_DIR="/home/deploy/apps/evolution-go"
if [ ! -d "$REPO_DIR/.git" ]; then
mkdir -p /home/deploy/apps
git clone --recursive https://github.com/TBDevMaster/evolution-go.git "$REPO_DIR"
fi
cd "$REPO_DIR"
git remote set-url origin https://github.com/TBDevMaster/evolution-go.git
chmod 750 scripts/deploy.sh
bash scripts/deploy.sh
'
}
for attempt in 1 2 3; do
echo "==== Deploy attempt $attempt/3 ===="
set +e
run_remote_deploy
status=$?
set -e
if [ "$status" -eq 0 ]; then
echo "==== Deploy successful ===="
exit 0
fi
echo "==== Deploy failed with exit code $status ===="
if [ "$attempt" -lt 3 ]; then
backoff=$((20 * attempt))
echo "Retrying in ${backoff}s..."
sleep "$backoff"
else
echo "All deployment attempts failed."
exit "$status"
fi
done