| author | ymh <ymh.work@gmail.com> |
| Tue, 29 Mar 2022 11:23:38 +0200 | |
| changeset 210 | 3de92ddba2de |
| parent 188 | 00cf90eb0f5a |
| permissions | -rw-r--r-- |
| 180 | 1 |
--- |
2 |
# - hosts: all |
|
3 |
# tasks: |
|
4 |
# - name: Print some debug information |
|
5 |
# vars: |
|
6 |
# msg: | |
|
7 |
# Module Variables ("vars"): |
|
8 |
# -------------------------------- |
|
9 |
# {{ vars | to_nice_json }} |
|
10 |
||
11 |
# Environment Variables ("environment"): |
|
12 |
# -------------------------------- |
|
13 |
# {{ environment | to_nice_json }} |
|
14 |
||
15 |
# GROUP NAMES Variables ("group_names"): |
|
16 |
# -------------------------------- |
|
17 |
# {{ group_names | to_nice_json }} |
|
18 |
||
19 |
# GROUPS Variables ("groups"): |
|
20 |
# -------------------------------- |
|
21 |
# {{ groups | to_nice_json }} |
|
22 |
||
23 |
# HOST Variables ("hostvars"): |
|
24 |
# -------------------------------- |
|
25 |
# {{ hostvars | to_nice_json }} |
|
26 |
||
27 |
# debug: |
|
28 |
# msg: "{{ msg.split('\n') }}" |
|
29 |
# tags: debug_info |
|
30 |
# |
|
31 |
# Localhost actions |
|
32 |
# |
|
33 |
- hosts: localhost |
|
34 |
connection: local |
|
35 |
vars: |
|
36 |
irinotes_build_dir: "{{playbook_dir}}/build/tmp/irinotes/" |
|
37 |
backend_build_dir: "{{playbook_dir}}/build/tmp/irinotes/src" |
|
38 |
client_dir: "{{playbook_dir}}/build/tmp/irinotes/client" |
|
39 |
tasks: |
|
40 |
||
41 |
- name: mkdir build folder |
|
42 |
file: |
|
43 |
path: "{{playbook_dir}}/build/tmp" |
|
44 |
state: directory |
|
45 |
||
46 |
- name: clear irinotes checkout dir if exists |
|
47 |
file: |
|
48 |
path: "{{irinotes_build_dir}}" |
|
49 |
state: absent |
|
50 |
||
51 |
- name: checkout irinotes |
|
52 |
hg: |
|
53 |
repo: "{{irinotes_repo}}" |
|
54 |
version: "{{irinotes_version}}" |
|
55 |
force: yes |
|
56 |
dest: "{{irinotes_build_dir}}" |
|
57 |
||
58 |
- name: make irinotes py package |
|
59 |
command: python setup.py sdist chdir="{{backend_build_dir}}" |
|
60 |
||
61 |
# |
|
62 |
# all actions |
|
63 |
# |
|
|
210
3de92ddba2de
Correct deploy script to use pyenv
ymh <ymh.work@gmail.com>
parents:
188
diff
changeset
|
64 |
# - hosts: remote_backend |
|
3de92ddba2de
Correct deploy script to use pyenv
ymh <ymh.work@gmail.com>
parents:
188
diff
changeset
|
65 |
- hosts: localhost |
|
3de92ddba2de
Correct deploy script to use pyenv
ymh <ymh.work@gmail.com>
parents:
188
diff
changeset
|
66 |
connection: local |
| 180 | 67 |
vars: |
68 |
backend_build_dir: "{{playbook_dir}}/build/tmp/irinotes/src" |
|
69 |
client_dir: "{{playbook_dir}}/build/tmp/irinotes/client" |
|
70 |
tasks: |
|
71 |
||
72 |
- name: get backend version |
|
|
210
3de92ddba2de
Correct deploy script to use pyenv
ymh <ymh.work@gmail.com>
parents:
188
diff
changeset
|
73 |
command: python setup.py -V chdir="{{backend_build_dir}}" |
| 180 | 74 |
register: backend_version |
75 |
||
76 |
- name: get discussion package version |
|
77 |
set_fact: |
|
78 |
backend_pkg_version: "{{backend_version.stdout}}" |
|
79 |
# |
|
80 |
# Localhost actions |
|
81 |
# |
|
82 |
- hosts: localhost |
|
83 |
connection: local |
|
84 |
vars: |
|
85 |
backend_build_dir: "{{playbook_dir}}/build/tmp/irinotes/src" |
|
86 |
client_dir: "{{playbook_dir}}/build/tmp/irinotes/client" |
|
87 |
tasks: |
|
88 |
||
89 |
# build client js |
|
90 |
- name: remove build |
|
91 |
file: path="{{client_dir}}/build" state=absent |
|
92 |
||
93 |
- name: client yarn install |
|
94 |
command: npm install --no-save yarn |
|
95 |
args: |
|
96 |
chdir: "{{client_dir}}" |
|
97 |
||
98 |
- name: client dependencies install |
|
99 |
command: npx yarn install |
|
100 |
args: |
|
101 |
chdir: "{{client_dir}}" |
|
102 |
||
103 |
- name: client build |
|
104 |
command: npx yarn build |
|
105 |
args: |
|
106 |
chdir: "{{client_dir}}" |
|
107 |
environment: |
|
| 182 | 108 |
REACT_APP_API_ROOT_URL: "{{backend_base_url}}" |
|
184
aac6db7cea99
first version of deploy script + set version to 0.1.0
ymh <ymh.work@gmail.com>
parents:
182
diff
changeset
|
109 |
REACT_APP_BASENAME: "{{static_url_base}}" |
| 180 | 110 |
REACT_APP_NETWORK_STATUS_INTERVAL: "{{network_status_interval}}" |
111 |
REACT_APP_NETWORK_STATUS_TIMEOUT: "{{network_status_timeout}}" |
|
112 |
REACT_APP_SYNC_INTERVAL: "{{sync_interval}}" |
|
113 |
||
114 |
# |
|
115 |
# Static server |
|
116 |
# |
|
117 |
- hosts: remote_static |
|
118 |
become: yes |
|
119 |
vars: |
|
120 |
backend_build_dir: "{{playbook_dir}}/build/tmp/irinotes/src" |
|
121 |
client_dir: "{{playbook_dir}}/build/tmp/irinotes/client" |
|
122 |
tasks: |
|
123 |
||
124 |
- name: create dest static directory content |
|
125 |
file: |
|
126 |
path: "{{remote_static_path}}" |
|
127 |
state: directory |
|
128 |
owner: "{{static_http_user}}" |
|
129 |
group: "{{static_http_group}}" |
|
130 |
||
131 |
- name: remove dest static directory content |
|
132 |
command: /bin/rm -fr "{{remote_static_path}}/*" warn=False |
|
133 |
when: remote_static_path != "" |
|
134 |
||
135 |
- name: transfert static dist to remote |
|
136 |
copy: |
|
137 |
src: "{{client_dir}}/build/" |
|
138 |
dest: "{{remote_static_path}}/" |
|
139 |
owner: "{{static_http_user}}" |
|
140 |
group: "{{static_http_group}}" |
|
141 |
notify: |
|
142 |
- restart static nginx |
|
143 |
||
144 |
- name: create refresh nginx config |
|
145 |
template: |
|
146 |
src: "{{static_nginx_use_ssl | ternary('nginx.static.ssl.conf.j2', 'nginx.static.conf.j2')}}" |
|
147 |
dest: "{{static_nginx_config | default('/etc/nginx/site-available/'+static_server_name, true)}}" |
|
148 |
notify: |
|
149 |
- restart static nginx |
|
150 |
||
151 |
handlers: |
|
152 |
- name: restart static nginx |
|
153 |
service: |
|
154 |
name: "{{static_http_service}}" |
|
155 |
state: restarted |
|
156 |
ignore_errors: yes |
|
157 |
||
158 |
# |
|
159 |
# backend servers |
|
160 |
# |
|
161 |
- hosts: remote_backend |
|
162 |
become: yes |
|
163 |
vars: |
|
164 |
backend_build_dir: "{{playbook_dir}}/build/tmp/irinotes/src" |
|
|
210
3de92ddba2de
Correct deploy script to use pyenv
ymh <ymh.work@gmail.com>
parents:
188
diff
changeset
|
165 |
backend_pkg_version: "{{hostvars['localhost']['backend_pkg_version']}}" |
| 180 | 166 |
tasks: |
167 |
||
168 |
- name: add iri group |
|
169 |
group: |
|
170 |
name: iri |
|
171 |
||
172 |
- name: add uwsgi user |
|
173 |
user: |
|
174 |
name: uwsgi |
|
175 |
group: iri |
|
176 |
home: /var/www |
|
177 |
create_home: no |
|
178 |
system: yes |
|
179 |
shell: /bin/false |
|
180 |
||
181 |
- name: create log dir |
|
182 |
file: |
|
183 |
path: "{{log_base_path}}" |
|
184 |
state: directory |
|
185 |
owner: uwsgi |
|
186 |
group: iri |
|
187 |
mode: 0755 |
|
188 |
||
189 |
- name: create config dir |
|
190 |
file: |
|
191 |
path: "{{backend_config_base}}" |
|
192 |
state: directory |
|
193 |
owner: uwsgi |
|
194 |
group: iri |
|
195 |
mode: 0755 |
|
196 |
||
197 |
- name: create config dir requirements |
|
198 |
file: |
|
199 |
path: "{{backend_config_base}}/requirements" |
|
200 |
state: directory |
|
201 |
owner: uwsgi |
|
202 |
group: iri |
|
203 |
mode: 0755 |
|
204 |
||
205 |
- name: create static folder |
|
206 |
file: |
|
207 |
path: "{{backend_static_root}}" |
|
208 |
state: directory |
|
209 |
owner: uwsgi |
|
210 |
group: iri |
|
211 |
mode: 0755 |
|
212 |
||
213 |
- name: create media folder |
|
214 |
file: |
|
215 |
path: "{{backend_media_root}}" |
|
216 |
state: directory |
|
217 |
owner: uwsgi |
|
218 |
group: iri |
|
219 |
mode: 0755 |
|
220 |
||
221 |
- name: install backend venv |
|
222 |
block: |
|
223 |
- name: register backend virtualenv stats |
|
224 |
stat: path="{{backend_venv}}" |
|
225 |
register: backend_venv_stats |
|
226 |
||
227 |
- name: copy backend base requirement file |
|
228 |
copy: |
|
229 |
src: "{{backend_build_dir}}/requirements/base.txt" |
|
230 |
dest: "{{backend_config_base}}/requirements/base.txt" |
|
231 |
register: copy_backend_requirements_base |
|
232 |
||
233 |
- name: copy backend prod requirement file |
|
234 |
copy: |
|
235 |
src: "{{backend_build_dir}}/requirements/prod.txt" |
|
236 |
dest: "{{backend_config_base}}/requirements/prod.txt" |
|
237 |
register: copy_backend_requirements_prod |
|
238 |
||
239 |
||
240 |
- name: remove annotation api venv |
|
241 |
file: |
|
242 |
path: "{{backend_venv}}" |
|
243 |
state: absent |
|
244 |
when: copy_backend_requirements_base.changed or copy_backend_requirements_prod.changed |
|
245 |
||
246 |
- name: create backend virtualenv |
|
247 |
pip: |
|
|
210
3de92ddba2de
Correct deploy script to use pyenv
ymh <ymh.work@gmail.com>
parents:
188
diff
changeset
|
248 |
virtualenv_command: /usr/local/share/pyenv/shims/python -m venv |
| 180 | 249 |
virtualenv: "{{backend_venv}}" |
250 |
name: pip |
|
251 |
state: latest |
|
|
210
3de92ddba2de
Correct deploy script to use pyenv
ymh <ymh.work@gmail.com>
parents:
188
diff
changeset
|
252 |
environment: |
|
3de92ddba2de
Correct deploy script to use pyenv
ymh <ymh.work@gmail.com>
parents:
188
diff
changeset
|
253 |
PYENV_VERSION: "3.9.12" |
| 180 | 254 |
when: (copy_backend_requirements_base.changed or copy_backend_requirements_prod.changed) or (not backend_venv_stats.stat.exists) |
255 |
||
256 |
- name: virtualenv install requirements |
|
257 |
pip: |
|
258 |
virtualenv: "{{backend_venv}}" |
|
259 |
requirements: "{{backend_config_base}}/requirements/prod.txt" |
|
260 |
when: (copy_backend_requirements_base.changed or copy_backend_requirements_prod.changed) or (not backend_venv_stats.stat.exists) |
|
261 |
notify: restart irinotes backend service |
|
262 |
||
263 |
- name: copy backend config |
|
264 |
template: |
|
265 |
src: "backend_settings.ini.j2" |
|
266 |
dest: "{{backend_config_base}}/settings.ini" |
|
267 |
notify: restart irinotes backend service |
|
268 |
||
269 |
# install irinotes |
|
270 |
- name: create temporary install directory |
|
271 |
tempfile: |
|
272 |
state: directory |
|
273 |
suffix: build |
|
274 |
register: backend_temp_folder |
|
275 |
||
276 |
- name: copy irinotes backend build |
|
277 |
copy: |
|
278 |
src: "{{backend_build_dir}}/dist/irinotes-{{backend_pkg_version}}.tar.gz" |
|
279 |
dest: "{{backend_temp_folder.path}}/irinotes-{{backend_pkg_version}}.tar.gz" |
|
280 |
||
281 |
- name: virtualenv remove irinotes |
|
282 |
pip: |
|
283 |
virtualenv: "{{backend_venv}}" |
|
284 |
name: irinotes |
|
285 |
state: absent |
|
286 |
notify: restart irinotes backend service |
|
287 |
||
288 |
- name: virtualenv install irinotes |
|
289 |
pip: |
|
290 |
virtualenv: "{{backend_venv}}" |
|
291 |
name: "file://{{backend_temp_folder.path}}/irinotes-{{backend_pkg_version}}.tar.gz" |
|
292 |
notify: restart irinotes backend service |
|
293 |
||
|
188
00cf90eb0f5a
Correct index file and add a favicon. increment version
ymh <ymh.work@gmail.com>
parents:
184
diff
changeset
|
294 |
- name: add the manage command |
|
00cf90eb0f5a
Correct index file and add a favicon. increment version
ymh <ymh.work@gmail.com>
parents:
184
diff
changeset
|
295 |
template: |
|
00cf90eb0f5a
Correct index file and add a favicon. increment version
ymh <ymh.work@gmail.com>
parents:
184
diff
changeset
|
296 |
src: "manage.j2" |
|
00cf90eb0f5a
Correct index file and add a favicon. increment version
ymh <ymh.work@gmail.com>
parents:
184
diff
changeset
|
297 |
dest: "{{backend_venv}}/bin/manage" |
|
00cf90eb0f5a
Correct index file and add a favicon. increment version
ymh <ymh.work@gmail.com>
parents:
184
diff
changeset
|
298 |
mode: 0755 |
|
00cf90eb0f5a
Correct index file and add a favicon. increment version
ymh <ymh.work@gmail.com>
parents:
184
diff
changeset
|
299 |
|
| 180 | 300 |
- name: irinotes migrate |
301 |
command: "{{backend_venv}}/bin/django-admin migrate --noinput" |
|
302 |
args: |
|
303 |
chdir: "{{backend_venv}}" |
|
304 |
environment: |
|
305 |
DJANGO_SETTINGS_MODULE: "irinotes.settings" |
|
306 |
IRINOTES_CONFIG_BASE: "{{backend_config_base}}" |
|
307 |
become: yes |
|
308 |
become_user: uwsgi |
|
309 |
notify: restart irinotes backend service |
|
310 |
||
311 |
- name: irinotes collectstatic |
|
312 |
command: "{{backend_venv}}/bin/django-admin collectstatic --noinput -c" |
|
313 |
args: |
|
314 |
chdir: "{{backend_venv}}" |
|
315 |
environment: |
|
316 |
DJANGO_SETTINGS_MODULE: "irinotes.settings" |
|
317 |
IRINOTES_CONFIG_BASE: "{{backend_config_base}}" |
|
318 |
become: yes |
|
319 |
become_user: uwsgi |
|
320 |
notify: restart irinotes backend service |
|
321 |
||
322 |
always: |
|
323 |
- name: remove temp folder |
|
324 |
file: |
|
325 |
state: absent |
|
326 |
path: "{{backend_temp_folder.path}}" |
|
327 |
when: backend_temp_folder is defined |
|
328 |
||
329 |
||
330 |
- name: copy backend uwsgi config |
|
331 |
template: |
|
332 |
src: "uwsgi_irinotes.yml.j2" |
|
333 |
dest: "{{backend_config_base}}/uwsgi_irinotes.yml" |
|
334 |
notify: restart irinotes backend service |
|
335 |
||
336 |
- name: copy annotations api supervisor config |
|
337 |
template: |
|
338 |
src: "supervisord_irinotes_backend.ini.j2" |
|
339 |
dest: "{{backend_supervisor_conf_path}}/irinotes_backend.ini" |
|
340 |
notify: restart irinotes backend service |
|
341 |
||
342 |
- name: Add uwsgi app (reread + add) |
|
343 |
supervisorctl: name=irinotes_backend state=present |
|
344 |
||
345 |
handlers: |
|
346 |
- name: reload backend service supervisorctl |
|
347 |
listen: "restart irinotes backend service" |
|
348 |
supervisorctl: |
|
349 |
name: irinotes_backend |
|
350 |
state: restarted |
|
351 |
ignore_errors: yes |