-
Notifications
You must be signed in to change notification settings - Fork 0
/
rolling_update.yml
71 lines (59 loc) · 1.96 KB
/
rolling_update.yml
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
---
- hosts: all
pre_tasks:
- name: Copy maintenance setup
copy:
src: rolling_update/maintenance
dest: "{{ app_home }}"
tasks:
- name: Pull latest app image
shell: docker pull skyderby/app:latest
- name: Stop web-server
shell: docker-compose stop web
args:
chdir: "{{ app_home }}"
- name: Remove maintenance web-server if present
shell: docker rm -f nginx-maintenance
ignore_errors: yes
- name: Deploy maintenance web-server
shell: >
docker run -d
-p 80:80 -p 443:443
--volume {{ app_home }}/maintenance/nginx.conf:/etc/nginx/nginx.conf:ro
--volume {{ app_home }}/maintenance/maintenance.html:/opt/app/maintenance.html:ro
--volume {{ app_home }}/ssl:/etc/pki/nginx:ro
--volume /etc/letsencrypt:/etc/letsencrypt:ro
--name nginx-maintenance
nginx:stable
args:
chdir: "{{ app_home }}"
- name: Stop app and workers containers
shell: docker-compose stop app workers
args:
chdir: "{{ app_home }}"
- name: Remove app and workers containers
shell: docker-compose rm -v -f app workers
args:
chdir: "{{ app_home }}"
- name: Deploy new version
shell: docker-compose up --no-deps --force-recreate -d app workers
args:
chdir: "{{ app_home }}"
- name: Wait app to start
shell: 'docker-compose exec -T app curl --fail http://127.0.0.1:8000/ping || exit 1'
register: result
until: result|success
retries: 30
delay: 1
changed_when: False
args:
chdir: "{{ app_home }}"
- name: Remove maintenance web-server
shell: docker rm -f -v nginx-maintenance
- name: Starting web-server
shell: docker-compose up -d --no-deps web
args:
chdir: "{{ app_home }}"
- name: Clean old images
shell: docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
ignore_errors: yes