From 8222110436e0c9e4d1abe48b2058cb77fb995348 Mon Sep 17 00:00:00 2001 From: BR Date: Thu, 15 Oct 2015 14:15:18 +0200 Subject: [PATCH 1/8] New: Added custom testing function "mysql_docker_test_release" to test.sh --- test.sh | 101 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 47 deletions(-) diff --git a/test.sh b/test.sh index b7fdfe5..3c0f9a5 100755 --- a/test.sh +++ b/test.sh @@ -1,51 +1,58 @@ #!/bin/bash +# jue oct 15 13:18:38 CEST 2015 +# borja@libcrack.so set -e -echo "=> Building mysql 5.5 image" -docker build -t mysql-5.5 5.5/ - -echo "=> Testing if mysql is running on 5.5" -docker run -d -p 13306:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" mysql-5.5; sleep 10 -mysqladmin -uuser -ptest -h127.0.0.1 -P13306 ping | grep -c "mysqld is alive" - -echo "=> Testing replication on mysql 5.5" -docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_MASTER=true -e REPLICATION_USER=repl -e REPLICATION_PASS=repl -p 13307:3306 --name mysql55master mysql-5.5; sleep 10 -docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_SLAVE=true -p 13308:3306 --link mysql55master:mysql mysql-5.5; sleep 10 -docker logs mysql55master | grep "repl:repl" -mysql -uuser -ptest -h127.0.0.1 -P13307 -e "show master status\G;" | grep "mysql-bin.*" -mysql -uuser -ptest -h127.0.0.1 -P13308 -e "show slave status\G;" | grep "Slave_IO_Running.*Yes" -mysql -uuser -ptest -h127.0.0.1 -P13308 -e "show slave status\G;" | grep "Slave_SQL_Running.*Yes" - -echo "=> Testing volume on mysql 5.5" -mkdir vol55 -docker run --name mysql55.1 -d -p 13309:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" -v $(pwd)/vol55:/var/lib/mysql mysql-5.5; sleep 10 -mysqladmin -uuser -ptest -h127.0.0.1 -P13309 ping | grep -c "mysqld is alive" -docker stop mysql55.1 -docker run -d -p 13310:3306 -v $(pwd)/vol55:/var/lib/mysql mysql-5.5; sleep 10 -mysqladmin -uuser -ptest -h127.0.0.1 -P13310 ping | grep -c "mysqld is alive" - -echo "=> Building mysql 5.6 image" -docker build -t mysql-5.6 5.6/ - -echo "=> Testing if mysql is running on 5.6" -docker run -d -p 23306:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" mysql-5.6; sleep 10 -mysqladmin -uuser -ptest -h127.0.0.1 -P13307 ping | grep -c "mysqld is alive" - -echo "=> Testing replication on mysql 5.6" -docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_MASTER=true -e REPLICATION_USER=repl -e REPLICATION_PASS=repl -p 23307:3306 --name mysql56master mysql-5.6; sleep 10 -docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_SLAVE=true -p 23308:3306 --link mysql56master:mysql mysql-5.6; sleep 10 -docker logs mysql56master | grep "repl:repl" -mysql -uuser -ptest -h127.0.0.1 -P23307 -e "show master status\G;" | grep "mysql-bin.*" -mysql -uuser -ptest -h127.0.0.1 -P23308 -e "show slave status\G;" | grep "Slave_IO_Running.*Yes" -mysql -uuser -ptest -h127.0.0.1 -P23308 -e "show slave status\G;" | grep "Slave_SQL_Running.*Yes" - -echo "=> Testing volume on mysql 5.6" -mkdir vol56 -docker run --name mysql56.1 -d -p 23309:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" -v $(pwd)/vol56:/var/lib/mysql mysql-5.6; sleep 10 -mysqladmin -uuser -ptest -h127.0.0.1 -P23309 ping | grep -c "mysqld is alive" -docker stop mysql56.1 -docker run -d -p 23310:3306 -v $(pwd)/vol56:/var/lib/mysql mysql-5.6; sleep 10 -mysqladmin -uuser -ptest -h127.0.0.1 -P23310 ping | grep -c "mysqld is alive" - -echo "=>Done" +mysql_docker_test_release() +{ + local major="5" + local minor="7" + + [[ -z "$major" ]] || major="$1" + [[ -z "$minor" ]] || major="$2" + + local release="${major}.${minor}" + + local lport="$(($RANDOM+1024))" + local lport_master="$(($lport+1))" + local lport_slave="$(($lport+2))" + local lport_vol="$(($lport+3))" + local lport_vol2="$(($lport+4))" + + echo -e "\e[1m=> Building mysql ${release} image\e[0m" + docker build -t mysql-${release} ${release}/ + + echo -e "\e[1m=> Testing if mysql is running on ${release}" + docker run -d -p ${lport}:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" mysql-${release} + sleep 10 + mysqladmin -uuser -ptest -h127.0.0.1 -P${lport} ping | grep -c "mysqld is alive" + + echo -e "\e[1m=> Testing replication on mysql ${release}\e[0m" + docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_MASTER=true \ + -e REPLICATION_USER=repl -e REPLICATION_PASS=repl -p ${lport_master}:3306 \ + --name mysql${release//.}master mysql-${release}; sleep 10 + docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_SLAVE=true \ + -p ${lport_slave}:3306 --link mysql${release//.}master:mysql mysql-${release} + sleep 10 + docker logs mysql${release//.}master | grep "repl:repl" + mysql -uuser -ptest -h127.0.0.1 -P${lport_master} -e "show master status\G;" | grep "mysql-bin.*" + mysql -uuser -ptest -h127.0.0.1 -P${lport_slave} -e "show slave status\G;" | grep "Slave_IO_Running.*Yes" + mysql -uuser -ptest -h127.0.0.1 -P${lport_slave} -e "show slave status\G;" | grep "Slave_SQL_Running.*Yes" + + echo -e "\e[1m=> Testing volume on mysql ${release}\e[0m" + mkdir vol${release//.} + docker run --name mysql${release//.}.1 -d -p ${lport_vol}:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" \ + -v $(pwd)/vol${release//.}:/var/lib/mysql mysql-${release} + sleep 10 + mysqladmin -uuser -ptest -h127.0.0.1 -P${lport_vol} ping | grep -c "mysqld is alive" + docker stop mysql${release//.}.1 + docker run -d -p ${lport_vol2}:3306 -v $(pwd)/vol${release//.}:/var/lib/mysql mysql-${release}; sleep 10 + mysqladmin -uuser -ptest -h127.0.0.1 -P${lport_vol2} ping | grep -c "mysqld is alive" +} + +mysql_docker_test_release 5 5 +mysql_docker_test_release 5 6 +mysql_docker_test_release 5 7 + +echo -e "\e[1m DONE \e[0m" From bfc17c6ab7dcbbde061b6af960eb153f071b1a56 Mon Sep 17 00:00:00 2001 From: BR Date: Thu, 15 Oct 2015 14:45:29 +0200 Subject: [PATCH 2/8] New: Added MySQL 5.7 from MySQL repos --- 5.7/Dockerfile | 41 +++++++++ 5.7/docker-compose.yml | 4 + 5.7/import_sql.sh | 28 ++++++ 5.7/my.cnf | 6 ++ 5.7/mysqld_charset.cnf | 7 ++ 5.7/run.sh | 190 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 276 insertions(+) create mode 100644 5.7/Dockerfile create mode 100644 5.7/docker-compose.yml create mode 100755 5.7/import_sql.sh create mode 100644 5.7/my.cnf create mode 100644 5.7/mysqld_charset.cnf create mode 100755 5.7/run.sh diff --git a/5.7/Dockerfile b/5.7/Dockerfile new file mode 100644 index 0000000..267c99c --- /dev/null +++ b/5.7/Dockerfile @@ -0,0 +1,41 @@ +FROM ubuntu:trusty +MAINTAINER Borja + +ENV DEBIAN_FRONTEND=noninteractive + +# Add MySQL configuration +ADD my.cnf /etc/mysql/conf.d/my.cnf +ADD mysqld_charset.cnf /etc/mysql/conf.d/mysqld_charset.cnf + +# Add MySQL APT repos +RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections +RUN apt-key adv --keyserver keys.gnupg.net --recv-keys 8C718D3B5072E1F5 +RUN echo "deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7-dmr" \ + > /etc/apt/sources.list.d/mysql.list + +# Install MySQL +RUN apt-get update && \ + apt-get -yq install mysql-server-5.7 pwgen && \ + rm -rf /var/lib/apt/lists/* && \ + if [ ! -f /usr/share/mysql/my-default.cnf ] ; then cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf; fi && \ + rm -rf /var/lib/mysql/* && \ + mysqld --initialize > /dev/null 2>&1 && \ + touch /var/lib/mysql/.EMPTY_DB + +# Add MySQL scripts +ADD import_sql.sh /import_sql.sh +ADD run.sh /run.sh + +ENV MYSQL_USER=admin \ + MYSQL_PASS=**Random** \ + ON_CREATE_DB=**False** \ + REPLICATION_MASTER=**False** \ + REPLICATION_SLAVE=**False** \ + REPLICATION_USER=replica \ + REPLICATION_PASS=replica + +# Add VOLUMEs to allow backup of config and databases +VOLUME ["/etc/mysql", "/var/lib/mysql"] + +EXPOSE 3306 +CMD ["/run.sh"] diff --git a/5.7/docker-compose.yml b/5.7/docker-compose.yml new file mode 100644 index 0000000..e858c43 --- /dev/null +++ b/5.7/docker-compose.yml @@ -0,0 +1,4 @@ +db: + image: tutum/mysql:5.7 + environment: + MYSQL_PASS: "**ChangeMe**" diff --git a/5.7/import_sql.sh b/5.7/import_sql.sh new file mode 100755 index 0000000..995e6c9 --- /dev/null +++ b/5.7/import_sql.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +if [[ $# -ne 3 ]]; then + echo "Usage: $0 " + exit 1 +fi + +echo "=> Starting MySQL Server" +/usr/bin/mysqld_safe > /dev/null 2>&1 & +PID=$! + +RET=1 +while [[ RET -ne 0 ]]; do + echo "=> Waiting for confirmation of MySQL service startup" + sleep 5 + mysql -u"$1" -p"$2" -e "status" > /dev/null 2>&1 +RET=$? +done + +echo " Started with PID ${PID}" + +echo "=> Importing SQL file" +mysql -u"$1" -p"$2" < "$3" + +echo "=> Stopping MySQL Server" +mysqladmin -u"$1" -p"$2" shutdown + +echo "=> Done!" diff --git a/5.7/my.cnf b/5.7/my.cnf new file mode 100644 index 0000000..02fe8be --- /dev/null +++ b/5.7/my.cnf @@ -0,0 +1,6 @@ +[mysqld] +bind-address=0.0.0.0 +# http://www.percona.com/blog/2008/05/31/dns-achilles-heel-mysql-installation/ +skip_name_resolve +#server-id +#log-bin diff --git a/5.7/mysqld_charset.cnf b/5.7/mysqld_charset.cnf new file mode 100644 index 0000000..de32582 --- /dev/null +++ b/5.7/mysqld_charset.cnf @@ -0,0 +1,7 @@ +[mysqld] +character_set_server=utf8 +character_set_filesystem=utf8 +collation-server=utf8_general_ci +init-connect='SET NAMES utf8' +init_connect='SET collation_connection = utf8_general_ci' +skip-character-set-client-handshake diff --git a/5.7/run.sh b/5.7/run.sh new file mode 100755 index 0000000..8e758ce --- /dev/null +++ b/5.7/run.sh @@ -0,0 +1,190 @@ +#!/bin/bash + +set -m +set -e + +VOLUME_HOME="/var/lib/mysql" +CONF_FILE="/etc/mysql/conf.d/my.cnf" +LOG="/var/log/mysql/error.log" + +# Set permission of config file +chmod 644 ${CONF_FILE} +chmod 644 /etc/mysql/conf.d/mysqld_charset.cnf + +StartMySQL () +{ + /usr/bin/mysqld_safe ${EXTRA_OPTS} > /dev/null 2>&1 & + # Time out in 1 minute + LOOP_LIMIT=60 + for (( i=0 ; ; i++ )); do + if [ ${i} -eq ${LOOP_LIMIT} ]; then + echo "Time out. Error log is shown as below:" + tail -n 100 ${LOG} + exit 1 + fi + echo "=> Waiting for confirmation of MySQL service startup, trying ${i}/${LOOP_LIMIT} ..." + sleep 1 + mysql -uroot -e "status" > /dev/null 2>&1 && break + done +} + +CreateMySQLUser() +{ + if [ "$MYSQL_PASS" = "**Random**" ]; then + unset MYSQL_PASS + fi + + PASS=${MYSQL_PASS:-$(pwgen -s 12 1)} + _word=$( [ ${MYSQL_PASS} ] && echo "preset" || echo "random" ) + echo "=> Creating MySQL user ${MYSQL_USER} with ${_word} password" + + mysql -uroot -e "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '$PASS'" + mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_USER}'@'%' WITH GRANT OPTION" + echo "=> Done!" + echo "========================================================================" + echo "You can now connect to this MySQL Server using:" + echo "" + echo " mysql -u$MYSQL_USER -p$PASS -h -P" + echo "" + echo "Please remember to change the above password as soon as possible!" + echo "MySQL user 'root' has no password but only allows local connections" + echo "========================================================================" +} + +OnCreateDB() +{ + if [ "$ON_CREATE_DB" = "**False**" ]; then + unset ON_CREATE_DB + else + echo "Creating MySQL database ${ON_CREATE_DB}" + mysql -uroot -e "CREATE DATABASE IF NOT EXISTS ${ON_CREATE_DB};" + echo "Database created!" + fi +} + +ImportSql() +{ + for FILE in ${STARTUP_SQL}; do + echo "=> Importing SQL file ${FILE}" + if [ "$ON_CREATE_DB" ]; then + mysql -uroot "$ON_CREATE_DB" < "${FILE}" + else + mysql -uroot < "${FILE}" + fi + done +} + +# Main +if [ ${REPLICATION_MASTER} == "**False**" ]; then + unset REPLICATION_MASTER +fi + +if [ ${REPLICATION_SLAVE} == "**False**" ]; then + unset REPLICATION_SLAVE +fi + +# Initialize empty data volume and create MySQL user +if [[ ! -d $VOLUME_HOME/mysql ]]; then + echo "=> An empty or uninitialized MySQL volume is detected in $VOLUME_HOME" + echo "=> Installing MySQL ..." + if [ ! -f /usr/share/mysql/my-default.cnf ] ; then + cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf + fi + mysql_install_db || exit 1 + touch /var/lib/mysql/.EMPTY_DB + echo "=> Done!" +else + echo "=> Using an existing volume of MySQL" +fi + +# Set MySQL REPLICATION - MASTER +if [ -n "${REPLICATION_MASTER}" ]; then + echo "=> Configuring MySQL replication as master (1/2) ..." + if [ ! -f /replication_set.1 ]; then + RAND="$(date +%s | rev | cut -c 1-2)$(echo ${RANDOM})" + echo "=> Writting configuration file '${CONF_FILE}' with server-id=${RAND}" + sed -i "s/^#server-id.*/server-id = ${RAND}/" ${CONF_FILE} + sed -i "s/^#log-bin.*/log-bin = mysql-bin/" ${CONF_FILE} + touch /replication_set.1 + else + echo "=> MySQL replication master already configured, skip" + fi +fi + +# Set MySQL REPLICATION - SLAVE +if [ -n "${REPLICATION_SLAVE}" ]; then + echo "=> Configuring MySQL replication as slave (1/2) ..." + if [ -n "${MYSQL_PORT_3306_TCP_ADDR}" ] && [ -n "${MYSQL_PORT_3306_TCP_PORT}" ]; then + if [ ! -f /replication_set.1 ]; then + RAND="$(date +%s | rev | cut -c 1-2)$(echo ${RANDOM})" + echo "=> Writting configuration file '${CONF_FILE}' with server-id=${RAND}" + sed -i "s/^#server-id.*/server-id = ${RAND}/" ${CONF_FILE} + sed -i "s/^#log-bin.*/log-bin = mysql-bin/" ${CONF_FILE} + touch /replication_set.1 + else + echo "=> MySQL replication slave already configured, skip" + fi + else + echo "=> Cannot configure slave, please link it to another MySQL container with alias as 'mysql'" + exit 1 + fi +fi + + +echo "=> Starting MySQL ..." +StartMySQL +tail -F $LOG & + +# Create admin user and pre create database +if [ -f /var/lib/mysql/.EMPTY_DB ]; then + echo "=> Creating admin user ..." + CreateMySQLUser + OnCreateDB + rm /var/lib/mysql/.EMPTY_DB +fi + + +# Import Startup SQL +if [ -n "${STARTUP_SQL}" ]; then + if [ ! -f /sql_imported ]; then + echo "=> Initializing DB with ${STARTUP_SQL}" + ImportSql + touch /sql_imported + fi +fi + +# Set MySQL REPLICATION - MASTER +if [ -n "${REPLICATION_MASTER}" ]; then + echo "=> Configuring MySQL replication as master (2/2) ..." + if [ ! -f /replication_set.2 ]; then + echo "=> Creating a log user ${REPLICATION_USER}:${REPLICATION_PASS}" + mysql -uroot -e "CREATE USER '${REPLICATION_USER}'@'%' IDENTIFIED BY '${REPLICATION_PASS}'" + mysql -uroot -e "GRANT REPLICATION SLAVE ON *.* TO '${REPLICATION_USER}'@'%'" + mysql -uroot -e "reset master" + echo "=> Done!" + touch /replication_set.2 + else + echo "=> MySQL replication master already configured, skip" + fi +fi + +# Set MySQL REPLICATION - SLAVE +if [ -n "${REPLICATION_SLAVE}" ]; then + echo "=> Configuring MySQL replication as slave (2/2) ..." + if [ -n "${MYSQL_PORT_3306_TCP_ADDR}" ] && [ -n "${MYSQL_PORT_3306_TCP_PORT}" ]; then + if [ ! -f /replication_set.2 ]; then + echo "=> Setting master connection info on slave" + mysql -uroot -e "CHANGE MASTER TO MASTER_HOST='${MYSQL_PORT_3306_TCP_ADDR}',MASTER_USER='${MYSQL_ENV_REPLICATION_USER}',MASTER_PASSWORD='${MYSQL_ENV_REPLICATION_PASS}',MASTER_PORT=${MYSQL_PORT_3306_TCP_PORT}, MASTER_CONNECT_RETRY=30" + mysql -uroot -e "start slave" + echo "=> Done!" + touch /replication_set.2 + else + echo "=> MySQL replication slave already configured, skip" + fi + else + echo "=> Cannot configure slave, please link it to another MySQL container with alias as 'mysql'" + exit 1 + fi +fi + +fg From 2d6e7091fc5bded95a750e3d6ba6ab97b39c30f2 Mon Sep 17 00:00:00 2001 From: BR Date: Fri, 16 Oct 2015 14:50:16 +0200 Subject: [PATCH 3/8] Fix: Incorrect "minor" variable assigment from function arguments --- test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 3c0f9a5..c82517e 100755 --- a/test.sh +++ b/test.sh @@ -10,7 +10,7 @@ mysql_docker_test_release() local minor="7" [[ -z "$major" ]] || major="$1" - [[ -z "$minor" ]] || major="$2" + [[ -z "$minor" ]] || minor="$2" local release="${major}.${minor}" From e0bc9f2b572c212646cbb6ad2c567496f8d50d27 Mon Sep 17 00:00:00 2001 From: BR Date: Fri, 16 Oct 2015 15:14:14 +0200 Subject: [PATCH 4/8] Mod: Minor code style improvements (store user & passwd in variables,etc) --- test.sh | 69 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/test.sh b/test.sh index c82517e..5ae1de6 100755 --- a/test.sh +++ b/test.sh @@ -12,7 +12,7 @@ mysql_docker_test_release() [[ -z "$major" ]] || major="$1" [[ -z "$minor" ]] || minor="$2" - local release="${major}.${minor}" + local release="${major}"."${minor}" local lport="$(($RANDOM+1024))" local lport_master="$(($lport+1))" @@ -20,39 +20,66 @@ mysql_docker_test_release() local lport_vol="$(($lport+3))" local lport_vol2="$(($lport+4))" + local user="user" + local passwd="test" + local host="127.0.0.1" + + local repl_user="repl" + local repl_passwd="repl" + local rep_host="127.0.0.1" + echo -e "\e[1m=> Building mysql ${release} image\e[0m" - docker build -t mysql-${release} ${release}/ + + docker build -t "mysql-${release}" "${release}/" echo -e "\e[1m=> Testing if mysql is running on ${release}" - docker run -d -p ${lport}:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" mysql-${release} + + docker run -d -p "${lport}":3306 -e MYSQL_USER="${user}" -e MYSQL_PASS="${passwd}" \ + mysql-"${release}" sleep 10 - mysqladmin -uuser -ptest -h127.0.0.1 -P${lport} ping | grep -c "mysqld is alive" + + mysqladmin -u"${user}" -p"${passwd}" -h"${host}" -P"${lport}" ping | grep -c "mysqld is alive" echo -e "\e[1m=> Testing replication on mysql ${release}\e[0m" - docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_MASTER=true \ - -e REPLICATION_USER=repl -e REPLICATION_PASS=repl -p ${lport_master}:3306 \ - --name mysql${release//.}master mysql-${release}; sleep 10 - docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_SLAVE=true \ - -p ${lport_slave}:3306 --link mysql${release//.}master:mysql mysql-${release} + + docker run -d -e MYSQL_USER="${user}" -e MYSQL_PASS="${passwd}" -e REPLICATION_MASTER=true \ + -e REPLICATION_USER="${repl_user}" -e REPLICATION_PASS="${repl_passwd}" -p "${lport_master}":3306 \ + --name mysql"${release//.}"master mysql-"${release}" + sleep 10 + + docker run -d -e MYSQL_USER="${user}" -e MYSQL_PASS="${passwd}" -e REPLICATION_SLAVE=true \ + -p "${lport_slave}":3306 --link mysql"${release//.}"master:mysql mysql-"${release}" sleep 10 - docker logs mysql${release//.}master | grep "repl:repl" - mysql -uuser -ptest -h127.0.0.1 -P${lport_master} -e "show master status\G;" | grep "mysql-bin.*" - mysql -uuser -ptest -h127.0.0.1 -P${lport_slave} -e "show slave status\G;" | grep "Slave_IO_Running.*Yes" - mysql -uuser -ptest -h127.0.0.1 -P${lport_slave} -e "show slave status\G;" | grep "Slave_SQL_Running.*Yes" + + docker logs mysql"${release//.}"master | grep "repl:repl" + mysql -u"${user}" -p"${passwd}" -h"${host}" -P"${lport_master}" -e "show master status\G;" \ + | grep "mysql-bin.*" + mysql -u"${user}" -p"${passwd}" -h"${host}" -P"${lport_slave}" -e "show slave status\G;" \ + | grep "Slave_IO_Running.*Yes" + mysql -u"${user}" -p"${passwd}" -h"${host}" -P"${lport_slave}" -e "show slave status\G;" \ + | grep "Slave_SQL_Running.*Yes" echo -e "\e[1m=> Testing volume on mysql ${release}\e[0m" - mkdir vol${release//.} - docker run --name mysql${release//.}.1 -d -p ${lport_vol}:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" \ - -v $(pwd)/vol${release//.}:/var/lib/mysql mysql-${release} + + mkdir vol"${release//.}" + docker run --name mysql"${release//.}".1 -d -p "${lport_vol}:3306" -e MYSQL_USER="${user}" \ + -e MYSQL_PASS="${passwd}" -v "$(pwd)/vol${release//.}":/var/lib/mysql mysql-"${release}" + sleep 10 + + mysqladmin -u"${user}" -p"${passwd}" -h"${host}" -P"${lport_vol}" ping | grep -c "mysqld is alive" + docker stop mysql"${release//.}".1 + docker run -d -p "${lport_vol2}":3306 -v "$(pwd)/vol${release//.}":/var/lib/mysql mysql-"${release}" sleep 10 - mysqladmin -uuser -ptest -h127.0.0.1 -P${lport_vol} ping | grep -c "mysqld is alive" - docker stop mysql${release//.}.1 - docker run -d -p ${lport_vol2}:3306 -v $(pwd)/vol${release//.}:/var/lib/mysql mysql-${release}; sleep 10 - mysqladmin -uuser -ptest -h127.0.0.1 -P${lport_vol2} ping | grep -c "mysqld is alive" + + mysqladmin -u"${user}" -p"${passwd}" -h"${host}" -P"${lport_vol2}" ping | grep -c "mysqld is alive" } +echo -e "\e[1m Starting tests at $(date "+%d/%m/%Y %H:%M:%S") \e[0m" + mysql_docker_test_release 5 5 mysql_docker_test_release 5 6 mysql_docker_test_release 5 7 -echo -e "\e[1m DONE \e[0m" +echo -e "\e[1m Finished tests at $(date "+%d/%m/%Y %H:%M:%S") \e[0m" + +# vim:set ts=2 sw=2 et: From f9edd6ac0bc1da3e03ff7259048242fe7691cc07 Mon Sep 17 00:00:00 2001 From: BR Date: Fri, 16 Oct 2015 16:00:44 +0200 Subject: [PATCH 5/8] Fix: Fixed function arguments (major,minor) assigment in test.sh --- test.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test.sh b/test.sh index 5ae1de6..82f9cf2 100755 --- a/test.sh +++ b/test.sh @@ -9,8 +9,8 @@ mysql_docker_test_release() local major="5" local minor="7" - [[ -z "$major" ]] || major="$1" - [[ -z "$minor" ]] || minor="$2" + [[ -z "$1" ]] || major="$1" + [[ -z "$2" ]] || minor="$2" local release="${major}"."${minor}" @@ -23,16 +23,14 @@ mysql_docker_test_release() local user="user" local passwd="test" local host="127.0.0.1" - local repl_user="repl" local repl_passwd="repl" - local rep_host="127.0.0.1" echo -e "\e[1m=> Building mysql ${release} image\e[0m" docker build -t "mysql-${release}" "${release}/" - echo -e "\e[1m=> Testing if mysql is running on ${release}" + echo -e "\e[1m=> Testing if mysql ${release} is running on ${host}" docker run -d -p "${lport}":3306 -e MYSQL_USER="${user}" -e MYSQL_PASS="${passwd}" \ mysql-"${release}" @@ -52,6 +50,7 @@ mysql_docker_test_release() sleep 10 docker logs mysql"${release//.}"master | grep "repl:repl" + mysql -u"${user}" -p"${passwd}" -h"${host}" -P"${lport_master}" -e "show master status\G;" \ | grep "mysql-bin.*" mysql -u"${user}" -p"${passwd}" -h"${host}" -P"${lport_slave}" -e "show slave status\G;" \ From 40240aea5029c793664cd2cfe30e1d1bca3bdece Mon Sep 17 00:00:00 2001 From: BR Date: Fri, 16 Oct 2015 16:50:50 +0200 Subject: [PATCH 6/8] Mod: Added logging type detection (json/syslog) to test.sh when testing mysql replication --- test.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 82f9cf2..4862e31 100755 --- a/test.sh +++ b/test.sh @@ -49,7 +49,9 @@ mysql_docker_test_release() -p "${lport_slave}":3306 --link mysql"${release//.}"master:mysql mysql-"${release}" sleep 10 - docker logs mysql"${release//.}"master | grep "repl:repl" + docker info | grep -q "Logging Driver: syslog" \ + && ( docker logs mysql"${release//.}"master | grep "${repl_user}":"${repl_passwd}" ) \ + || grep "${repl_user}":"${repl_passwd}" /var/log/syslog mysql -u"${user}" -p"${passwd}" -h"${host}" -P"${lport_master}" -e "show master status\G;" \ | grep "mysql-bin.*" From 849be282b74d2aa9bdfd1e3f7cc2be39dce6c6e4 Mon Sep 17 00:00:00 2001 From: BR Date: Fri, 16 Oct 2015 20:41:38 +0200 Subject: [PATCH 7/8] Mod: Added params "--initialize-insecure=on" "--user=mysql" and "--datadir=/var/lib/mysql" to mysqld initialization --- 5.7/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/5.7/Dockerfile b/5.7/Dockerfile index 267c99c..ec5fba1 100644 --- a/5.7/Dockerfile +++ b/5.7/Dockerfile @@ -19,7 +19,7 @@ RUN apt-get update && \ rm -rf /var/lib/apt/lists/* && \ if [ ! -f /usr/share/mysql/my-default.cnf ] ; then cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf; fi && \ rm -rf /var/lib/mysql/* && \ - mysqld --initialize > /dev/null 2>&1 && \ + mysqld --initialize-insecure=on --user=mysql --datadir=/var/lib/mysql > /dev/null 2>&1 && \ touch /var/lib/mysql/.EMPTY_DB # Add MySQL scripts From a316d4b5f010dfd7cecd0222d0a1314901aabfc7 Mon Sep 17 00:00:00 2001 From: BR Date: Fri, 16 Oct 2015 20:43:42 +0200 Subject: [PATCH 8/8] Mod: Added detection of docker logging method (json/syslog) after creating the replication user --- test.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 4862e31..1bc5e08 100755 --- a/test.sh +++ b/test.sh @@ -51,7 +51,11 @@ mysql_docker_test_release() docker info | grep -q "Logging Driver: syslog" \ && ( docker logs mysql"${release//.}"master | grep "${repl_user}":"${repl_passwd}" ) \ - || grep "${repl_user}":"${repl_passwd}" /var/log/syslog + || { + [[ -r /var/log/syslog ]] \ + && grep "${repl_user}":"${repl_passwd}" /var/log/syslog \ + || echo -e "\e]31m ERROR:\e]0mCannot verify replication user creation" + } mysql -u"${user}" -p"${passwd}" -h"${host}" -P"${lport_master}" -e "show master status\G;" \ | grep "mysql-bin.*"