-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathmaster-pb7-python312.yml
More file actions
214 lines (190 loc) · 6.28 KB
/
master-pb7-python312.yml
File metadata and controls
214 lines (190 loc) · 6.28 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
---
# Recreate PB7 venv with Python 3.12 on localhost (Master)
# Steps:
# 1. Stop PBRun + PBRemote
# 2. Kill running pb7 processes (bots + workers)
# 3. Install python3.12-venv
# 4. Remove old venv_pb7
# 5. Update pb7 repository (keep current branch)
# 6. Create new python3.12 venv for pb7 + install requirements (upgrade pip)
# 7. Build passivbot-rust with maturin
# 8. Start PBRun
# 9. Start PBRun + PBRemote
- hosts: localhost
gather_facts: "{{ debug }}"
vars:
ansible_become_password: "{{ user_pw }}"
user: "{{ user }}"
user_pw: "{{ user_pw }}"
pbgdir: "{{ pbgdir }}"
pb7dir: "{{ pb7dir }}"
pb7venv: "{{ pb7venv }}"
tasks:
- name: display facts
debug:
var: ansible_facts
tags: debug,never
- name: Stop PBRun + PBRemote
shell: |
python "{{ pbgdir }}/starter.py" -k PBRun PBRemote
args:
executable: /bin/bash
chdir: "{{ pbgdir }}"
when: pbgdir != ""
ignore_errors: yes
- name: Detect OS + arch (for Ubuntu 20.04 x86_64 uv path)
shell: |
set -euo pipefail
. /etc/os-release
echo "${ID:-unknown} ${VERSION_ID:-unknown}"
uname -m
args:
executable: /bin/bash
register: os_arch
changed_when: false
- name: Set use_uv_python312 flag (Ubuntu 20.04 + x86_64)
set_fact:
use_uv_python312: >-
{{ (os_arch.stdout_lines[0].startswith('ubuntu 20.04'))
and (os_arch.stdout_lines[1] == 'x86_64') }}
uv_bin: "{{ lookup('env', 'HOME') }}/.local/bin/uv"
changed_when: false
- name: kill all pb7 processes (bots)
shell: |
pids=$(ps -ef | grep "{{ pb7dir }}/src/main.py" | grep -v grep | awk '{print $2}')
if [ -n "$pids" ]; then
kill $pids
fi
when: pb7dir != ""
ignore_errors: yes
- name: kill all pb7 processes (workers using pb7 venv)
shell: |
pids=$(ps -ef | grep "{{ pb7venv }}/bin/python" | grep -v grep | awk '{print $2}')
if [ -n "$pids" ]; then
kill $pids
fi
when: pb7venv != ""
ignore_errors: yes
- name: Install python3.12-venv
apt:
pkg:
- python3.12-venv
update_cache: yes
clean: yes
become: yes
when: not (use_uv_python312 | default(false))
- name: Install curl + ca-certificates for uv (Ubuntu 20.04 x86_64)
raw: |
set -e
apt-get update -y
DEBIAN_FRONTEND=noninteractive apt-get install -y curl ca-certificates
become: yes
when: use_uv_python312 | default(false)
- name: Install uv (Ubuntu 20.04 x86_64)
shell: |
set -euo pipefail
curl -LsSf https://astral.sh/uv/install.sh | sh
args:
executable: /bin/bash
creates: "{{ uv_bin }}"
when: use_uv_python312 | default(false)
- name: Install Python 3.12 via uv (Ubuntu 20.04 x86_64)
shell: |
set -euo pipefail
"{{ uv_bin }}" python install 3.12
args:
executable: /bin/bash
register: uv_python_install
changed_when: uv_python_install.rc == 0 and (uv_python_install.stdout | default('')) != ''
when: use_uv_python312 | default(false)
- name: Remove old pb7 venv
file:
path: "{{ pb7venv }}"
state: absent
when: pb7venv != ""
become: yes
- name: Get current pb7 branch
command: git rev-parse --abbrev-ref HEAD
args:
chdir: "{{ pb7dir }}"
register: current_pb7_branch
changed_when: false
when: pb7dir != ""
- name: update passivbot repository for pb7 (keep current branch)
git:
repo: https://github.com/enarjord/passivbot.git
dest: "{{ pb7dir }}"
version: "{{ current_pb7_branch.stdout }}"
update: yes
force: yes
when: pb7dir != ""
register: pb7_repo
- name: print pb7_repo
debug:
var: pb7_repo
tags: debug,never
- name: Create python3.12 venv for PB7 (apt python3.12)
pip:
virtualenv_command: python3.12 -m venv
virtualenv: "{{ pb7venv }}"
requirements: "{{ pb7dir }}/requirements.txt"
extra_args: --upgrade pip
when: (not (use_uv_python312 | default(false))) and pb7dir != "" and pb7venv != ""
- name: Create python3.12 venv for PB7 (uv Python 3.12 on Ubuntu 20.04 x86_64)
shell: |
set -euo pipefail
"{{ uv_bin }}" venv --python 3.12 "{{ pb7venv }}"
args:
executable: /bin/bash
creates: "{{ pb7venv }}/bin/activate"
when: (use_uv_python312 | default(false)) and pb7dir != "" and pb7venv != ""
- name: Ensure pip exists in uv venv (Ubuntu 20.04 x86_64)
shell: |
set -euo pipefail
"{{ pb7venv }}/bin/python" -m ensurepip --upgrade
args:
executable: /bin/bash
when: (use_uv_python312 | default(false)) and pb7dir != "" and pb7venv != ""
- name: Install PB7 requirements into uv venv
shell: |
set -euo pipefail
"{{ pb7venv }}/bin/python" -m pip install --upgrade pip
"{{ pb7venv }}/bin/python" -m pip install -r "{{ pb7dir }}/requirements.txt"
args:
executable: /bin/bash
when: (use_uv_python312 | default(false)) and pb7dir != "" and pb7venv != ""
- name: Build passivbot-rust with maturin
shell: |
source ~/.profile || source ~/.bashrc || true
source "{{ pb7venv }}/bin/activate"
maturin develop --release
args:
chdir: "{{ pb7dir }}/passivbot-rust"
executable: /bin/bash
when: pb7dir != "" and pb7venv != ""
register: maturin_result
- name: Write rust source stamp after maturin build
shell: |
source "{{ pb7venv }}/bin/activate"
python -c "
import sys
sys.path.insert(0, 'src')
from rust_utils import stamp_compiled_extensions, source_fingerprint
stamp_compiled_extensions(source_fingerprint())
print('Rust source stamp updated.')
"
args:
chdir: "{{ pb7dir }}"
executable: /bin/bash
when: pb7dir != "" and pb7venv != ""
- name: print maturin result
debug:
var: maturin_result
tags: debug,never
- name: Start PBRun + PBRemote
shell: |
python "{{ pbgdir }}/starter.py" -s PBRun PBRemote
args:
executable: /bin/bash
chdir: "{{ pbgdir }}"
when: pbgdir != ""