-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zero-Downtime-Deployment
161 lines (124 loc) · 3.61 KB
/
Zero-Downtime-Deployment
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
Zero downtime deployment with Swarm, HEALTHCHECK and Dnsrr:
https://www.youtube.com/watch?v=dLBGoaMz7dQ
https://github.com/BretFisher/browncoat
https://www.youtube.com/watch?v=oWrwi1NiViw
https://medium.com/better-programming/zero-downtime-deployment-with-docker-swarm-d84d8d9d9a14
https://medium.com/better-programming/zero-downtime-deployment-with-docker-swarm-d84d8d9d9a14
<if you update the nginx:1.18/latest image, you'll see that ninx run 6 replicas until the new image is stable!!
Don't forget to install visualizer to see the process in live.
/> docker service create --name=viz --publish=8080:8080/tcp --constraint=node.role==manager --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock bretfisher/visualizer
version: '3.7'
services:
nginx:
image: "nginx:latest"
ports:
- '80:80'
deploy:
replicas: 4
update_config:
parallelism: 2
order: start-first
failure_action: rollback
delay: 10s
rollback_config:
parallelism: 0
order: stop-first
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s
healthcheck:
test: ["CMD", "curl", "--fail", "http://18.218.210.112"]
interval: 20s
timeout: 10s
retries: 3
/> docker stack deploy --compose-file=docker-compose.yml nginx
================================================================================
<Important project>
vim dockerfile:
FROM php:7.2.2-apache
COPY ./index.php /var/www/html
RUN docker-php-ext-install mysqli
<First, build the image, docker build -t apach:latest . >
--------------------------------------------------------------------------------
vim index.php:
<?php
define('HOST', "18.218.210.112");
define('DBUSER', "root");
define('PASS', "1234");
define('DB', "myexample");
define('PORT', 3306);
$link=mysqli_connect(HOST,DBUSER,PASS,DB,PORT);
// Check connection
if (mysqli_connect_errno($link)){
echo "Failure to connect: " . mysqli_connect_error();
}
$sql = "SELECT * FROM mytable";
$result = $link->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["myfield"]. "<br>";
}
} else {
echo "0 results";
}
$link->close();
?>
--------------------------------------------------------------------------------
vim init.sql:
CREATE DATABASE myexample;
USE myexample;
CREATE TABLE mytable (myfield VARCHAR(20));
INSERT INTO mytable VALUES ('Hello'), ('Dolly');
--------------------------------------------------------------------------------
vim docker-compose.yml:
version: '3.7'
services:
db:
environment:
MYSQL_ROOT_PASSWORD: 1234
image: "mysql:5.7"
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
- data-mysql:/var/lib/mysql
ports:
- '3306:3306'
deploy:
replicas: 2
healthcheck:
test: ["CMD-SHELL", 'mysqladmin ping']
interval: 10s
timeout: 5s
retries: 10
nginx:
image: apach:latest
depends_on:
- db
ports:
- '80:80'
deploy:
replicas: 2
update_config:
parallelism: 2
order: start-first
failure_action: rollback
delay: 10s
rollback_config:
parallelism: 0
order: stop-first
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s
healthcheck:
test: ["CMD", "curl", "--fail", "http://18.218.210.112"]
interval: 20s
timeout: 10s
retries: 3
volumes:
data-mysql:
driver: local
/> docker stack deploy --compose-file=docker-compose.yml nginx