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

dump-autoload generating different autoload files when run under Docker #8808

Closed
Namoshek opened this issue Apr 20, 2020 · 6 comments
Closed
Labels

Comments

@Namoshek
Copy link

Namoshek commented Apr 20, 2020

I have no explanation for the following behavior. When running the same command under Docker, the generated classmap misses a few hundred mappings:

marvin /c/foo/bar> composer dump-autoload --no-scripts -vvv
Reading ./composer.json
Loading config file ./composer.json
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid
Executing command (/c/foo/bar): git branch --no-color --no-abbrev -v
Failed to initialize global composer: Composer could not find the config file: /home/marvin/.composer/composer.json
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Reading /c/foo/bar/vendor/composer/installed.json
Running 1.10.5 (2020-04-10 11:44:22) with PHP 7.3.14-1~deb10u1 on Linux / 4.19.84-microsoft-standard
Generating optimized autoload files
Generated optimized autoload files containing 6709 classes

marvin /c/foo/bar> docker run --rm -v /c/foo/bar:/app -w /app composer dump-autoload --no-scripts -vvv
Reading ./composer.json
Loading config file ./composer.json
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid
Executing command (/app): git branch --no-color --no-abbrev -v
Failed to initialize global composer: Composer could not find the config file: /tmp/composer.json
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Reading /app/vendor/composer/installed.json
Running 1.10.5 (2020-04-10 11:44:22) with PHP 7.4.5 on Linux / 4.19.84-microsoft-standard
Generating optimized autoload files
Generated optimized autoload files containing 6283 classes

Both commands are run under WSL 2. Running the Docker command from a Windows PowerShell doesn't change the output. (Installing PHP and composer under Windows I have not tried - it normally is a mess.)

I specifically miss class mappings of files defined in autoload.classmap (Laravel project):

{
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories",
            "database/migrations"
        ]
    }
}

In total there are 310 (+2 .gitignore) files in this three directories, which is less than the difference mentioned. The vendor/composer/autoload_classmap.php contains some of the classes in those directories though, just not all of them as I'd expect.

The only difference composer diagnose gives, besides the fact that everything seems ok, is the PHP version: 7.3.14 under WSL2 vs. 7.4.5 under Docker.

Has anyone ever noticed something similar? I appreciate any valuable hint.


Update: 2020-04-22 14:26

After some diggin', tryin' and swearin' I'm now at the point where I know it must be related to WSL 2. If I use the old Docker for Windows backend (Hyper-V VM), it works fine. Also within the WSL 2, if I copy my project from the /c/foo/bar path to an internal path like /home/marvin/foo/bar and run the Docker container to dump-autoload, the results are fine as well. So it must be an issue with the combination of WSL 2 as Docker backend and the mounted Windows drive.

Interestingly enough, when running docker run --rm -v /c/foo/bar:/app -w /app --entrypoint /bin/bash composer using the WSL 2 Docker backend, the scandir() PHP function for example returns all the files for which I'm missing the mapping within the classmap. So the files are there and permissions are fine, they just don't seem to be handled correctly.

@Seldaek
Copy link
Member

Seldaek commented Apr 22, 2020

You can try to repro this directly writing a php script which calls https://github.com/composer/composer/blob/1.10/src/Composer/Autoload/ClassMapGenerator.php#L62 and perhaps debugging that might help you figure out how to best report this to WSL? It definitely sounds like a WSL 2 bug more than a Composer one.

@Namoshek
Copy link
Author

Thank you for your answer. Unfortunately, I wasn't successful in tracking down the issue.

I've since switched to using the Linux root system though (projects located under /home/foo/bar for example) as soon as I realized it is nowadays possible to access the Linux file system via a network path: \\wsl$\Debian\home\foo\bar. Performance-wise, this is the best option anyway. So I'll close this issue and leave my solution as hint for future readers.

@roborourke
Copy link

FWIW I'm seeing this same issue running PHP installed via HomeBrew on a Mac. The classmaps seem to be missing for second level dependencies when using composer dump-autoload directly versus composer install / update.

@Seldaek
Copy link
Member

Seldaek commented Nov 9, 2021

@roborourke please create a new issue and include as many details as possible if you want us to help. There was no resolution here and adding a "me too" without additional info isn't going to move things forward.

@kkozlovskis
Copy link

Maybe this will help:

https://bugs.php.net/bug.php?id=80227
microsoft/WSL#5074

@Centurion
Copy link

if I copy my project from the /c/foo/bar path to an internal path like /home/marvin/foo/bar and run the Docker container to dump-autoload, the results are fine as well

THANK YOU!
everything under /mnt/c/* was very slow in apache container and was missing autoloads, moving it to /home/somewhere/else did the trick...what a scheiß

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

5 participants