-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker_pull_and_run.yml
95 lines (84 loc) · 2.96 KB
/
docker_pull_and_run.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
- name: Pull Docker images and run containers for frontend, backend, and Redis
hosts: localhost
connection: local
become: true
tasks:
- name: Set default values if variables are not defined
set_fact:
BACKEND_IMAGE: "{{ BACKEND_IMAGE | default('container.psi.ch/controls-ci/data_board_backend') }}"
FRONTEND_IMAGE: "{{ FRONTEND_IMAGE | default('container.psi.ch/controls-ci/data_board_frontend') }}"
REDIS_IMAGE: "{{ REDIS_IMAGE | default('redis') }}"
BACKEND_PORT: "{{ BACKEND_PORT | default(8080) }}"
BACKEND_HOST: "{{ BACKEND_HOST | default('http://' + ansible_default_ipv4.address) }}"
FRONTEND_PORT: "{{ FRONTEND_PORT | default(80) }}"
REDIS_PORT: "{{ REDIS_PORT | default(6379) }}"
- name: Create Docker network
docker_network:
name: data_board_network
driver: bridge
- name: Pull Docker image for Redis from registry
docker_image:
name: "{{ REDIS_IMAGE }}"
source: pull
- name: Run Docker container for Redis with custom config inline
docker_container:
name: data_board_redis
image: "{{ REDIS_IMAGE }}"
state: started
restart_policy: unless-stopped
ports:
- "{{ REDIS_PORT }}:6379"
detach: true
image_name_mismatch: recreate
command: ["redis-server", "--save", '""', "--appendonly", "no"]
- name: Add Redis container to Docker network
docker_network:
name: data_board_network
connected:
- data_board_redis
appends: yes
- name: Pull Docker image for backend from registry
docker_image:
name: "{{ BACKEND_IMAGE }}"
source: pull
- name: Run Docker container for backend
docker_container:
name: data_board_backend
image: "{{ BACKEND_IMAGE }}"
state: started
restart_policy: unless-stopped
ports:
- "{{ BACKEND_PORT }}:8080"
detach: true
env:
REDIS_HOST: "data_board_redis"
REDIS_PORT: "{{ REDIS_PORT }}"
image_name_mismatch: recreate
- name: Add backend container to Docker network
docker_network:
name: data_board_network
connected:
- data_board_backend
appends: yes
- name: Pull Docker image for frontend from registry
docker_image:
name: "{{ FRONTEND_IMAGE }}"
source: pull
- name: Run Docker container for frontend
docker_container:
name: data_board_frontend
image: "{{ FRONTEND_IMAGE }}"
state: started
restart_policy: unless-stopped
ports:
- "{{ FRONTEND_PORT }}:80"
detach: true
env:
DATA_BOARD_PUBLIC_BACKEND_URL: "{{ BACKEND_HOST }}:{{ BACKEND_PORT }}"
image_name_mismatch: recreate
- name: Add frontend container to Docker network
docker_network:
name: data_board_network
connected:
- data_board_frontend
appends: yes