From bde34139f894d046fef98edb585a3d6515609fac Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Fri, 22 Nov 2019 19:01:21 +0000 Subject: [PATCH] put mysql in docker for ci Signed-off-by: Arthur Gautier --- .travis.yml | 6 ++- pymysqlreplication/tests/base.py | 2 - scripts/install_mysql.sh | 79 ++++++++++++++++++++++++++++++++ scripts/install_mysql56.sh | 61 ------------------------ scripts/install_mysql57.sh | 62 ------------------------- 5 files changed, 83 insertions(+), 127 deletions(-) create mode 100755 scripts/install_mysql.sh delete mode 100755 scripts/install_mysql56.sh delete mode 100755 scripts/install_mysql57.sh diff --git a/.travis.yml b/.travis.yml index 898f7071..5ad2cf00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ dist: trusty language: python +services: + - docker python: - "2.7" - "3.4" @@ -21,8 +23,8 @@ cache: - $HOME/bins before_script: - env | grep DB - - bash -c "if [ '$DB' = 'mysql57' ]; then sudo ./scripts/install_mysql57.sh; fi" - - bash -c "if [ '$DB' = 'mysql56' ]; then sudo ./scripts/install_mysql56.sh; fi" + - bash -c "if [ '$DB' = 'mysql57' ]; then sudo ./scripts/install_mysql.sh 5.7; fi" + - bash -c "if [ '$DB' = 'mysql56' ]; then sudo ./scripts/install_mysql.sh 5.6; fi" script: - "sudo $(which nosetests) pymysqlreplication.tests.test_abnormal:TestAbnormalBinLogStreamReader.test_no_trailing_rotate_event" - "nosetests -e test_no_trailing_rotate_event" diff --git a/pymysqlreplication/tests/base.py b/pymysqlreplication/tests/base.py index 15df2751..e1cd2bda 100644 --- a/pymysqlreplication/tests/base.py +++ b/pymysqlreplication/tests/base.py @@ -31,8 +31,6 @@ def setUp(self): "charset": "utf8", "db": "pymysqlreplication_test" } - if os.getenv("TRAVIS") is not None and db == "mysql56": - self.database["user"] = "travis" self.conn_control = None db = copy.copy(self.database) diff --git a/scripts/install_mysql.sh b/scripts/install_mysql.sh new file mode 100755 index 00000000..59cba50f --- /dev/null +++ b/scripts/install_mysql.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +set -x + +# Remove old mysql version +/etc/init.d/mysql stop || true +apt-get remove mysql-common mysql-server-5.5 mysql-server-core-5.5 mysql-client-5.5 mysql-client-core-5.5 +apt-get autoremove + +VERSION=$1 + +docker pull percona:$VERSION + +# Cleanup old mysql datas +rm -rf /var/ramfs/mysql/ +rm -rf /var/ramfs/mysql-ctl/ +mkdir /var/ramfs/mysql/ +mkdir /var/ramfs/mysql-ctl/ +chmod 777 /var/ramfs/mysql/ +chmod 777 /var/ramfs/mysql-ctl/ +rm -rf /var/run/mysqld/ +mkdir /var/run/mysqld/ +chmod 777 /var/run/mysqld/ + +OPTIONS="" +# Replication +OPTIONS="$OPTIONS --log_bin=mysql-bin" +OPTIONS="$OPTIONS --binlog-format=row" +# Gtid +OPTIONS="$OPTIONS --log_slave_updates" +OPTIONS="$OPTIONS --gtid_mode=ON" +OPTIONS="$OPTIONS --enforce-gtid-consistency=ON" + +MASTER_OPTIONS="$OPTIONS --server-id=1" +MASTER_OPTIONS="$MASTER_OPTIONS --datadir=/var/ramfs/mysql/" +MASTER_OPTIONS="$MASTER_OPTIONS --socket=/var/run/mysqld/mysqld.sock" + +docker run --publish 3306:3306 \ + -d --name master \ + -e MYSQL_ALLOW_EMPTY_PASSWORD=yes\ + -v /var/ramfs/mysql/:/var/ramfs/mysql/\ + percona:$VERSION\ + $MASTER_OPTIONS +# -v /var/run/mysqld/:/var/run/mysqld/\ + +CTL_OPTIONS="$OPTIONS --server-id=2" +CTL_OPTIONS="$CTL_OPTIONS --socket=/var/run/mysqld/mysqld-ctl.sock" +CTL_OPTIONS="$CTL_OPTIONS --datadir=/var/ramfs/mysql-ctl/" +CTL_OPTIONS="$CTL_OPTIONS --pid-file=/var/lib/mysql/mysql-ctl.pid" + +docker run --publish 3307:3306 \ + -d --name ctl \ + -e MYSQL_ALLOW_EMPTY_PASSWORD=yes\ + -v /var/ramfs/mysql-ctl/:/var/ramfs/mysql-ctl/\ + percona:$VERSION\ + $CTL_OPTIONS +# -v /var/run/mysqld/:/var/run/mysqld/\ + +for i in $(seq 0 40); do + sleep 1; + mysql -u root --host=127.0.0.1 --port=3306 -e 'SELECT VERSION();' + if [ $? -eq 0 ]; then + break 2; + fi +done + +for i in $(seq 0 40); do + sleep 1; + mysql -u root --host=127.0.0.1 --port=3307 -e 'SELECT VERSION();' + if [ $? -eq 0 ]; then + break 2; + fi +done + +docker logs master +docker logs ctl + +mysql -u root --host=127.0.0.1 --port=3306 -e 'CREATE DATABASE pymysqlreplication_test;' +mysql -u root --host=127.0.0.1 --port=3307 -e "CREATE DATABASE pymysqlreplication_test;" diff --git a/scripts/install_mysql56.sh b/scripts/install_mysql56.sh deleted file mode 100755 index 6ca76e6e..00000000 --- a/scripts/install_mysql56.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env bash - -set -x - -# Remove old mysql version -/etc/init.d/mysql stop || true -apt-get remove mysql-common mysql-server-5.5 mysql-server-core-5.5 mysql-client-5.5 mysql-client-core-5.5 -apt-get autoremove - -# Config -sed -i'' 's/table_cache/table_open_cache/' /etc/mysql/my.cnf -sed -i'' 's/log_slow_queries/slow_query_log/' /etc/mysql/my.cnf - -# Install new mysql version -echo deb [trusted=yes] http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.6 | tee /etc/apt/sources.list.d/mysql.list -apt-get update -env DEBIAN_FRONTEND=noninteractive apt-get install -o Dpkg::Options::='--force-confold' -q -y mysql-server mysql-client - -# Cleanup old mysql datas -rm -rf /var/ramfs/mysql/ -rm -rf /var/ramfs/mysql-ctl/ -mkdir /var/ramfs/mysql/ -mkdir /var/ramfs/mysql-ctl/ -chown mysql /var/ramfs/mysql/ -chown mysql /var/ramfs/mysql-ctl/ - -# Config -echo '[mysqld]' | tee /etc/mysql/conf.d/replication.cnf -echo 'log-bin=mysql-bin' | tee -a /etc/mysql/conf.d/replication.cnf -echo 'server-id=1' | tee -a /etc/mysql/conf.d/replication.cnf -echo 'binlog-format = row' | tee -a /etc/mysql/conf.d/replication.cnf - -/etc/init.d/mysql stop || true - -# Install new datas -mysql_install_db --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/ramfs/mysql-ctl --verbose - -mysql_install_db --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/ramfs/mysql --verbose - -# Enable GTID -echo '[mysqld]' | tee /etc/mysql/conf.d/gtid.cnf -echo 'gtid_mode=ON' | tee -a /etc/mysql/conf.d/gtid.cnf -echo 'enforce_gtid_consistency' | tee -a /etc/mysql/conf.d/gtid.cnf -echo 'binlog_format=ROW' | tee -a /etc/mysql/conf.d/gtid.cnf -echo 'log_slave_updates' | tee -a /etc/mysql/conf.d/gtid.cnf - -# Start mysql (avoid errors to have logs) -/etc/init.d/mysql start || true -tail -1000 /var/log/syslog -nohup mysqld --log-bin=mysql-ctl-bin.log --server-id 2 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave-updates -P 3307 --socket=/var/run/mysqld/mysqld-ctl.sock --datadir=/var/ramfs/mysql-ctl --pid-file=/var/lib/mysql/mysql-ctl.pid --user=root & -#Give it time to start -sleep 5 -tail -1000 nohup.out - -mysql --version -mysql -e 'SELECT VERSION();' -mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO ''@'localhost';" -mysql -u root --port=3307 --socket=/var/run/mysqld/mysqld-ctl.sock -e "GRANT ALL PRIVILEGES ON *.* TO ''@'localhost';" - -mysql -e 'CREATE DATABASE pymysqlreplication_test;' -mysql -u root --port=3307 --socket=/var/run/mysqld/mysqld-ctl.sock -e "CREATE DATABASE pymysqlreplication_test;" diff --git a/scripts/install_mysql57.sh b/scripts/install_mysql57.sh deleted file mode 100755 index 18e23aa4..00000000 --- a/scripts/install_mysql57.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env bash - -set -x - -# Remove old mysql version -/etc/init.d/mysql stop || true -apt-get remove mysql-common mysql-server-5.5 mysql-server-core-5.5 mysql-client-5.5 mysql-client-core-5.5 -apt-get autoremove - -# Config -sed -i'' 's/table_cache/table_open_cache/' /etc/mysql/my.cnf -sed -i'' 's/log_slow_queries/slow_query_log/' /etc/mysql/my.cnf - -# Install new mysql version -echo deb [trusted=yes] http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7 | tee /etc/apt/sources.list.d/mysql.list -apt-get update -env DEBIAN_FRONTEND=noninteractive apt-get install -o Dpkg::Options::='--force-confold' -q -y mysql-server mysql-client - -# Cleanup old mysql datas -rm -rf /var/ramfs/mysql/ -rm -rf /var/ramfs/mysql-ctl/ -mkdir /var/ramfs/mysql/ -mkdir /var/ramfs/mysql-ctl/ -chown -R mysql /var/ramfs/mysql/ -chown -R mysql /var/ramfs/mysql-ctl/ - -# Config -echo '[mysqld]' | tee /etc/mysql/conf.d/replication.cnf -echo 'log-bin=mysql-bin' | tee -a /etc/mysql/conf.d/replication.cnf -echo 'server-id=1' | tee -a /etc/mysql/conf.d/replication.cnf -echo 'binlog-format = row' | tee -a /etc/mysql/conf.d/replication.cnf - -/etc/init.d/mysql stop || true - -# Install new datas -mysql_install_db --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/ramfs/mysql-ctl --user=mysql --insecure --verbose -mysql_install_db --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/ramfs/mysql --insecure --user=mysql --verbose - -# Enable GTID -echo '[mysqld]' | tee /etc/mysql/conf.d/gtid.cnf -echo 'gtid_mode=ON' | tee -a /etc/mysql/conf.d/gtid.cnf -echo 'enforce_gtid_consistency' | tee -a /etc/mysql/conf.d/gtid.cnf -echo 'binlog_format=ROW' | tee -a /etc/mysql/conf.d/gtid.cnf -echo 'log_slave_updates' | tee -a /etc/mysql/conf.d/gtid.cnf - -# Start mysql (avoid errors to have logs) -/etc/init.d/mysql start || true -mysql_upgrade -/etc/init.d/mysql restart || true -tail -1000 /var/log/syslog -nohup mysqld_safe --log-bin=mysql-ctl-bin.log --server-id 2 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave-updates -P 3307 --socket=/var/run/mysqld/mysqld-ctl.sock --datadir=/var/ramfs/mysql-ctl --pid-file=/var/lib/mysql/mysql-ctl.pid & -#Give it time to start -sleep 5 -tail -1000 nohup.out - -mysql --version -mysql -e 'SELECT VERSION();' -mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1'; FLUSH PRIVILEGES;" -mysql -u root --port=3307 --socket=/var/run/mysqld/mysqld-ctl.sock -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'; FLUSH PRIVILEGES;" - -mysql -e 'CREATE DATABASE pymysqlreplication_test;' -mysql -u root --port=3307 --socket=/var/run/mysqld/mysqld-ctl.sock -e "CREATE DATABASE pymysqlreplication_test;"