|
1 | 1 | #!/bin/bash |
2 | 2 | set -xe |
3 | 3 |
|
4 | | -DOCKER_COMPOSE_VERSION=1.29.2 |
| 4 | +DOCKER_COMPOSE_VERSION=v2.2.3 |
5 | 5 |
|
6 | 6 | sudo apt-get update |
7 | 7 | sudo apt-get install -y netcat-openbsd make gcc |
8 | 8 |
|
9 | 9 | sudo curl -o /usr/local/bin/docker-compose -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` |
10 | 10 | sudo chmod +x /usr/local/bin/docker-compose |
11 | 11 |
|
12 | | -docker-compose up -d mysql-1 mysql-2 |
| 12 | +if [ "$MYSQL_VERSION" == "8.0" ]; then |
| 13 | + docker-compose -f docker-compose_8.0.yml up -d mysql-1 mysql-2 |
| 14 | +else |
| 15 | + docker-compose up -d mysql-1 mysql-2 |
| 16 | +fi |
13 | 17 |
|
14 | | -# We need a way to check if the mysql servers have booted or not before running |
15 | | -# the tests and this way is slightly faster than installing mysql-client |
| 18 | +MAX_ATTEMPTS=60 |
16 | 19 |
|
17 | | -wait_for_mysql() { |
18 | | - port=$1 |
19 | | - echo "Waiting for MySQL at port $port..." |
| 20 | +function wait_for_version () { |
20 | 21 | attempts=0 |
21 | | - while ! nc -w 1 localhost $port | grep -q "mysql"; do |
| 22 | + until docker exec -t $1 mysql -N -s -u root -e "select @@version"; do |
22 | 23 | sleep 1 |
23 | 24 | attempts=$((attempts + 1)) |
24 | | - if (( attempts > 60 )); then |
25 | | - echo "ERROR: mysql $port was not started." >&2 |
26 | | - exit 1 |
| 25 | + if (( attempts > $MAX_ATTEMPTS )); then |
| 26 | + echo "ERROR: $1 was not started." >&2 |
| 27 | + exit 1 |
27 | 28 | fi |
28 | 29 | done |
29 | | - echo "MySQL at port $port has started!" |
30 | 30 | } |
31 | 31 |
|
32 | | -wait_for_mysql 29291 |
33 | | -wait_for_mysql 29292 |
| 32 | +wait_for_configuration () { |
| 33 | + attempts=0 |
| 34 | + # we do need to see the "root@%" user configured, so wait for that |
| 35 | + until mysql --port $1 --protocol tcp --skip-password -N -s -u root -e "select host from mysql.user where user = 'root';" 2>/dev/null | grep -q '%'; do |
| 36 | + sleep 1 |
| 37 | + attempts=$((attempts + 1)) |
| 38 | + if (( attempts > $MAX_ATTEMPTS )); then |
| 39 | + echo "ERROR: $1 was not started." >&2 |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | + done |
| 43 | +} |
| 44 | + |
| 45 | +wait_for_version "ghostferry-mysql-1-1" |
| 46 | +wait_for_version "ghostferry-mysql-2-1" |
34 | 47 |
|
35 | | -docker-compose exec -T mysql-1 mysql -u root -e "select @@version" |
| 48 | +wait_for_configuration 29291 |
| 49 | +wait_for_configuration 29292 |
0 commit comments