overtrue / phplint

:bug: A tool that can speed up linting of php files by running several lint processes at once.
MIT License
988 stars 89 forks source link

Crash when using Docker for PHP 8.2 #179

Closed ghnp5 closed 1 year ago

ghnp5 commented 1 year ago

New Issue

Diagnose

Output of `docker inspect overtrue/phplint:8.2` command ``` [ { "Id": "sha256:b95d8b30659175cb0ec475a5923fcf1b0ccc4a1f1bfdebba37477b60ea5a0e8a", "RepoTags": [ "overtrue/phplint:8.2" ], "RepoDigests": [ "overtrue/phplint@sha256:52d28859e36e32047f26f6239bbc1aac13a3c9f5d493ab10d0a89bb1d465ba10" ], "Parent": "", "Comment": "buildkit.dockerfile.v0", "Created": "2022-12-28T14:28:03.483191165Z", "Container": "", "ContainerConfig": { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": null, "Cmd": null, "Image": "", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": null }, "DockerVersion": "", "Author": "", "Config": { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "PHPIZE_DEPS=autoconf \t\tdpkg-dev dpkg \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkgconf \t\tre2c", "PHP_INI_DIR=/usr/local/etc/php", "PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64", "PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64", "PHP_LDFLAGS=-Wl,-O1 -pie", "GPG_KEYS=39B641343D8C104B2B146DC3F9C39DC0B9698544 E60913E4DF209907D8E30D96659A97C9CF2A795A 1198C0117593497A5EC5C199286AF1F9897469DC", "PHP_VERSION=8.2.0", "PHP_URL=https://www.php.net/distributions/php-8.2.0.tar.xz", "PHP_ASC_URL=https://www.php.net/distributions/php-8.2.0.tar.xz.asc", "PHP_SHA256=6ea4c2dfb532950fd712aa2a08c1412a6a81cd1334dd0b0bf88a8e44c2b3a943" ], "Cmd": null, "Image": "", "Volumes": null, "WorkingDir": "/workdir", "Entrypoint": [ "/entrypoint.sh" ], "OnBuild": null, "Labels": null }, "Architecture": "amd64", "Os": "linux", "Size": 96329369, "VirtualSize": 96329369, "GraphDriver": { "Data": { "LowerDir": "/.../overlay2/fe108bc0ef398e6b5d5232b440f7309cbe494bb033199ccb08ff52b722081c63/diff:/.../overlay2/4b1bb4103bfc98f3d0d46570629c31785f87a5c55c5980546b260e27ffcd5ee2/diff:/.../overlay2/753c0ffd6cbb05a5f50062d34a1a3f68408add3782e4504cdea5b5afb7035fb3/diff:/.../overlay2/816b1ca059d0b7b2c59cda920209ed644dfd290730f0690e1e8ca761115930dc/diff:/.../overlay2/ccff7a700b740f6bd0073194da11a02c24add6a1278c5b4d83aee28c39bafe0a/diff:/.../overlay2/01aed581c134f85634c77a34fcb9210e14a11f2ba8d60175a02694ce312b9b88/diff:/.../overlay2/408436218d22fe8f434c20a39ec0030b505b923cf53b055055918a55824aecda/diff:/.../overlay2/da17778af5cabe098a9e86b6263e7e68b36af2726d167a31a52e0f8de7b3e00d/diff:/.../overlay2/25a55d205fb7d5d8c9c0d6cdd6913ee80387c6f4bad4a74c376dc891bf8f2fff/diff:/.../overlay2/95ac80e0fcdaae24871486871d32cdd8d47c14341ef5fc7fe919267d18069251/diff:/.../overlay2/097c077c5645158bb4af2a3cd4dd617626c95c46b1253bf7b0e8e6f77099ba92/diff:/.../overlay2/2e1148d0bd6cb87adbaa85377cecc8da6fb83b7867dc47960900f417e024849a/diff:/.../overlay2/7f875d20fafcd289c884e886d4edbd737e91536ac37b00afa751a2e64e203707/diff", "MergedDir": "/.../overlay2/b8b6d6d613002ad18f9c3a25c017262759aab37b9884e6dec2a4ce5feb960591/merged", "UpperDir": "/.../overlay2/b8b6d6d613002ad18f9c3a25c017262759aab37b9884e6dec2a4ce5feb960591/diff", "WorkDir": "/.../overlay2/b8b6d6d613002ad18f9c3a25c017262759aab37b9884e6dec2a4ce5feb960591/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:ded7a220bb058e28ee3254fbba04ca90b679070424424761a53a043b93b612bf", "sha256:1c5a6c02a11369d794a3c816f4ff32f215d6437a40832e0cce55edfdb19cd47f", "sha256:a7046b0c6ea4ebdd0617a8eaead1011f95fe2fab1272ac70ac129cf0cf5e8998", "sha256:f28cd5dd6faa0f7953ecd8dad531764594f7e94ca803a2d84807992101094af6", "sha256:4be5ce74bb4bfc95d96137cd18fbcc31116d3424ef697a640834985a2f8f77dc", "sha256:643f8d0063368035a69ae4de25f814ef32737e9ab561873943f4cf580cdd43a4", "sha256:296fdb636dfd3e22c7d093623db78ad6850f9f1e87ee62233cab80526b3f9c38", "sha256:31688591c20487e16b5dcb4c5b73ffc15a727a170b97ed666cf3c94cf9054e7c", "sha256:1e8819c423127a2e1fee7c01792bc01732114f126c8144ae760d72004f90c2b3", "sha256:7e54bcd2dd6f5bb0149d9b16ce614404a1e97d16b2b84560b5710332212f7a03", "sha256:2301ac3291cbf881f471e9d6d2608b29f6ab634d9ead05c9548d6a303a33dd69", "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef", "sha256:0c6e54e666c7a8c61f482f12a1a0d78b714f5356a33fbd83244f6de660126127", "sha256:a7e8b751f76d3f1d49a13ea22571a86e800b0dd646f6635260c9fb03c1acf38c" ] }, "Metadata": { "LastTagTime": "0001-01-01T00:00:00Z" } } ] ```

Summary

I'm trying to test this program to lint my files. I'm trying against a directory with just 4 PHP files.

docker run --rm -t -v /.../phpfiles:/workdir -v /logs/.phplint.cache:/.phplint.cache overtrue/phplint:8.2 ./ --exclude=somefolder --no-configuration --cache=/.phplint.cache --jobs=10 --warning

But I'm getting a crash:

+ '[' '!' -z  ]
+ sh -c '/root/.composer/vendor/bin/phplint ./ --exclude=somefolder --no-configuration --cache=/.phplint.cache --jobs=10 --warning'
phplint 6.0 by overtrue and contributors.

Runtime       : 8.2.0

PHP Notice:  file_get_contents(): Read of 12288 bytes failed with errno=21 Is a directory in /root/.composer/vendor/overtrue/phplint/src/Cache.php on line 13

Notice: file_get_contents(): Read of 12288 bytes failed with errno=21 Is a directory in /root/.composer/vendor/overtrue/phplint/src/Cache.php on line 13
PHP Fatal error:  Uncaught TypeError: Overtrue\PHPLint\Linter::setCache(): Argument #1 ($cache) must be of type array, null given, called in /root/.composer/vendor/overtrue/phplint/src/Command/LintCommand.php on line 170 and defined in /root/.composer/vendor/overtrue/phplint/src/Linter.php:90
Stack trace:
#0 /root/.composer/vendor/overtrue/phplint/src/Command/LintCommand.php(170): Overtrue\PHPLint\Linter->setCache(NULL)
#1 /root/.composer/vendor/symfony/console/Command/Command.php(312): Overtrue\PHPLint\Command\LintCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 /root/.composer/vendor/symfony/console/Application.php(1022): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /root/.composer/vendor/symfony/console/Application.php(314): Symfony\Component\Console\Application->doRunCommand(Object(Overtrue\PHPLint\Command\LintCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /root/.composer/vendor/symfony/console/Application.php(168): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /root/.composer/vendor/overtrue/phplint/bin/phplint(32): Symfony\Component\Console\Application->run()
#6 /root/.composer/vendor/bin/phplint(120): include('/root/.composer...')
#7 {main}
  thrown in /root/.composer/vendor/overtrue/phplint/src/Linter.php on line 90

Fatal error: Uncaught TypeError: Overtrue\PHPLint\Linter::setCache(): Argument #1 ($cache) must be of type array, null given, called in /root/.composer/vendor/overtrue/phplint/src/Command/LintCommand.php on line 170 and defined in /root/.composer/vendor/overtrue/phplint/src/Linter.php:90
Stack trace:
#0 /root/.composer/vendor/overtrue/phplint/src/Command/LintCommand.php(170): Overtrue\PHPLint\Linter->setCache(NULL)
#1 /root/.composer/vendor/symfony/console/Command/Command.php(312): Overtrue\PHPLint\Command\LintCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 /root/.composer/vendor/symfony/console/Application.php(1022): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /root/.composer/vendor/symfony/console/Application.php(314): Symfony\Component\Console\Application->doRunCommand(Object(Overtrue\PHPLint\Command\LintCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /root/.composer/vendor/symfony/console/Application.php(168): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /root/.composer/vendor/overtrue/phplint/bin/phplint(32): Symfony\Component\Console\Application->run()
#6 /root/.composer/vendor/bin/phplint(120): include('/root/.composer...')
#7 {main}
  thrown in /root/.composer/vendor/overtrue/phplint/src/Linter.php on line 90
llaville commented 1 year ago

Is there any reasonable reason why you don't use the latest version 9.0 ?

llaville commented 1 year ago

CAUTION : With previous versions 3.x, 4.x, 5.x or 6.x the cache option must specify a filename (default to .phplint-cache), while new latest version 9.0.x cache identify a directory (default to .phplint.cache)

ghnp5 commented 1 year ago

Oh, thanks. I just wanted to ensure phplint uses PHP 8.2. But based on what you said, the tags of the docker images don't correspond to PHP versions, is that it?

How do I know which PHP version is installed on 9.0.x ? I want to make sure that my files are linted based on PHP 8.2. Thanks!

Seems the lint worked now, but it used PHP 8.0.28 instead of PHP 8.2 :)

phplint 9.0.3 by overtrue and contributors.

Runtime       : PHP 8.0.28
Configuration : No config file loaded

....

Time: < 1 sec, Memory: 4.0 MiB, Cache: 0 hit, 4 misses

 [OK] 4 files
ghnp5 commented 1 year ago

For example, it gives me errors for all enums used, as they're only supported in PHP 8.1 :)

llaville commented 1 year ago

Oh, thanks. I just wanted to ensure phplint uses PHP 8.2. But based on what you said, the tags of the docker images don't correspond to PHP versions, is that it?

On legacy versions (3.x, 4.x, 5.x or .6.x) docker tag correspond to the GitHub branch of the repository. Branch main (default) is for new major version 9.0 and Docker tag is latest

How do I know which PHP version is installed on 9.0.x ?

The Runtime line identify latest PHP 8.0 used !

I want to make sure that my files are linted based on PHP 8.2.

Actually the Workflow that generate the docker image with tag latest use PHP 8.0, but we could use PHP 8.2 to be compatible with all PHP 8 versions !

ghnp5 commented 1 year ago

Thank you. Yeah, this was my first time using this, and I realized the Runtime line says what's the version, while I was typing my message above :)

I see the Dockerfile has 8.0 hardcoded there - https://github.com/overtrue/phplint/blob/main/Dockerfile

What I suggest is that you could generate a few Docker tags, one for each version, like:

:9.0-php8.2 :9.0-php8.1 :9.0-php8.0

And then we could choose which to use, depending on what we use for our application.

For now, I might go ahead and create my own local image (replicating your Dockerfile, changing the version to 8.2), but here's my suggestion anyway :)

Thanks very much!

llaville commented 1 year ago

Will add on my TODO list for tomorrow !

ghnp5 commented 1 year ago

Thank you very much for your the work on this project. Very appreciated :)

llaville commented 1 year ago

Workaround is to use the PHAR distribution that really depends of your platform (PHP runtime), until docker images are available !

llaville commented 1 year ago

@ghnp5 I'll close this report, because fix will be applied on issue 180.