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.yml
93 lines (82 loc) · 2.36 KB
/
deploy.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
---
- name: Setup registry and prepare the application image
gather_facts: no
hosts: localhost
environment:
DOCKER_HOST: "{{ DOCKER_HOST_IP }}:2375"
tasks:
- 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: no
hosts: all
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: 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 the first network
docker_network:
name: test_nw
ipam_options:
subnet: '10.1.4.0/24'
gateway: 10.1.4.100
- name: Setup the second network
docker_network:
name: test_nw2
ipam_options:
subnet: '10.2.3.0/24'
- name: Create the web container and run it
docker_container:
name: app_example_web
image: "{{ REGISTRY_URL }}/{{ IMAGE_NAME }}:{{ IMAGE_TAG }}"
state: started
restart: yes
purge_networks: yes
networks:
- name: test_nw
ports:
- "80:8000"
- name: Create the nodes container and run it
docker_container:
name: app_example_nodes
image: "{{ REGISTRY_URL }}/{{ IMAGE_NAME }}:{{ IMAGE_TAG }}"
state: started
restart: yes
purge_networks: yes
networks:
- name: test_nw
- name: test_nw2
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