This repository has been archived by the owner on Jan 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-overlay.yml
123 lines (108 loc) · 3.4 KB
/
deploy-overlay.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
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
---
- name: Setup registry and prepare the application image
gather_facts: no
hosts: localhost
environment:
DOCKER_HOST: "{{ DOCKER_HOST_IP }}:2375"
tasks:
- name: Fetch the up-to-date Consul image from DockerHub
docker_image:
name: consul
tag: latest
pull: yes
- name: Ensure the Consul master container is up and running
docker_container:
name: dev-consul
image: consul
state: started
network_mode: host
command: [consul, agent, "-data-dir=/consul/data/", -server, -bootstrap, "-bind={{ DOCKER_HOST_IP }}"]
- name: Setup an overlay network master
docker_network:
name: test_overlay
driver: overlay
ipam_options:
subnet: '10.10.10.0/24'
- name: Ensure the registry container is up and running
docker_container:
name: registry
image: registry:2
state: started
ports:
- "5000:5000"
- name: Build an image and push it to the registry
docker_image:
path: ../docker-compose
name: "{{ REGISTRY_URL }}/{{ IMAGE_NAME }}"
tag: "{{ IMAGE_TAG }}"
push: yes
- name: Deploy application image
gather_facts: yes
hosts: back
tasks:
- name: Copy requirements.txt to remote hosts
copy:
src: requirements.txt
dest: /tmp/requirements.txt
- name: Make sure python requirements are met
pip:
requirements: /tmp/requirements.txt
extra_args: --disable-pip-version-check
- name: Fetch the up-to-date Consul image from DockerHub
docker_image:
name: consul
tag: latest
pull: yes
- name: Ensure the Consul container is up and running in client mode
docker_container:
name: consul-client
image: consul
state: started
network_mode: host
command: [consul, agent, "-data-dir=/consul/data/", "-bind={{ ansible_default_ipv4.address }}", "-retry-join={{ DOCKER_HOST_IP }}"]
env:
CONSUL_LOCAL_CONFIG: {"leave_on_terminate": true}
- name: Pull the docker image from the registry
docker_image:
name: "{{ REGISTRY_URL }}/{{ IMAGE_NAME }}:{{ IMAGE_TAG }}"
repository: "{{ REGISTRY_URL }}"
use_tls: no
state: present
- name: Setup an overlay network
docker_network:
name: test_overlay
driver: overlay
ipam_options:
subnet: '10.10.10.0/24'
- name: Create the web container and run it
docker_container:
name: "app_example_web-{{ ansible_hostname }}"
image: "{{ REGISTRY_URL }}/{{ IMAGE_NAME }}:{{ IMAGE_TAG }}"
state: started
restart: yes
purge_networks: yes
networks:
- name: test_overlay
ports:
- "80:8000"
- name: Create the nodes container and run it
docker_container:
name: "app_example_nodes-{{ ansible_hostname }}"
image: "{{ REGISTRY_URL }}/{{ IMAGE_NAME }}:{{ IMAGE_TAG }}"
state: started
restart: yes
purge_networks: yes
networks:
- name: test_overlay
ports:
- 239.255.0.42:8000:8000
- name: Shutdown the registry
gather_facts: no
hosts: localhost
environment:
DOCKER_HOST: "{{ DOCKER_HOST_IP }}:2375"
tasks:
- name: Shutdown and remove the registry container
docker_container:
name: registry
state: absent