Repository navigation
164 lines (145 loc) · 5.34 KB
/
Copy pathdeploy-oracle.yml
File metadata and controls
164 lines (145 loc) · 5.34 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Deploy R0-U41 to Oracle
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
concurrency:
group: r0-u41-oracle-deploy
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Check out the release
uses: actions/checkout@v4
- name: Configure Oracle SSH
env:
ORACLE_SSH_KEY: ${{ secrets.ORACLE_SSH_KEY }}
ORACLE_KNOWN_HOSTS: ${{ secrets.ORACLE_KNOWN_HOSTS }}
run: |
set -euo pipefail
test -n "$ORACLE_SSH_KEY"
test -n "$ORACLE_KNOWN_HOSTS"
install -d -m 700 "$RUNNER_TEMP/ssh"
printf '%s\n' "$ORACLE_SSH_KEY" > "$RUNNER_TEMP/ssh/oracle_key"
printf '%s\n' "$ORACLE_KNOWN_HOSTS" > "$RUNNER_TEMP/ssh/known_hosts"
chmod 600 "$RUNNER_TEMP/ssh/oracle_key" "$RUNNER_TEMP/ssh/known_hosts"
- name: Sync application files
run: |
set -euo pipefail
ssh_opts="-i $RUNNER_TEMP/ssh/oracle_key -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$RUNNER_TEMP/ssh/known_hosts"
rsync -az \
--delete \
--exclude '.env' \
--exclude '.git/' \
--exclude '.github/' \
--exclude '.idea/' \
--exclude '.venv/' \
--exclude 'venv/' \
--exclude 'keys/' \
--exclude 'archive/' \
--exclude 'data/' \
--exclude 'sessions/' \
--exclude '__pycache__/' \
--exclude '*.pyc' \
--exclude '*.pkl' \
--exclude '*.pk1' \
--exclude '*.db' \
-e "ssh $ssh_opts" \
./ opc@129.146.36.195:/home/opc/bots/R0U41/
- name: Install dependencies and restart tmux session
env:
SSH_OPTS: -i ${{ runner.temp }}/ssh/oracle_key -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=${{ runner.temp }}/ssh/known_hosts
run: |
set -euo pipefail
ssh $SSH_OPTS opc@129.146.36.195 'bash -se' <<'REMOTE'
set -euo pipefail
app=/home/opc/bots/R0U41
session=R0U41
target="$session:0"
cd "$app"
python -m pip install --user --disable-pip-version-check -r requirements.txt
app_pids() {
pgrep -u "$(id -u)" -f '[p]ython main.py' || true
}
if tmux has-session -t "$session" 2>/dev/null; then
tmux send-keys -t "$target" C-c
fi
pids=$(app_pids)
if [ -n "$pids" ]; then
echo "Stopping existing R0-U41 app processes: $pids"
for pid in $pids; do
kill -TERM "$pid" 2>/dev/null || true
done
for _ in $(seq 1 15); do
[ -z "$(app_pids)" ] && break
sleep 1
done
fi
pids=$(app_pids)
if [ -n "$pids" ]; then
echo "Force-stopping remaining R0-U41 app processes: $pids" >&2
for pid in $pids; do
kill -KILL "$pid" 2>/dev/null || true
done
for _ in $(seq 1 5); do
[ -z "$(app_pids)" ] && break
sleep 1
done
fi
if [ -n "$(app_pids)" ]; then
echo 'R0-U41 app processes remained after graceful and force stop.' >&2
exit 1
fi
if tmux has-session -t "$session" 2>/dev/null; then
tmux send-keys -t "$target" "cd $app && python main.py" C-m
else
tmux new-session -d -s "$session" -c "$app" "python main.py"
fi
REMOTE
- name: Verify the tmux process
env:
SSH_OPTS: -i ${{ runner.temp }}/ssh/oracle_key -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=${{ runner.temp }}/ssh/known_hosts
run: |
set -euo pipefail
ssh $SSH_OPTS opc@129.146.36.195 'bash -se' <<'REMOTE'
set -euo pipefail
app=/home/opc/bots/R0U41
tmux has-session -t R0U41
app_pids() {
pgrep -u "$(id -u)" -f '[p]ython main.py' || true
}
seen=0
for _ in $(seq 1 15); do
pids=$(app_pids)
count=$(printf '%s\n' "$pids" | awk 'NF { count++ } END { print count + 0 }')
if [ "$count" -eq 1 ]; then
echo "R0-U41 running with pid $pids"
seen=$((seen + 1))
[ "$seen" -ge 3 ] && exit 0
else
[ "$count" -gt 1 ] && echo "R0-U41 has $count app-scoped python main.py processes: $pids" >&2
seen=0
fi
sleep 1
done
echo 'R0-U41 did not have exactly one app-scoped python main.py process after restart.' >&2
exit 1
REMOTE
- name: Capture runtime startup output
if: always()
env:
SSH_OPTS: -i ${{ runner.temp }}/ssh/oracle_key -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=${{ runner.temp }}/ssh/known_hosts
run: |
set -euo pipefail
ssh $SSH_OPTS opc@129.146.36.195 'bash -se' <<'REMOTE'
set -euo pipefail
sleep 5
echo '--- R0-U41 tmux output ---'
tmux capture-pane -p -t R0U41:0 -S -160 || true
echo '--- R0-U41 process check ---'
pgrep -af '[p]ython main.py' || true
REMOTE