Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set-codebase-owner function #320

Open
wants to merge 10 commits into
base: development
Choose a base branch
from

Conversation

DonRichards
Copy link
Member

@DonRichards DonRichards commented Jan 13, 2023

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.

  • Excludes the /sites/default/files/ to prevent causing issues with File systems like S3.
  • Excludes files with the proper permissions already.

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
Copy link
Contributor

@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
Copy link
Contributor

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
Copy link
Member Author

@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
Copy link
Contributor

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
Copy link
Contributor

joshdentremont commented Jan 18, 2023

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
Copy link
Member Author

@joshdentremont Did that error happen before using this function?

@joshdentremont
Copy link
Contributor

@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: #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
Copy link
Member Author

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

@DonRichards
Copy link
Member Author

@joshdentremont Would you mind giving that a try?

@DonRichards
Copy link
Member Author

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
Copy link
Contributor

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
Copy link
Member Author

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

@seth-shaw-asu
Copy link

@DonRichards, could you please resolve the merge conflicts?

@DonRichards
Copy link
Member Author

Rebased

@DonRichards
Copy link
Member Author

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

@joshdentremont
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants