From fd9ad2bd460dad344e6ec3934ec803c096a871e2 Mon Sep 17 00:00:00 2001 From: Oliver Stark Date: Mon, 3 Apr 2023 19:18:03 +0200 Subject: [PATCH 1/9] Change ssl option until all dependencies fully support it --- bin/craft-copy-import-db.php | 2 +- src/.my.cnf.example | 3 +++ src/Services/Database.php | 13 ++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/bin/craft-copy-import-db.php b/bin/craft-copy-import-db.php index 3fa5fdb..bcd8988 100755 --- a/bin/craft-copy-import-db.php +++ b/bin/craft-copy-import-db.php @@ -69,7 +69,7 @@ '{MYSQL_DATABASE}' => getenv('MYSQL_DATABASE'), ]; -$cmd = 'mysql --defaults-extra-file={EXTRA_FILE} --force {MYSQL_DATABASE} < {FILE} && echo 1'; +$cmd = 'mysql --defaults-extra-file={EXTRA_FILE} --ssl-mode=DISABLED --force {MYSQL_DATABASE} < {FILE} && echo 1'; $cmd = str_replace(array_keys($tokens), array_values($tokens), $cmd); $process = \Symfony\Component\Process\Process::fromShellCommandline($cmd); diff --git a/src/.my.cnf.example b/src/.my.cnf.example index 194a286..e531007 100644 --- a/src/.my.cnf.example +++ b/src/.my.cnf.example @@ -14,3 +14,6 @@ max_allowed_packet=64M # Prevent SET @@GLOBAL.GTID_PURGED in dump set-gtid-purged=OFF + +[mysql] +ssl-mode=DISABLED diff --git a/src/Services/Database.php b/src/Services/Database.php index 273c3b8..c74e94b 100644 --- a/src/Services/Database.php +++ b/src/Services/Database.php @@ -81,10 +81,21 @@ protected function alterCraftDefaultBackupCommand(string $file): void // The actual overwrite to allow .my.cnf again // It basically reverts this change: // https://github.com/craftcms/cms/commit/c1068dd56974172a98213b616461266711aef86a - Craft::$app->getConfig()->getGeneral()->backupCommand = str_replace( + $backupCommand = str_replace( '--defaults-file', '--defaults-extra-file', $backupCommand ); + + // Disable single-transaction for now and change ssl-mode + $backupCommand = str_replace( + ' --single-transaction', + ' --ssl-mode=DISABLED', + $backupCommand + ); + + + Craft::$app->getConfig()->getGeneral()->backupCommand = $backupCommand; + } } From 70b00905cb1d01b7e0f4db9b36c0de5f44bdbf81 Mon Sep 17 00:00:00 2001 From: Oliver Stark Date: Mon, 3 Apr 2023 19:43:00 +0200 Subject: [PATCH 2/9] Assure my.cnf file on import too --- src/Actions/DbExportAction.php | 15 ++++----------- src/Actions/DbImportAction.php | 4 ++++ src/Helpers/MysqlConfigFile.php | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 src/Helpers/MysqlConfigFile.php diff --git a/src/Actions/DbExportAction.php b/src/Actions/DbExportAction.php index 81c33a0..9e18655 100644 --- a/src/Actions/DbExportAction.php +++ b/src/Actions/DbExportAction.php @@ -6,6 +6,7 @@ use Craft; use craft\errors\ShellCommandException; +use fortrabbit\Copy\Helpers\MysqlConfigFile; use fortrabbit\Copy\Plugin; use ostark\Yii2ArtisanBridge\base\Action; use yii\base\Exception; @@ -13,6 +14,8 @@ class DbExportAction extends Action { + use MysqlConfigFile; + /** * Export database from file * @@ -21,7 +24,7 @@ class DbExportAction extends Action public function run(?string $file = null): int { $plugin = Plugin::getInstance(); - $this->assureMyCfnForMysqldump(); + $this->assureMyCnf(); $this->info("Creating DB Dump in '{$file}'"); try { @@ -40,15 +43,5 @@ public function run(?string $file = null): int } } - protected function assureMyCfnForMysqldump(): bool - { - $mycnfDest = Craft::getAlias('@root') . '/.my.cnf'; - $mycnfSrc = Plugin::PLUGIN_ROOT_PATH . '/.my.cnf.example'; - if (! file_exists($mycnfDest)) { - return copy($mycnfSrc, $mycnfDest); - } - - return true; - } } diff --git a/src/Actions/DbImportAction.php b/src/Actions/DbImportAction.php index 8457639..857fa50 100644 --- a/src/Actions/DbImportAction.php +++ b/src/Actions/DbImportAction.php @@ -6,6 +6,7 @@ use craft\errors\ShellCommandException; use craft\helpers\FileHelper; +use fortrabbit\Copy\Helpers\MysqlConfigFile; use fortrabbit\Copy\Plugin; use ostark\Yii2ArtisanBridge\base\Action; use yii\base\Exception; @@ -13,6 +14,8 @@ class DbImportAction extends Action { + use MysqlConfigFile; + /** * Import database from file * @@ -31,6 +34,7 @@ public function run(string $file): int } $this->info("Importing DB Dump from '{$file}'"); + $this->assureMyCnf(); try { $file = Plugin::getInstance()->database->import($file); diff --git a/src/Helpers/MysqlConfigFile.php b/src/Helpers/MysqlConfigFile.php new file mode 100644 index 0000000..1c66d04 --- /dev/null +++ b/src/Helpers/MysqlConfigFile.php @@ -0,0 +1,26 @@ + Date: Mon, 3 Apr 2023 19:46:41 +0200 Subject: [PATCH 3/9] backup command tweaks --- src/Services/Database.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Services/Database.php b/src/Services/Database.php index c74e94b..f4a36b1 100644 --- a/src/Services/Database.php +++ b/src/Services/Database.php @@ -83,19 +83,17 @@ protected function alterCraftDefaultBackupCommand(string $file): void // https://github.com/craftcms/cms/commit/c1068dd56974172a98213b616461266711aef86a $backupCommand = str_replace( '--defaults-file', - '--defaults-extra-file', + '--defaults-extra-file --ssl-mode=DISABLED', $backupCommand ); - // Disable single-transaction for now and change ssl-mode + // Disable single-transaction for now $backupCommand = str_replace( ' --single-transaction', - ' --ssl-mode=DISABLED', + '', $backupCommand ); - Craft::$app->getConfig()->getGeneral()->backupCommand = $backupCommand; - } } From d83c313f7dd5e2ed1060a35c4d437232a4480ee7 Mon Sep 17 00:00:00 2001 From: Oliver Stark Date: Mon, 3 Apr 2023 19:48:33 +0200 Subject: [PATCH 4/9] 2.3.1 Changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb1cb1b..8ca72ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog -## 2.3.0 - 2023-XX-XX +## 2.3.1 - 2023-04-03 +- More tweaks on the mysql command line options + +## 2.3.0 - 2023-03-01 - Use `--defaults-extra-file` to support custom .my.cnf ## 2.2.0 - 2022-11-08 From ebf5c619abc719a32db63363ff227b717a313cda Mon Sep 17 00:00:00 2001 From: Oliver Stark Date: Mon, 3 Apr 2023 20:06:06 +0200 Subject: [PATCH 5/9] Option order --- src/Services/Database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/Database.php b/src/Services/Database.php index f4a36b1..428c25c 100644 --- a/src/Services/Database.php +++ b/src/Services/Database.php @@ -83,7 +83,7 @@ protected function alterCraftDefaultBackupCommand(string $file): void // https://github.com/craftcms/cms/commit/c1068dd56974172a98213b616461266711aef86a $backupCommand = str_replace( '--defaults-file', - '--defaults-extra-file --ssl-mode=DISABLED', + '--ssl-mode=DISABLED --defaults-extra-file', $backupCommand ); From 0db2fd49a8f4bfdf996ba9260d668775625847d2 Mon Sep 17 00:00:00 2001 From: Oliver Stark Date: Mon, 3 Apr 2023 20:15:58 +0200 Subject: [PATCH 6/9] Option order --- src/Services/Database.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Services/Database.php b/src/Services/Database.php index 428c25c..4f320b8 100644 --- a/src/Services/Database.php +++ b/src/Services/Database.php @@ -83,7 +83,7 @@ protected function alterCraftDefaultBackupCommand(string $file): void // https://github.com/craftcms/cms/commit/c1068dd56974172a98213b616461266711aef86a $backupCommand = str_replace( '--defaults-file', - '--ssl-mode=DISABLED --defaults-extra-file', + '--defaults-extra-file', $backupCommand ); @@ -94,6 +94,15 @@ protected function alterCraftDefaultBackupCommand(string $file): void $backupCommand ); + // Disable ssl-mode for now + $backupCommand = str_replace( + '--no-tablespaces', + '--no-tablespaces --ssl-mode=DISABLED', + $backupCommand + ); + + + Craft::$app->getConfig()->getGeneral()->backupCommand = $backupCommand; } } From bf7b77fc9cb76ca34c965658da82ace2a9fce7fb Mon Sep 17 00:00:00 2001 From: Oliver Stark Date: Mon, 3 Apr 2023 20:20:26 +0200 Subject: [PATCH 7/9] Missing import --- src/Helpers/MysqlConfigFile.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Helpers/MysqlConfigFile.php b/src/Helpers/MysqlConfigFile.php index 1c66d04..ca2b504 100644 --- a/src/Helpers/MysqlConfigFile.php +++ b/src/Helpers/MysqlConfigFile.php @@ -2,6 +2,7 @@ namespace fortrabbit\Copy\Helpers; +use Craft; use fortrabbit\Copy\Plugin; trait MysqlConfigFile From 7b1809a31022fe8db1e2f26dd0bfd519eb435f30 Mon Sep 17 00:00:00 2001 From: Oliver Stark Date: Mon, 3 Apr 2023 21:05:49 +0200 Subject: [PATCH 8/9] Alter Craft default restore command --- src/.my.cnf.example | 3 --- src/Services/Database.php | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/.my.cnf.example b/src/.my.cnf.example index e531007..194a286 100644 --- a/src/.my.cnf.example +++ b/src/.my.cnf.example @@ -14,6 +14,3 @@ max_allowed_packet=64M # Prevent SET @@GLOBAL.GTID_PURGED in dump set-gtid-purged=OFF - -[mysql] -ssl-mode=DISABLED diff --git a/src/Services/Database.php b/src/Services/Database.php index 4f320b8..423e0e6 100644 --- a/src/Services/Database.php +++ b/src/Services/Database.php @@ -44,6 +44,8 @@ public function import(?string $file = null): string { $file = $this->prepareFile($file); + $this->alterCraftDefaultRestoreCommand($file); + $this->db->restore($file); return $file; @@ -101,8 +103,19 @@ protected function alterCraftDefaultBackupCommand(string $file): void $backupCommand ); + Craft::$app->getConfig()->getGeneral()->backupCommand = $backupCommand; + } + + protected function alterCraftDefaultRestoreCommand(): void + { + // Determine the command that should be executed + $restoreCommand = $this->db->getSchema()->getDefaultRestoreCommand(); + Craft::$app->getConfig()->getGeneral()->restoreCommand = str_replace( + '.cnf"', + '.cnf" --ssl-mode=DISABLED', + $restoreCommand + ); - Craft::$app->getConfig()->getGeneral()->backupCommand = $backupCommand; } } From 4d930772cab070370de2cfa4a5cd611faa6d52c3 Mon Sep 17 00:00:00 2001 From: Oliver Stark Date: Mon, 3 Apr 2023 21:17:49 +0200 Subject: [PATCH 9/9] Run GA on ubuntu-20.04 --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b31f3e6..3ca73b8 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,7 +7,7 @@ env: jobs: build: name: Build - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 defaults: run: working-directory: ./docker