-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.travis.yml
191 lines (158 loc) · 11.3 KB
/
.travis.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
---
sudo: required
dist: trusty
services:
- docker
script:
# Build docker image
- cd 5.7/
- docker build -t maestrano/mysql:travis . > /dev/null 2>&1
# Create volumes
- mkdir -p vol-m0 vol-m1 vol-m2
# Configuration
- HOST_PUB_IP=$(ifconfig | grep "eth0 " -A 1 | grep "inet " | cut -d':' -f2 | cut -d' ' -f1)
- PORT_NODE_0=33000
- VOL_NODE_0=$(pwd)/vol-m0
- PORT_NODE_1=33001
- VOL_NODE_1=$(pwd)/vol-m1
- PORT_NODE_2=33002
- VOL_NODE_2=$(pwd)/vol-m2
- PORT_NODE_3=33005
- VOL_NODE_3=$(pwd)/vol-m3
- CLUSTER_CONFIG=$HOST_PUB_IP:$PORT_NODE_1:1,$HOST_PUB_IP:$PORT_NODE_2:2
#============================================================================
# Test standalone MySQL
#============================================================================
# Start standalone instance
- docker run -d -p $PORT_NODE_0:3306 -v $VOL_NODE_0:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=app_db --name m0 maestrano/mysql:travis
# Wait for standalone instance to be up
- for i in {30..0}; do mysql -P $PORT_NODE_0 -h $HOST_PUB_IP -u root -proot -e 'SELECT 1' &> /dev/null && break; sleep 1; done
- if [ "$i" = 0 ]; then echo 'MySQL startup process failed.'; exit 1; fi
# Create data
- mysql -P $PORT_NODE_0 -h $HOST_PUB_IP -u root -proot -e "create table app_db.dummy (id varchar(10));"
- mysql -P $PORT_NODE_0 -h $HOST_PUB_IP -u root -proot -e "show tables in app_db;"
- mysql -P $PORT_NODE_0 -h $HOST_PUB_IP -u root -proot -e "insert into app_db.dummy VALUES(RAND(1000))"
- "record_count=$(mysql -P $PORT_NODE_0 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- '[ "$record_count" == "1" ]'
# UTF-8 support
- mysql -P $PORT_NODE_0 -h $HOST_PUB_IP -u root -proot -e "insert into app_db.dummy VALUES('£™Τὴಬಾè')"
- "record_count=$(mysql -P $PORT_NODE_0 -h $HOST_PUB_IP -u root -proot -BNe \"SELECT COUNT(*) FROM app_db.dummy WHERE id = \'£™Τὴಬಾè'\")"
- '[ "$record_count" == "1" ]'
- mysql -P $PORT_NODE_0 -h $HOST_PUB_IP -u root -proot -e "delete from app_db.dummy WHERE id = '£™Τὴಬಾè'"
# Perform successive backups
- for i in {30..0}; do docker exec -it m0 /usr/local/bin/backup.sh; sleep 1; done
# Check that only 20 backups are kept
- "bkup_count=$(docker exec -it m0 ls -l /snapshots | grep sql.gz | wc -l)"
- '[ "$bkup_count" == "20" ]'
# Perform recovery and check integrity
- docker exec -it m0 bash -c "gunzip --stdout /snapshots/\$(ls -1r /snapshots/ | head -n 1) | mysql -u root -proot"
- "record_count=$(mysql -P $PORT_NODE_0 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- '[ "$record_count" == "1" ]'
# Destroy container
- docker rm -f m0
#============================================================================
# Backward compatibility: Initialize m0 volume using official mysql image
#============================================================================
- docker run -d -p $PORT_NODE_1:3306 -v $VOL_NODE_1:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=app_db --name m1 mysql:5.7
- for i in {30..0}; do mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -e 'SELECT 1' &> /dev/null && break; sleep 1; done
- mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -e "create table app_db.dummy_original (id varchar(10));"
- mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -e "insert into app_db.dummy_original VALUES(RAND(1000))"
- docker stop m1
- docker rm -f m1
#============================================================================
# Test MySQL cluster: Master-Master setup
#============================================================================
# Start cluster instance 1
- docker run -d -p $PORT_NODE_1:3306 -v $VOL_NODE_1:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=app_db -e SELF_HOST=$HOST_PUB_IP -e SELF_PORT=$PORT_NODE_1 -e MYSQL_REP_PEERS=$HOST_PUB_IP:$PORT_NODE_1:1 --name m1 maestrano/mysql:travis
# Wait for cluster instance 1 to be up
- for i in {30..0}; do mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -e 'SELECT 1' &> /dev/null && break; sleep 1; done
- if [ "$i" = 0 ]; then echo 'MySQL startup process failed.'; exit 1; fi
# Create data
- mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -e "create table app_db.dummy (id varchar(10));"
- mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -e "show tables in app_db;"
- mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -e "insert into app_db.dummy VALUES(RAND(1000))"
- "record_count=$(mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- '[ "$record_count" == "1" ]'
# Create replica 2 and insert data on master in parallel
- docker run -d -p $PORT_NODE_2:3306 -v $VOL_NODE_2:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=app_db -e SELF_HOST=$HOST_PUB_IP -e SELF_PORT=$PORT_NODE_2 -e MYSQL_REP_PEERS=$HOST_PUB_IP:$PORT_NODE_1:1,$HOST_PUB_IP:$PORT_NODE_2:2 --name m2 maestrano/mysql:travis
- for i in {1000..0}; do mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -e "insert into app_db.dummy VALUES(RAND(1000))" 2>/dev/null; done
# Wait for cluster instance 2 to be up
- for i in {30..0}; do mysql -P $PORT_NODE_2 -h $HOST_PUB_IP -u root -proot -e 'SELECT 1' &> /dev/null && break; sleep 1; done
- if [ "$i" = 0 ]; then echo 'MySQL startup process failed.'; exit 1; fi
# Ensure counts are equal
- "count_node_1=$(mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- "count_node_2=$(mysql -P $PORT_NODE_2 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- '[ "$count_node_1" == "$count_node_2" ]'
- last_count=$count_node_1
# Create replica 3 and insert data on master in parallel
- docker run -d -p $PORT_NODE_3:3306 -v $VOL_NODE_3:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=app_db -e SELF_HOST=$HOST_PUB_IP -e SELF_PORT=$PORT_NODE_3 -e MYSQL_REP_PEERS=$HOST_PUB_IP:$PORT_NODE_1:1,$HOST_PUB_IP:$PORT_NODE_2:2,$HOST_PUB_IP:$PORT_NODE_3:3 --name m3 maestrano/mysql:travis
- for i in {1000..0}; do mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -e "insert into app_db.dummy VALUES(RAND(1000))" 2>/dev/null; done
# Wait for cluster instance 3 to be up
- for i in {30..0}; do mysql -P $PORT_NODE_3 -h $HOST_PUB_IP -u root -proot -e 'SELECT 1' &> /dev/null && break; sleep 1; done
- if [ "$i" = 0 ]; then echo 'MySQL startup process failed.'; exit 1; fi
# Ensure counts are equal
- "count_node_1=$(mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- "count_node_2=$(mysql -P $PORT_NODE_2 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- "count_node_3=$(mysql -P $PORT_NODE_3 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- '[ "$count_node_1" == "$count_node_2" ]'
- '[ "$count_node_1" == "$count_node_3" ]'
- last_count=$count_node_1
# Give some time to the circular replication to settle
- sleep 60
# Insert data on instance 2 then instance 3
- for i in {20..0}; do mysql -P $PORT_NODE_2 -h $HOST_PUB_IP -u root -proot -e "insert into app_db.dummy VALUES(RAND(1000))" 2>/dev/null; done
- for i in {20..0}; do mysql -P $PORT_NODE_3 -h $HOST_PUB_IP -u root -proot -e "insert into app_db.dummy VALUES(RAND(1000))" 2>/dev/null; done
# Ensure counts are equal
- "count_node_1=$(mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- "count_node_2=$(mysql -P $PORT_NODE_2 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- "count_node_3=$(mysql -P $PORT_NODE_3 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- '[ $count_node_1 -eq $count_node_2 ]'
- '[ $count_node_1 -eq $count_node_3 ]'
- '[ $count_node_1 -gt $last_count ]'
- last_count=$count_node_1
# Ensure counts on dummy_original are equal
- "count_node_1=$(mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy_original')"
- "count_node_2=$(mysql -P $PORT_NODE_2 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy_original')"
- "count_node_3=$(mysql -P $PORT_NODE_3 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy_original')"
- '[ $count_node_1 -eq $count_node_2 ]'
- '[ $count_node_1 -eq $count_node_3 ]'
#============================================================================
# Test MySQL cluster: Stop/Start second replica
#============================================================================
# Stop/start replica - insert data at the same time
- docker stop m2
- for i in {20..0}; do mysql -P $PORT_NODE_3 -h $HOST_PUB_IP -u root -proot -e "insert into app_db.dummy VALUES(RAND(1000))" 2>/dev/null; done
- docker start m2
- for i in {100..0}; do mysql -P $PORT_NODE_3 -h $HOST_PUB_IP -u root -proot -e "insert into app_db.dummy VALUES(RAND(1000))" 2>/dev/null; done
# Wait for cluster instance 2 to be up
- for i in {30..0}; do mysql -P $PORT_NODE_2 -h $HOST_PUB_IP -u root -proot -e 'SELECT 1' &> /dev/null && break; sleep 1; done
- if [ "$i" = 0 ]; then echo 'MySQL startup process failed.'; exit 1; fi
# Ensure counts are equal
- "count_node_1=$(mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- "count_node_2=$(mysql -P $PORT_NODE_2 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- "count_node_3=$(mysql -P $PORT_NODE_3 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- '[ $count_node_1 -eq $count_node_2 ]'
- '[ $count_node_1 -eq $count_node_3 ]'
- '[ $count_node_1 -gt $last_count ]'
- last_count=$count_node_1
#============================================================================
# Test MySQL cluster: Destroy/Create initial master
#============================================================================
# Destroy and recreate original master - insert data at the same time
- docker rm -f m1
- for i in {20..0}; do mysql -P $PORT_NODE_2 -h $HOST_PUB_IP -u root -proot -e "insert into app_db.dummy VALUES(RAND(1000))" 2>/dev/null; done
- docker run -d -p $PORT_NODE_1:3306 -v $VOL_NODE_1:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=app_db -e SELF_HOST=$HOST_PUB_IP -e SELF_PORT=$PORT_NODE_1 -e MYSQL_REP_PEERS=$HOST_PUB_IP:$PORT_NODE_1:1,$HOST_PUB_IP:$PORT_NODE_2:2,$HOST_PUB_IP:$PORT_NODE_3:3 --name m1 maestrano/mysql:travis
- for i in {100..0}; do mysql -P $PORT_NODE_2 -h $HOST_PUB_IP -u root -proot -e "insert into app_db.dummy VALUES(RAND(1000))" 2>/dev/null; done
# Wait for cluster instance 1 to be up
- for i in {30..0}; do mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -e 'SELECT 1' &> /dev/null && break; sleep 1; done
- if [ "$i" = 0 ]; then echo 'MySQL startup process failed.'; exit 1; fi
# Give some time to the circular replication to settle
- sleep 60
# Ensure counts are equal
- "count_node_1=$(mysql -P $PORT_NODE_1 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- "count_node_2=$(mysql -P $PORT_NODE_2 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- "count_node_3=$(mysql -P $PORT_NODE_3 -h $HOST_PUB_IP -u root -proot -BNe 'SELECT COUNT(*) FROM app_db.dummy')"
- '[ $count_node_1 -eq $count_node_2 ]'
- '[ $count_node_1 -eq $count_node_3 ]'
- '[ $count_node_1 -gt $last_count ]'
- last_count=$count_node_1