-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add docker localtest * add MYSQL_ROOT_HOST
- Loading branch information
Showing
6 changed files
with
135 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/libexec/ | ||
/.vendor/ | ||
.idea/ | ||
*.tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
services: | ||
mysql-primary: | ||
image: $TEST_MYSQL_IMAGE | ||
container_name: mysql-primary | ||
command: --server-id=1 --log-bin=mysql-bin --binlog-format=row --gtid-mode=ON --enforce-gtid-consistency=ON | ||
environment: | ||
MYSQL_ROOT_PASSWORD: opensesame | ||
MYSQL_ROOT_HOST: '%' | ||
MYSQL_DATABASE: test | ||
MYSQL_TCP_PORT: 3307 | ||
ports: | ||
- '3307:3307' | ||
expose: | ||
- '3307' | ||
mysql-replica: | ||
image: $TEST_MYSQL_IMAGE | ||
container_name: mysql-replica | ||
command: --server-id=2 --log-bin=mysql-bin --binlog-format=row --gtid-mode=ON --enforce-gtid-consistency=ON --log-slave-updates=ON | ||
environment: | ||
MYSQL_ROOT_PASSWORD: opensesame | ||
MYSQL_ROOT_HOST: '%' | ||
MYSQL_DATABASE: test | ||
MYSQL_TCP_PORT: 3308 | ||
ports: | ||
- '3308:3308' | ||
expose: | ||
- '3308' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
|
||
# This script starts two MySQL docker containers in a primary-replica setup | ||
# which can be used for running the replica tests in localtests/ . | ||
# Set the environment var TEST_MYSQL_IMAGE to change the docker image. | ||
# | ||
# Usage: | ||
# docker-gh-ost-replica-tests up start the containers | ||
# docker-gh-ost-replica-tests down remove the containers | ||
# docker-gh-ost-replica-tests run run replica tests on the containers | ||
|
||
set -e | ||
|
||
GH_OST_ROOT=$(git rev-parse --show-toplevel) | ||
if [[ ":$PATH:" != *":$GH_OST_ROOT:"* ]]; then | ||
export PATH="${PATH}:${GH_OST_ROOT}/script" | ||
fi | ||
|
||
poll_mysql() { | ||
CTR=0 | ||
cmd="gh-ost-test-mysql-$1" | ||
while ! $cmd -e "select 1;" > /dev/null 2>&1 | ||
do | ||
sleep 1 | ||
CTR=$((CTR + 1)) | ||
if [ $CTR -gt 30 ]; then | ||
echo " ❌ MySQL $1 failed to start" | ||
return 1 | ||
fi | ||
done | ||
echo " ✔ MySQL $1 OK" | ||
return 0 | ||
} | ||
|
||
setup() { | ||
[ -z "$TEST_MYSQL_IMAGE" ] && TEST_MYSQL_IMAGE="mysql:8.0.39" | ||
|
||
echo "Starting MySQL $TEST_MYSQL_IMAGE containers..." | ||
compose_file="$GH_OST_ROOT/localtests/docker-compose.yml" | ||
(TEST_MYSQL_IMAGE="$TEST_MYSQL_IMAGE" envsubst < "$compose_file") > "$compose_file.tmp" | ||
docker compose -f "$compose_file.tmp" up -d --wait | ||
|
||
echo "Waiting for MySQL..." | ||
poll_mysql "master" || exit 1 | ||
poll_mysql "replica" || exit 1 | ||
|
||
echo -n "Setting up replication..." | ||
gh-ost-test-mysql-master -e "create user if not exists 'repl'@'%' identified with 'mysql_native_password' by 'repl';" | ||
gh-ost-test-mysql-master -e "grant replication slave on *.* to 'repl'@'%'; flush privileges;" | ||
gh-ost-test-mysql-master -e "create user if not exists 'gh-ost'@'%' identified by 'gh-ost';" | ||
gh-ost-test-mysql-master -e "grant all on *.* to 'gh-ost'@'%';" | ||
|
||
sleep 1 | ||
gh-ost-test-mysql-replica -e "change master to master_host='mysql-primary', master_port=3307, master_user='repl', master_password='repl', master_auto_position=1;" | ||
gh-ost-test-mysql-replica -e "start slave;" | ||
echo "OK" | ||
} | ||
|
||
teardown() { | ||
echo "Stopping containers..." | ||
docker stop mysql-replica | ||
docker stop mysql-primary | ||
echo "Removing containers..." | ||
docker rm mysql-replica | ||
docker rm mysql-primary | ||
} | ||
|
||
main() { | ||
if [[ "$1" == "up" ]]; then | ||
setup | ||
elif [[ "$1" == "down" ]]; then | ||
teardown | ||
elif [[ "$1" == "run" ]]; then | ||
shift 1 | ||
"$GH_OST_ROOT/localtests/test.sh" -d "$@" | ||
fi | ||
} | ||
|
||
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
# | ||
# This executes a command on the mysql-primary docker container created | ||
# from localtests/docker-compose.yml. It's used by localtests/test.sh. | ||
|
||
MYSQL_PWD=opensesame mysql -uroot -h0.0.0.0 -P3307 "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
# | ||
# This executes a command on the mysql-replica docker container created | ||
# from localtests/docker-compose.yml. It's used by localtests/test.sh. | ||
|
||
MYSQL_PWD=opensesame mysql -uroot -h0.0.0.0 -P3308 "$@" |