Islandora-Devops / isle-dc

ISLE 8 - Dockerized Islandora 8 Deployment orchestrated with docker-compose
MIT License
23 stars 60 forks source link

Add set-codebase-owner function #320

Open DonRichards opened 1 year ago

DonRichards commented 1 year ago

This should add a function to set permissions of "codebase/" during the build process.

This also adds a function that you're able to call with a make command at any time.

The command uses find with a couple of exclusions for improved performance of running a permissions change.

During the build process, the vendor directory may already be there or is set to root, or in some cases, the entire codebase directory is root (this happens in some MACs due to user IDs).

This shouldn't impact any existing installations.

How to test

  1. Run make clean (to start with a completely clean build).
  2. Run make set-codebase-owner a. The codebase should not exist at this point so that it will output the following error message. "No codebase/ folder found, skipping"
  3. Run make starter-dev b. This should build as normal. Check that the build is completed as normal.
joshdentremont commented 1 year ago

@DonRichards Drupal failed to install when I ran make starter:

 [notice] Starting Drupal installation. This takes a while.
 [notice] Performed install task: install_select_language
 [notice] Performed install task: install_select_profile
 [notice] Performed install task: install_load_profile
 [notice] Performed install task: install_verify_requirements
 [error]  Error: Cannot use object of type stdClass as array in drupal_rewrite_settings() (line 329 of /var/www/drupal/web/core/includes/install.inc) #0 /var/www/drupal/web/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php(267): drupal_rewrite_settings()
#1 [internal function]: Drupal\Core\Installer\Form\SiteSettingsForm->submitForm()
#2 /var/www/drupal/web/core/lib/Drupal/Core/Form/FormSubmitter.php(114): call_user_func_array()
#3 /var/www/drupal/web/core/lib/Drupal/Core/Form/FormSubmitter.php(52): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers()
#4 /var/www/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php(595): Drupal\Core\Form\FormSubmitter->doSubmitForm()
#5 /var/www/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php(501): Drupal\Core\Form\FormBuilder->processForm()
#6 /var/www/drupal/web/core/includes/install.core.inc(967): Drupal\Core\Form\FormBuilder->submitForm()
#7 /var/www/drupal/web/core/includes/install.core.inc(618): install_get_form()
#8 /var/www/drupal/web/core/includes/install.core.inc(571): install_run_task()
#9 /var/www/drupal/web/core/includes/install.core.inc(119): install_run_tasks()
#10 /var/www/drupal/vendor/drush/drush/includes/drush.inc(213): install_drupal()
#11 /var/www/drupal/vendor/drush/drush/includes/drush.inc(197): drush_call_user_func_array()
#12 /var/www/drupal/vendor/drush/drush/src/Commands/core/SiteInstallCommands.php(149): drush_op()
#13 [internal function]: Drush\Commands\core\SiteInstallCommands->install()
#14 /var/www/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array()
#15 /var/www/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
#16 /var/www/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
#17 /var/www/drupal/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(390): Consolidation\AnnotatedCommand\CommandProcessor->process()
#18 /var/www/drupal/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
#19 /var/www/drupal/vendor/symfony/console/Application.php(1039): Symfony\Component\Console\Command\Command->run()
#20 /var/www/drupal/vendor/symfony/console/Application.php(275): Symfony\Component\Console\Application->doRunCommand()
#21 /var/www/drupal/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#22 /var/www/drupal/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run()
#23 /var/www/drupal/vendor/drush/drush/src/Runtime/Runtime.php(48): Drush\Runtime\Runtime->doRun()
#24 /var/www/drupal/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run()
#25 /var/www/drupal/vendor/drush/drush/includes/preflight.inc(18): require('/var/www/drupal...')
#26 phar:///usr/bin/drush/bin/drush.php(141): drush_main()
#27 /usr/bin/drush(10): require('phar:///usr/bin...')
#28 {main}.
Error: Cannot use object of type stdClass as array in /var/www/drupal/web/core/includes/install.inc on line 329 #0 /var/www/drupal/web/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php(267): drupal_rewrite_settings()
#1 [internal function]: Drupal\Core\Installer\Form\SiteSettingsForm->submitForm()
#2 /var/www/drupal/web/core/lib/Drupal/Core/Form/FormSubmitter.php(114): call_user_func_array()
#3 /var/www/drupal/web/core/lib/Drupal/Core/Form/FormSubmitter.php(52): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers()
#4 /var/www/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php(595): Drupal\Core\Form\FormSubmitter->doSubmitForm()
#5 /var/www/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php(501): Drupal\Core\Form\FormBuilder->processForm()
#6 /var/www/drupal/web/core/includes/install.core.inc(967): Drupal\Core\Form\FormBuilder->submitForm()
#7 /var/www/drupal/web/core/includes/install.core.inc(618): install_get_form()
#8 /var/www/drupal/web/core/includes/install.core.inc(571): install_run_task()
#9 /var/www/drupal/web/core/includes/install.core.inc(119): install_run_tasks()
#10 /var/www/drupal/vendor/drush/drush/includes/drush.inc(213): install_drupal()
#11 /var/www/drupal/vendor/drush/drush/includes/drush.inc(197): drush_call_user_func_array()
#12 /var/www/drupal/vendor/drush/drush/src/Commands/core/SiteInstallCommands.php(149): drush_op()
#13 [internal function]: Drush\Commands\core\SiteInstallCommands->install()
#14 /var/www/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array()
#15 /var/www/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
#16 /var/www/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
#17 /var/www/drupal/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(390): Consolidation\AnnotatedCommand\CommandProcessor->process()
#18 /var/www/drupal/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
#19 /var/www/drupal/vendor/symfony/console/Application.php(1039): Symfony\Component\Console\Command\Command->run()
#20 /var/www/drupal/vendor/symfony/console/Application.php(275): Symfony\Component\Console\Application->doRunCommand()
#21 /var/www/drupal/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#22 /var/www/drupal/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run()
#23 /var/www/drupal/vendor/drush/drush/src/Runtime/Runtime.php(48): Drush\Runtime\Runtime->doRun()
#24 /var/www/drupal/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run()
#25 /var/www/drupal/vendor/drush/drush/includes/preflight.inc(18): require('/var/www/drupal...')
#26 phar:///usr/bin/drush/bin/drush.php(141): drush_main()
#27 /usr/bin/drush(10): require('phar:///usr/bin...')
#28 {main}
Error: Cannot use object of type stdClass as array in drupal_rewrite_settings() (line 329 of /var/www/drupal/web/core/includes/install.inc).
 [warning] Drush command terminated abnormally.
make[1]: *** [starter-finalize] Error 1
make: *** [starter] Error 2
joshdentremont commented 1 year ago

Ran make clean and make starter again and this time Drupal was installed, but I'm still getting errors trying to use composer:

  [ErrorException]
  file_put_contents(/var/www/drupal/web/sites/default/settings.php): failed to open stream: Operation not permitted

The permissions are the same with this PR as they were before, nginx:nginx on the drupal container, and josh:101 locally

DonRichards commented 1 year ago

@joshdentremont I think I was able to pinpoint the build issue. When those errors came up in the past, it was always either a missing codebase directory or a file permission issue. These changes should fire the permissions reset when it's needed. Are you using make up, make starter-dev, or something else to build? Either way, give this a try and let me know if this corrects your build issue.

joshdentremont commented 1 year ago

Still getting the same permissions and error message. I am running make starter with the environment variable set to starter in the .env.

If I manually set settings.php to be owned by root and give the owner write permissions Composer seems to work. What is weird is that this is not necessary on Linux. If I run composer with a read only file on linux it doesn't throw this error

  [ErrorException]
  file_put_contents(/var/www/drupal/web/sites/default/settings.php): failed to open stream: Operation not permitted
joshdentremont commented 1 year ago

Just noticed today that changing settings.php to have write permissions worked, but when I ran make up again this morning it changed it back to read only.

DonRichards commented 1 year ago

@joshdentremont Did that error happen before using this function?

joshdentremont commented 1 year ago

@DonRichards It happened when using this commit, which should have run your code automatically I think.

I added some more detail to the original issue that might help clear things up: https://github.com/Islandora-Devops/isle-dc/issues/306

Essentially, it seems like the issue is a mac permission vs linux permissions thing. My guess is that since the codebase is mounted to the local filesystem it's not allowing root in the docker container to write to a read only file, which is allowed on Linux apparently.

Since it's a read only file, changing the owner doesn't seem to make any difference.

DonRichards commented 1 year ago

It took me a while to replicate this issue. OK, I think I have found a solution.

DonRichards commented 1 year ago

@joshdentremont Would you mind giving that a try?

DonRichards commented 1 year ago

I added it's ability to fall back if docker isn't running and if the codebase directory doesn't exist it just skips it.

joshdentremont commented 1 year ago

This appears to work as intended, but it's different to the issue I was having so it would probably be good to have someone else test it as well.

One concern I have is that it can take a bit of time to change these permissions so adding it to make up can really slow down the process of bringing your containers back up.

DonRichards commented 1 year ago

@joshdentremont The permissions need to be correct to build correctly. This only makes changes if the permissions are wrong.

seth-shaw-asu commented 1 year ago

@DonRichards, could you please resolve the merge conflicts?

DonRichards commented 1 year ago

Rebased

DonRichards commented 1 year ago

During the rebase I added a 2nd "config-export" unintentionally. I just pushed the removal of it.

joshdentremont commented 1 year ago

This works as described. If there is no codebase folder it skips and moves on, installing via make starter or make starter_dev works as intended, and running make set-codebase-owner sets the permissions to user:nginx