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

Unable to Create "web" Directory for Drupal Projects in Docker with Composer 2.7.0 #11853 #11854

Open
daniela-zc opened this issue Feb 15, 2024 · 13 comments
Labels

Comments

@daniela-zc
Copy link

Issue Report:
When attempting to install Drupal into a Docker container using Composer version 2.7.0, the expected "web" directory is missing, causing issues with project setup. This behavior is unexpected and disrupts the standard Drupal installation process within Docker environments.

Temporal solution:
Downgrade to Composer 2.6.6: As a temporary workaround, reverting to Composer version 2.6.6 has been observed to resolve the issue. This allows for the creation of the "web" directory as expected, enabling the Drupal project setup within Docker containers.

@xabbuh
Copy link
Contributor

xabbuh commented Feb 15, 2024

Could it be that the directory was created by a plugin and that this plugin is not executed with 2.7.0 as you run Composer as the root user (see #11839)?

@daniela-zc
Copy link
Author

It's likely related, but I've already attempted using "export COMPOSER_ALLOW_SUPERUSER=1" without success. I'm working with Drupal, and this is what I have noticed:

- Running "composer create-project drupal/recommended-project ." functions correctly.
- However, "composer install" fails to produce the desired outcome.

The issue appears confined to Docker environments; outside of Docker, the process works flawlessly.

@Seldaek
Copy link
Member

Seldaek commented Feb 22, 2024

Have you tried prefixing the composer command with COMPOSER_ALLOW_SUPERUSER=1 like COMPOSER_ALLOW_SUPERUSER=1 composer install? That's a simple way to set env vars for just this one process. Because if you do export it may not work depending on the exact way you do it with docker. https://stackoverflow.com/questions/33379393/docker-env-vs-run-export

@Arr-n-D
Copy link

Arr-n-D commented Feb 27, 2024

I spent the entire morning trying to figure out why this was happening, and finally came across this thread. I assume therefore that we would need to add the plugins we wish to execute ( without using COMPOSER_ALLOW_SUPERUSER=1 ) to the config.allow-plugins list?

@Arr-n-D
Copy link

Arr-n-D commented Feb 28, 2024

I'm commenting the same thing on this as I've commented on #11839

I spent the entire morning debugging why at first, the web folder was not created by Drupal project scaffolding from my Docker image.
I then used the COMPOSER_ALLOW_SUPERUSER=1 setting and that fixed that issue.
I then spent the entire afternoon and evening trying to figure out why commands such as ./vendor/bin/drush from my container would fail with this error

Fatal error: Uncaught Error: Class "Drupal" not found in /var/www/html/vendor/drush/drush/src/Boot/DrupalBoot8.php:93

After reverting COMPOSER_ALLOW_SUPERUSER=1 and applying the composer self-update 2.6.6 solution, things restarted working as intended. This indicates to me that there's more to the solution than just setting COMPOSER_ALLOW_SUPERUSER

@Seldaek
Copy link
Member

Seldaek commented Feb 28, 2024

@Arr-n-D I'm not sure what the issue is there, but I know for sure that rolling back to 2.6.6 is not a long term solution. It's just hiding the problem and gets you stuck on an unmaintained Composer release. I'm fairly sure that either running as non-root or setting the COMPOSER_ALLOW_SUPERUSER=1 env var should get 2.7.0 running more or less like 2.6.6 did. So if there is another issue still maybe it's a small regression somewhere else. That's worth investigating IMO but I have no drupal knowledge and no working docker setup so I'd be happy if someone affected can help figure some of this out.

@Arr-n-D
Copy link

Arr-n-D commented Feb 28, 2024

I can confirm that COMPOSER_ALLOW_SUPERUSER=1 only mitigated the problem where the Web folder wasn't created, but additional issues rose further down the line.

Running as non-root is in the works for our workflow, but it's not something I can do in the short-term without adding a bunch of things to my workload.

I think it'd be worth investigating indeed, but I myself don't have much knowledge with Drupal in terms of project configuration, I am but the DevOps 😄 I could potentially try to generate a starter project with Drupal that fails due to this exact issue and send it over to you

@daniela-zc
Copy link
Author

daniela-zc commented Feb 28, 2024

@Arr-n-D This was the correct solution for me : Probesys/bileto@777ee4c
Check it out , it may work for you too

@Arr-n-D
Copy link

Arr-n-D commented Feb 28, 2024

@Arr-n-D This was the correct solution for me : Probesys/bileto@777ee4c
Check it out , it may work for you too

This seems to require running things with a non-root user.

As mentioned, it is not currently viable for me to change that

@daniela-zc
Copy link
Author

@Arr-n-D You are right, I was able to install "web" folder successfully but now I am having problems with drush not existing.

@Seldaek
Copy link
Member

Seldaek commented Feb 29, 2024

Could it be that drush or whatever plugin is running when drupal installs runs composer again in a subprocess that does not have the COMPOSER_ALLOW_SUPERUSER env var set, thus causing some failures?

Do you have instructions for me so I can try to repro this? Just composer commands to run and a git repo to clone if needed.

@Arr-n-D
Copy link

Arr-n-D commented Feb 29, 2024

@Seldaek Once I get off work today, I'll try and wip up a reproduceable example for you

Seldaek added a commit that referenced this issue Mar 4, 2024
…ing as non-interactive root, mainly create-project, refs #11854
@Seldaek
Copy link
Member

Seldaek commented Mar 4, 2024

From @daniela-zc 's message:

  • Running "composer create-project drupal/recommended-project ." functions correctly.
  • However, "composer install" fails to produce the desired outcome.

That is interesting, it allowed me to catch one last place where we didn't disable plugins correctly in create-project. c3efff9 fixes that so both install and create-project should fail in the same way now when run as root without COMPOSER_ALLOW_SUPERUSER=1 set.

I was able to reproduce that the web dir is created when having the env var, I see this after the composer install is complete:

Scaffolding files for drupal/core:
  - Copy [project-root]/.editorconfig from assets/scaffold/files/editorconfig
  - Copy [project-root]/.gitattributes from assets/scaffold/files/gitattributes
  - Copy [web-root]/.csslintrc from assets/scaffold/files/csslintrc
  - Copy [web-root]/.eslintignore from assets/scaffold/files/eslintignore
  - Copy [web-root]/.eslintrc.json from assets/scaffold/files/eslintrc.json
  - Copy [web-root]/.ht.router.php from assets/scaffold/files/ht.router.php
  - Copy [web-root]/.htaccess from assets/scaffold/files/htaccess
[...]

And without I do not get this, and indeed the web dir does not exist. Note the lines with yellow and red background in this output:

image

So I am still waiting to see a way to repro the failure with the env var set correctly. As far as I can tell it all works as it should.

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

No branches or pull requests

4 participants