From 6942289adc87f96ff66001ae65c444ad7e8cd0fb Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 18 Oct 2017 11:06:24 +1030 Subject: [PATCH 1/6] Adding tmp dir support to the composer handler. --- docker-compose.yml | 1 + src/Handler.php | 1 + 2 files changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 7125419..cc54353 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,6 +17,7 @@ services: DATABASE_USER: user DATABASE_PASSWORD: password PRIVATE_DIR: /shared/private + TMP_DIR: /shared/tmp PUBLIC_DIR: web/sites/default/files HASH_SALT: random-hash CONFIG_SYNC_DIRECTORY: /shared/private/random-hash/sync diff --git a/src/Handler.php b/src/Handler.php index 2d3fe9d..ce9cc6f 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -134,6 +134,7 @@ public function modifySettingsFile() " 'namespace' => getenv('DATABASE_NAMESPACE') ?: 'Drupal\\\\Core\\\\Database\\\\Driver\\\\mysql',\n" . ");\n" . "\$settings['file_private_path'] = getenv('PRIVATE_DIR');\n" . + "\$settings['file_temporary_path'] = getenv('TMP_DIR');\n" . "\$settings['hash_salt'] = getenv('HASH_SALT') ?: '" . str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(random_bytes(55))) . "';\n" . "\$config_directories['sync'] = getenv('CONFIG_SYNC_DIRECTORY') ?: 'sites/default/files/config_".str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(random_bytes(55))) . "/sync';\n" . "if (! is_dir(\$app_root . '/' . \$config_directories['sync'])) mkdir(\$app_root . '/' . \$config_directories['sync'], 0777, true);\n" . From 357c30c557f9ed445de5870eb1b101a36a1b7bed Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 18 Oct 2017 11:21:31 +1030 Subject: [PATCH 2/6] Need to set dir and permissions as well. --- RoboFileBase.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RoboFileBase.php b/RoboFileBase.php index 5bcf2ab..fe10e5f 100644 --- a/RoboFileBase.php +++ b/RoboFileBase.php @@ -27,6 +27,7 @@ abstract class RoboFileBase extends \Robo\Tasks { protected $application_root = "web"; protected $file_public_path = '/shared/public'; protected $file_private_path = '/shared/private'; + protected $file_temporary_path = '/shared/tmp'; protected $services_yml = "web/sites/default/services.yml"; protected $settings_php = "web/sites/default/settings.php"; @@ -178,8 +179,10 @@ public function buildSetFilesOwner() { $this->say("Setting files directory owner."); $this->_exec("$this->sudo_cmd chown $this->web_server_user:$this->local_user -R $this->file_public_path"); $this->_exec("$this->sudo_cmd chown $this->web_server_user:$this->local_user -R $this->file_private_path"); + $this->_exec("$this->sudo_cmd chown $this->web_server_user:$this->local_user -R $this->file_temporary_path"); $this->setPermissions($this->file_public_path, '0775'); $this->setPermissions($this->file_private_path, '0775'); + $this->setPermissions($this->file_temporary_path, '0775'); } /** From 04d54a6bead0fb55bce3f52f904f1e2f03ecfda6 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 18 Oct 2017 11:59:44 +1030 Subject: [PATCH 3/6] Add public dir support in, make dirs if required. --- src/Handler.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Handler.php b/src/Handler.php index ce9cc6f..3ba690a 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -93,9 +93,12 @@ public function createDirectories() { $root = $this->getDrupalRootPath(); $dirs = [ - 'modules', - 'profiles', - 'themes', + $root . '/modules', + $root . '/profiles', + $root . '/themes', + getenv('PRIVATE_DIR') ?: '/shared/private', + getenv('TMP_DIR') ?: '/shared/tmp', + getenv('PUBLIC_DIR') ?: 'web/sites/default/files', ]; // Required for unit testing. @@ -133,8 +136,9 @@ public function modifySettingsFile() " 'collation' => getenv('DATABASE_COLLATION') ?: 'utf8mb4_general_ci',\n" . " 'namespace' => getenv('DATABASE_NAMESPACE') ?: 'Drupal\\\\Core\\\\Database\\\\Driver\\\\mysql',\n" . ");\n" . - "\$settings['file_private_path'] = getenv('PRIVATE_DIR');\n" . - "\$settings['file_temporary_path'] = getenv('TMP_DIR');\n" . + "\$settings['file_private_path'] = getenv('PRIVATE_DIR') ?: '/shared/private';\n" . + "\$settings['file_temporary_path'] = getenv('TMP_DIR') ?: '/shared/tmp';\n" . + "\$settings['file_public_path'] = getenv('PUBLIC_DIR') ?: 'web/sites/default/files';\n" . "\$settings['hash_salt'] = getenv('HASH_SALT') ?: '" . str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(random_bytes(55))) . "';\n" . "\$config_directories['sync'] = getenv('CONFIG_SYNC_DIRECTORY') ?: 'sites/default/files/config_".str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(random_bytes(55))) . "/sync';\n" . "if (! is_dir(\$app_root . '/' . \$config_directories['sync'])) mkdir(\$app_root . '/' . \$config_directories['sync'], 0777, true);\n" . From 986be4d714bb672b911ccb93c9aa8d5a31264b55 Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 18 Oct 2017 14:10:11 +1030 Subject: [PATCH 4/6] Revert "Add public dir support in, make dirs if required." This reverts commit 04d54a6bead0fb55bce3f52f904f1e2f03ecfda6. --- src/Handler.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Handler.php b/src/Handler.php index 3ba690a..ce9cc6f 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -93,12 +93,9 @@ public function createDirectories() { $root = $this->getDrupalRootPath(); $dirs = [ - $root . '/modules', - $root . '/profiles', - $root . '/themes', - getenv('PRIVATE_DIR') ?: '/shared/private', - getenv('TMP_DIR') ?: '/shared/tmp', - getenv('PUBLIC_DIR') ?: 'web/sites/default/files', + 'modules', + 'profiles', + 'themes', ]; // Required for unit testing. @@ -136,9 +133,8 @@ public function modifySettingsFile() " 'collation' => getenv('DATABASE_COLLATION') ?: 'utf8mb4_general_ci',\n" . " 'namespace' => getenv('DATABASE_NAMESPACE') ?: 'Drupal\\\\Core\\\\Database\\\\Driver\\\\mysql',\n" . ");\n" . - "\$settings['file_private_path'] = getenv('PRIVATE_DIR') ?: '/shared/private';\n" . - "\$settings['file_temporary_path'] = getenv('TMP_DIR') ?: '/shared/tmp';\n" . - "\$settings['file_public_path'] = getenv('PUBLIC_DIR') ?: 'web/sites/default/files';\n" . + "\$settings['file_private_path'] = getenv('PRIVATE_DIR');\n" . + "\$settings['file_temporary_path'] = getenv('TMP_DIR');\n" . "\$settings['hash_salt'] = getenv('HASH_SALT') ?: '" . str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(random_bytes(55))) . "';\n" . "\$config_directories['sync'] = getenv('CONFIG_SYNC_DIRECTORY') ?: 'sites/default/files/config_".str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(random_bytes(55))) . "/sync';\n" . "if (! is_dir(\$app_root . '/' . \$config_directories['sync'])) mkdir(\$app_root . '/' . \$config_directories['sync'], 0777, true);\n" . From 34b71e87f417f02d92a8617ffdb3a154f2a9958b Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 18 Oct 2017 14:36:19 +1030 Subject: [PATCH 5/6] Supporting vars in the settings. --- src/Handler.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Handler.php b/src/Handler.php index ce9cc6f..30acb7c 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -133,8 +133,9 @@ public function modifySettingsFile() " 'collation' => getenv('DATABASE_COLLATION') ?: 'utf8mb4_general_ci',\n" . " 'namespace' => getenv('DATABASE_NAMESPACE') ?: 'Drupal\\\\Core\\\\Database\\\\Driver\\\\mysql',\n" . ");\n" . - "\$settings['file_private_path'] = getenv('PRIVATE_DIR');\n" . - "\$settings['file_temporary_path'] = getenv('TMP_DIR');\n" . + "\$settings['file_private_path'] = getenv('PRIVATE_DIR') ?: '/shared/private';\n" . + "\$settings['file_temporary_path'] = getenv('TMP_DIR') ?: '/shared/tmp';\n" . + "\$settings['file_public_path'] = getenv('PUBLIC_DIR') ?: 'web/sites/default/files';\n" . "\$settings['hash_salt'] = getenv('HASH_SALT') ?: '" . str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(random_bytes(55))) . "';\n" . "\$config_directories['sync'] = getenv('CONFIG_SYNC_DIRECTORY') ?: 'sites/default/files/config_".str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(random_bytes(55))) . "/sync';\n" . "if (! is_dir(\$app_root . '/' . \$config_directories['sync'])) mkdir(\$app_root . '/' . \$config_directories['sync'], 0777, true);\n" . From dbe826112ca0259ba53718a2810658b7cbd1b68f Mon Sep 17 00:00:00 2001 From: Simon Lindsay Date: Wed, 18 Oct 2017 15:24:51 +1030 Subject: [PATCH 6/6] As it turns out, the PUBLIC_DIR is the host directory, we symlink the host directory into /code/web/sites/default/files always, only the backend location can be changed with the PUBLIC_DIR variable --- src/Handler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Handler.php b/src/Handler.php index 30acb7c..36ca801 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -135,7 +135,6 @@ public function modifySettingsFile() ");\n" . "\$settings['file_private_path'] = getenv('PRIVATE_DIR') ?: '/shared/private';\n" . "\$settings['file_temporary_path'] = getenv('TMP_DIR') ?: '/shared/tmp';\n" . - "\$settings['file_public_path'] = getenv('PUBLIC_DIR') ?: 'web/sites/default/files';\n" . "\$settings['hash_salt'] = getenv('HASH_SALT') ?: '" . str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(random_bytes(55))) . "';\n" . "\$config_directories['sync'] = getenv('CONFIG_SYNC_DIRECTORY') ?: 'sites/default/files/config_".str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(random_bytes(55))) . "/sync';\n" . "if (! is_dir(\$app_root . '/' . \$config_directories['sync'])) mkdir(\$app_root . '/' . \$config_directories['sync'], 0777, true);\n" .