From 3c021ff6c92e49fad669deed0805cceae26bdccf Mon Sep 17 00:00:00 2001 From: Piotr Kwiecinski Date: Sat, 8 Aug 2020 14:21:28 +0100 Subject: [PATCH 1/2] script to setup integration tests --- compose/bin/setup-integration-tests | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 compose/bin/setup-integration-tests diff --git a/compose/bin/setup-integration-tests b/compose/bin/setup-integration-tests new file mode 100755 index 000000000..c49838d2c --- /dev/null +++ b/compose/bin/setup-integration-tests @@ -0,0 +1,19 @@ +#!/bin/bash +source env/db.env + +REAL_SRC=$(cd -P "src" && pwd) +MYSQL_CONFIG=dev/tests/integration/etc/install-config-mysql.php +INTEGRATION_DB=magento_integration_tests +CREATE_DB="bin/clinotty mysqladmin -hdb -uroot -p${MYSQL_ROOT_PASSWORD} create ${INTEGRATION_DB}" && echo "Database ${INTEGRATION_DB} created." +bin/clinotty mysql -hdb -uroot -p${MYSQL_ROOT_PASSWORD} ${INTEGRATION_DB} -e exit &> /dev/null || $CREATE_DB + +sed -e "s/'db-host' => 'localhost'/'db-host' => 'db'/" \ + -e "s/'db-password' => '123123q'/'db-password' => '${MYSQL_ROOT_PASSWORD}'/" \ + -e "s/'amqp-host' => 'localhost'/'amqp-host' => 'rabbitmq'/" \ + src/dev/tests/integration/etc/install-config-mysql.php.dist > src/dev/tests/integration/etc/install-config-mysql.php + +# Workaround until coping nested files works as expected +docker cp $REAL_SRC/$MYSQL_CONFIG $(docker-compose ps -q phpfpm|awk '{print $1}'):/var/www/html/$MYSQL_CONFIG +echo "Completed copying $MYSQL_CONFIG from host to container" +bin/fixowns $MYSQL_CONFIG +bin/fixperms $MYSQL_CONFIG From db0bb7286fef702e4e2c81f875d6bc85c58bb5ee Mon Sep 17 00:00:00 2001 From: Piotr Kwiecinski Date: Fri, 28 Aug 2020 23:00:12 +0100 Subject: [PATCH 2/2] Use credentials from env/db.env Update command to handle db creation and permissions --- compose/bin/setup-integration-tests | 23 +++++++++++------------ compose/env/db.env | 6 ++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/compose/bin/setup-integration-tests b/compose/bin/setup-integration-tests index c49838d2c..bd0892253 100755 --- a/compose/bin/setup-integration-tests +++ b/compose/bin/setup-integration-tests @@ -1,19 +1,18 @@ #!/bin/bash source env/db.env -REAL_SRC=$(cd -P "src" && pwd) -MYSQL_CONFIG=dev/tests/integration/etc/install-config-mysql.php -INTEGRATION_DB=magento_integration_tests -CREATE_DB="bin/clinotty mysqladmin -hdb -uroot -p${MYSQL_ROOT_PASSWORD} create ${INTEGRATION_DB}" && echo "Database ${INTEGRATION_DB} created." -bin/clinotty mysql -hdb -uroot -p${MYSQL_ROOT_PASSWORD} ${INTEGRATION_DB} -e exit &> /dev/null || $CREATE_DB +MYSQL_INTEGRATION_CONFIG=dev/tests/integration/etc/install-config-mysql.php -sed -e "s/'db-host' => 'localhost'/'db-host' => 'db'/" \ +# If database doesn't exist create it and add user permissions +bin/clinotty mysql -h${MYSQL_INTEGRATION_HOST} -uroot -p${MYSQL_ROOT_PASSWORD} ${MYSQL_INTEGRATION_DATABASE} -e exit &> /dev/null || + bin/clinotty mysqladmin -h${MYSQL_INTEGRATION_HOST} -uroot -p${MYSQL_ROOT_PASSWORD} create ${MYSQL_INTEGRATION_DATABASE} && + echo "Database ${MYSQL_INTEGRATION_DATABASE} created." && + bin/cli mysql -uroot -p${MYSQL_ROOT_PASSWORD} -h${MYSQL_INTEGRATION_HOST} \ + -e "GRANT ALL PRIVILEGES ON ${MYSQL_INTEGRATION_DATABASE}.* TO '${MYSQL_INTEGRATION_USER}'@'%';FLUSH PRIVILEGES;" + +sed -e "s/'db-host' => 'localhost'/'db-host' => '${MYSQL_INTEGRATION_HOST}'/" \ -e "s/'db-password' => '123123q'/'db-password' => '${MYSQL_ROOT_PASSWORD}'/" \ -e "s/'amqp-host' => 'localhost'/'amqp-host' => 'rabbitmq'/" \ - src/dev/tests/integration/etc/install-config-mysql.php.dist > src/dev/tests/integration/etc/install-config-mysql.php + src/${MYSQL_INTEGRATION_CONFIG}.dist > src/${MYSQL_INTEGRATION_CONFIG} -# Workaround until coping nested files works as expected -docker cp $REAL_SRC/$MYSQL_CONFIG $(docker-compose ps -q phpfpm|awk '{print $1}'):/var/www/html/$MYSQL_CONFIG -echo "Completed copying $MYSQL_CONFIG from host to container" -bin/fixowns $MYSQL_CONFIG -bin/fixperms $MYSQL_CONFIG +bin/copytocontainer ${MYSQL_INTEGRATION_CONFIG} diff --git a/compose/env/db.env b/compose/env/db.env index 850b62f9e..b23ada319 100644 --- a/compose/env/db.env +++ b/compose/env/db.env @@ -2,3 +2,9 @@ MYSQL_ROOT_PASSWORD=magento MYSQL_DATABASE=magento MYSQL_USER=magento MYSQL_PASSWORD=magento + +MYSQL_INTEGRATION_ROOT_PASSWORD=magento +MYSQL_INTEGRATION_DATABASE=magento_integration_tests +MYSQL_INTEGRATION_USER=magento +MYSQL_INTEGRATION_PASSWORD=magento +MYSQL_INTEGRATION_HOST=db