From fca39ee3c03c8c716b9d0b4922aaceccbd22e74a Mon Sep 17 00:00:00 2001 From: jiahao Date: Fri, 23 Oct 2020 18:49:26 +0800 Subject: [PATCH 1/5] tests: the initial database scripts support configuration via variable. --- .travis/initializedb.sh | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/.travis/initializedb.sh b/.travis/initializedb.sh index 594fde1..ef64acd 100755 --- a/.travis/initializedb.sh +++ b/.travis/initializedb.sh @@ -2,7 +2,7 @@ set -ex -if [ $DB_VERSION == 'mysql:8.0' -o $DB_VERSION == 'mariadb:10.3' ]; then +if [ "$DB_VERSION" == 'mysql:8.0' -o "$DB_VERSION" == 'mariadb:10.3' ]; then sudo cp t/data/test-sha256.crt t/data/test.crt sudo cp t/data/test-sha256.key t/data/test.key else @@ -19,13 +19,13 @@ ssl-key=/etc/mysql/ssl/test.key socket=/var/run/mysqld/mysqld.sock EOF -if [ $DB_VERSION != 'mysql:8.0' -a $DB_VERSION != 'mysql:5.7' ]; then +if [ "$DB_VERSION" != 'mysql:8.0' -a "$DB_VERSION" != 'mysql:5.7' ]; then cat << EOF >>mysqld.cnf secure-auth=0 EOF fi -if [ $DB_VERSION == 'mysql:5.6' ]; then +if [ "$DB_VERSION" == 'mysql:5.6' ]; then cat << EOF >>mysqld.cnf sha256_password_private_key_path=/etc/mysql/ssl/test.key sha256_password_public_key_path=/etc/mysql/ssl/test.pub @@ -39,17 +39,24 @@ socket=/var/run/mysqld/mysqld.sock EOF path=`pwd` +container_name=mysqld sudo chmod -R 777 /var/run/mysqld sudo docker pull ${DB_VERSION} +if [ $(sudo docker ps -a --filter "name=^/$container_name$" --format '{{.Names}}') == "$container_name" ]; then + sudo docker stop $container_name + sudo docker rm $container_name +fi + sudo docker run \ -itd \ --privileged \ - --name=mysqld \ + --name=$container_name \ --pid=host \ --net=host \ --ipc=host \ -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \ + -e MYSQL_TCP_PORT="${TEST_NGINX_MYSQL_PORT:-3306}" \ --volume=/var/run/mysqld:/var/run/mysqld \ --volume=$path/mysqld.cnf:/etc/mysql/conf.d/mysqld.cnf \ --volume=$path/t/data/test.crt:/etc/mysql/ssl/test.crt \ @@ -58,31 +65,31 @@ sudo docker run \ ${DB_VERSION} mysql() { - docker exec mysqld mysql "${@}" + sudo docker exec mysqld mysql "${@}" } -while : +for i in {1..100} : do sleep 3 mysql --protocol=tcp -e 'select version()' && break done -docker logs mysqld +sudo docker logs mysqld if [ ! -d download-cache ]; then mkdir download-cache; fi if [ ! -f download-cache/world.sql.gz ]; then wget -O download-cache/world.sql.gz http://downloads.mysql.com/docs/world.sql.gz; fi -docker cp download-cache/world.sql.gz mysqld:/tmp/world.sql.gz -docker exec mysqld /bin/sh -c "zcat /tmp/world.sql.gz | mysql -uroot" +sudo docker cp download-cache/world.sql.gz mysqld:/tmp/world.sql.gz +sudo docker exec mysqld /bin/sh -c "zcat /tmp/world.sql.gz | mysql -uroot" mysql -uroot -e 'create database ngx_test;' mysql -uroot -e 'create user "ngx_test"@"%" identified by "ngx_test";' mysql -uroot -e 'grant all on ngx_test.* to "ngx_test"@"%";' -if [ $DB_VERSION == 'mysql:8.0' -o $DB_VERSION == 'mysql:5.7' ]; then # sha256_password, mysql_native_password +if [ "$DB_VERSION" == 'mysql:8.0' -o "$DB_VERSION" == 'mysql:5.7' ]; then # sha256_password, mysql_native_password mysql -uroot -e 'create user "user_sha256"@"%" identified with "sha256_password" by "pass_sha256";' mysql -uroot -e 'grant all on ngx_test.* to "user_sha256"@"%";' mysql -uroot -e 'create user "nopass_sha256"@"%" identified with "sha256_password";' mysql -uroot -e 'grant all on ngx_test.* to "nopass_sha256"@"%";' - if [ $DB_VERSION != 'mysql:5.7' ]; then # mysql:8.0 caching_sha2_password + if [ "$DB_VERSION" != 'mysql:5.7' ]; then # mysql:8.0 caching_sha2_password mysql -uroot -e 'create user "user_caching_sha2"@"%" identified with "caching_sha2_password" by "pass_caching_sha2";' mysql -uroot -e 'grant all on ngx_test.* to "user_caching_sha2"@"%";' mysql -uroot -e 'create user "nopass_caching_sha2"@"%" identified with "caching_sha2_password";' @@ -91,7 +98,7 @@ if [ $DB_VERSION == 'mysql:8.0' -o $DB_VERSION == 'mysql:5.7' ]; then # sha256_p mysql -uroot -e 'create user "user_native"@"%" identified with "mysql_native_password" by "pass_native";' else # other: mysql_native_password, mysql_old_password - if [ $DB_VERSION == 'mysql:5.6' ]; then # mysql:5.6 sha256_password + if [ "$DB_VERSION" == 'mysql:5.6' ]; then # mysql:5.6 sha256_password mysql -uroot -e 'create user "user_sha256"@"%" identified with "sha256_password";' mysql -uroot -e 'set old_passwords = 2;set password for "user_sha256"@"%" = PASSWORD("pass_sha256");' mysql -uroot -e 'grant all on ngx_test.* to "user_sha256"@"%";' From 88e69be6f4c3b58f38aed3ad87c6707f76f46243 Mon Sep 17 00:00:00 2001 From: jiahao Date: Fri, 23 Oct 2020 23:02:57 +0800 Subject: [PATCH 2/5] bugfix: minor tweaks. --- .travis/initializedb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/initializedb.sh b/.travis/initializedb.sh index ef64acd..cfd6a35 100755 --- a/.travis/initializedb.sh +++ b/.travis/initializedb.sh @@ -43,7 +43,7 @@ container_name=mysqld sudo chmod -R 777 /var/run/mysqld sudo docker pull ${DB_VERSION} -if [ $(sudo docker ps -a --filter "name=^/$container_name$" --format '{{.Names}}') == "$container_name" ]; then +if [ "$(sudo docker ps -a --filter "name=^/$container_name$" --format '{{.Names}}')" == "$container_name" ]; then sudo docker stop $container_name sudo docker rm $container_name fi From 4eddabb3dae37945dadf764d86b4f0d5ac82dd27 Mon Sep 17 00:00:00 2001 From: jiahao Date: Fri, 23 Oct 2020 23:02:57 +0800 Subject: [PATCH 3/5] bugfix: minor tweaks. --- .travis/initializedb.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.travis/initializedb.sh b/.travis/initializedb.sh index cfd6a35..c9f7dfd 100755 --- a/.travis/initializedb.sh +++ b/.travis/initializedb.sh @@ -2,7 +2,7 @@ set -ex -if [ "$DB_VERSION" == 'mysql:8.0' -o "$DB_VERSION" == 'mariadb:10.3' ]; then +if [ $DB_VERSION == 'mysql:8.0' -o $DB_VERSION == 'mariadb:10.3' ]; then sudo cp t/data/test-sha256.crt t/data/test.crt sudo cp t/data/test-sha256.key t/data/test.key else @@ -19,13 +19,13 @@ ssl-key=/etc/mysql/ssl/test.key socket=/var/run/mysqld/mysqld.sock EOF -if [ "$DB_VERSION" != 'mysql:8.0' -a "$DB_VERSION" != 'mysql:5.7' ]; then +if [ $DB_VERSION != 'mysql:8.0' -a $DB_VERSION != 'mysql:5.7' ]; then cat << EOF >>mysqld.cnf secure-auth=0 EOF fi -if [ "$DB_VERSION" == 'mysql:5.6' ]; then +if [ $DB_VERSION == 'mysql:5.6' ]; then cat << EOF >>mysqld.cnf sha256_password_private_key_path=/etc/mysql/ssl/test.key sha256_password_public_key_path=/etc/mysql/ssl/test.pub @@ -48,6 +48,8 @@ if [ "$(sudo docker ps -a --filter "name=^/$container_name$" --format '{{.Names} sudo docker rm $container_name fi +sudo chmod -R 777 /var/run/mysqld +sudo docker pull ${DB_VERSION} sudo docker run \ -itd \ --privileged \ @@ -83,13 +85,13 @@ mysql -uroot -e 'create database ngx_test;' mysql -uroot -e 'create user "ngx_test"@"%" identified by "ngx_test";' mysql -uroot -e 'grant all on ngx_test.* to "ngx_test"@"%";' -if [ "$DB_VERSION" == 'mysql:8.0' -o "$DB_VERSION" == 'mysql:5.7' ]; then # sha256_password, mysql_native_password +if [ $DB_VERSION == 'mysql:8.0' -o $DB_VERSION == 'mysql:5.7' ]; then # sha256_password, mysql_native_password mysql -uroot -e 'create user "user_sha256"@"%" identified with "sha256_password" by "pass_sha256";' mysql -uroot -e 'grant all on ngx_test.* to "user_sha256"@"%";' mysql -uroot -e 'create user "nopass_sha256"@"%" identified with "sha256_password";' mysql -uroot -e 'grant all on ngx_test.* to "nopass_sha256"@"%";' - if [ "$DB_VERSION" != 'mysql:5.7' ]; then # mysql:8.0 caching_sha2_password + if [ $DB_VERSION != 'mysql:5.7' ]; then # mysql:8.0 caching_sha2_password mysql -uroot -e 'create user "user_caching_sha2"@"%" identified with "caching_sha2_password" by "pass_caching_sha2";' mysql -uroot -e 'grant all on ngx_test.* to "user_caching_sha2"@"%";' mysql -uroot -e 'create user "nopass_caching_sha2"@"%" identified with "caching_sha2_password";' @@ -98,7 +100,7 @@ if [ "$DB_VERSION" == 'mysql:8.0' -o "$DB_VERSION" == 'mysql:5.7' ]; then # sha2 mysql -uroot -e 'create user "user_native"@"%" identified with "mysql_native_password" by "pass_native";' else # other: mysql_native_password, mysql_old_password - if [ "$DB_VERSION" == 'mysql:5.6' ]; then # mysql:5.6 sha256_password + if [ $DB_VERSION == 'mysql:5.6' ]; then # mysql:5.6 sha256_password mysql -uroot -e 'create user "user_sha256"@"%" identified with "sha256_password";' mysql -uroot -e 'set old_passwords = 2;set password for "user_sha256"@"%" = PASSWORD("pass_sha256");' mysql -uroot -e 'grant all on ngx_test.* to "user_sha256"@"%";' From 6bb27db17c715303e6f1c4ce5fe96774fee753e1 Mon Sep 17 00:00:00 2001 From: jiahao Date: Fri, 23 Oct 2020 23:10:38 +0800 Subject: [PATCH 4/5] bugfix: minor tweaks. --- .travis/initializedb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/initializedb.sh b/.travis/initializedb.sh index c9f7dfd..ddf13b1 100755 --- a/.travis/initializedb.sh +++ b/.travis/initializedb.sh @@ -69,7 +69,7 @@ sudo docker run \ mysql() { sudo docker exec mysqld mysql "${@}" } -for i in {1..100} : +for i in {1..100} do sleep 3 mysql --protocol=tcp -e 'select version()' && break From 027bd78889e8efdac588ccf0c8f09defb6b98f94 Mon Sep 17 00:00:00 2001 From: jiahao Date: Fri, 23 Oct 2020 23:12:39 +0800 Subject: [PATCH 5/5] bugfix: remove useless lines. --- .travis/initializedb.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis/initializedb.sh b/.travis/initializedb.sh index ddf13b1..dd0dacd 100755 --- a/.travis/initializedb.sh +++ b/.travis/initializedb.sh @@ -41,8 +41,6 @@ EOF path=`pwd` container_name=mysqld -sudo chmod -R 777 /var/run/mysqld -sudo docker pull ${DB_VERSION} if [ "$(sudo docker ps -a --filter "name=^/$container_name$" --format '{{.Names}}')" == "$container_name" ]; then sudo docker stop $container_name sudo docker rm $container_name