Composer 安装后脚本未执行

Nik*_*Nik 2 composer-php

我正在尝试构建一个包含 PHP 应用程序的 docker 映像。

\n

该应用程序通过composer.json安装一些依赖项,并且在安装composer后,需要完成一些自定义(例如,必须将某些文件从供应商文件夹复制到其他位置等)。

\n

因此,我将这些步骤编写为 bash 命令,并将其放入composer.json post-install-cmd 部分中。

\n

这是我的composer.json(我省略了细节,但结构是相同的):

\n
{\n  "name": "MyApp",\n  "description": "My Service",\n  "type": "project",\n  "repositories": {\n    "a-fancy-library-i-depend-on": {\n      "type": "package",\n      "package": {\n        "name": "a-fancy-library-i-depend-on",\n        "version": "1.0",\n        "source": {\n          "url": "https://github.com/a-fancy-library-i-depend-on",\n          "type": "git",\n          "reference": "master"\n        }\n      }\n    },\n  },\n  "require": {\n    "symfony/filesystem": "5.2.6",\n    "symfony/yaml": "^4.2"\n  },\n  "require-dev": {\n    "a-fancy-library-i-depend-on": "*"\n  },\n  "scripts": {\n    "post-install-cmd": [\n      "rm -rf ./src/setup",\n      "cp -r vendor/a-fancy-library-i-depend-on/setup/ ./src/setup",\n      "mkdir vendor/a-fancy-library-i-depend-on/log"\n    ]\n  },\n  "autoload": {\n    "classmap": [\n      "src/"\n    ]\n  },\n  "config": {\n    "allow-plugins": {\n      "a-fancy-library-i-depend-on/composer-module-installer": true\n    }\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

在我的 Dockerfile 中,我包含了运行 Composer 安装的步骤:

\n
FROM php:7.4.20-fpm\n\nRUN apt-get update && apt-get install -y git zlib1g-dev libzip-dev libpng-dev libicu-dev g++ zip unzip\n\nRUN docker-php-ext-install zip gd intl\n\nRUN docker-php-ext-configure intl\n\nRUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer\n\nADD code /code\n\nWORKDIR /code\n\nRUN composer install\n
Run Code Online (Sandbox Code Playgroud)\n

问题是“安装后”脚本未执行。

\n

映像构建成功,但安装文件夹为空。

\n

如果我从此图像运行一个容器并在其上输入 bash

\n
 docker container run -ti my-image:local bash\n
Run Code Online (Sandbox Code Playgroud)\n

然后我尝试跑

\n
# composer install\n
Run Code Online (Sandbox Code Playgroud)\n

瞧\xc3\xa0!脚本被执行。

\n

这是构建映像命令的 Composer 安装阶段输出:

\n
Step 10/15 : RUN composer install\n ---> Running in af5ffb3ef4e9\nNo composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.\nLoading composer repositories with package information\nUpdating dependencies\nLock file operations: 76 installs, 0 updates, 0 removals\n  - Locking gettext/gettext (v4.8.6)\n  - Locking gettext/languages (2.9.0)\n  - Locking phpfastcache/riak-client (3.4.3)\n  - Locking phpmailer/phpmailer (v6.5.3)\n  - Locking psr/cache (1.0.1)\n  - Locking psr/container (1.1.2)\n  - Locking psr/event-dispatcher (1.0.0)\n  - Locking psr/log (1.1.4)\n  - Locking robrichards/xmlseclibs (3.1.1)\n  - Locking simplesamlphp/assert (v0.0.13)\n  - Locking simplesamlphp/composer-module-installer (v1.1.8)\n  - Locking simplesamlphp/saml2 (v4.4.0)\n  - Locking simplesamlphp/simplesamlphp (v1.19.4)\n  - Locking simplesamlphp/simplesamlphp-module-adfs (v0.9.9)\n  - Locking simplesamlphp/simplesamlphp-module-authcrypt (v0.9.4)\n  - Locking simplesamlphp/simplesamlphp-module-authfacebook (v0.9.3)\n  - Locking simplesamlphp/simplesamlphp-module-authorize (v0.9.4)\n  - Locking simplesamlphp/simplesamlphp-module-authtwitter (v0.9.3)\n  - Locking simplesamlphp/simplesamlphp-module-authwindowslive (v0.9.1)\n  - Locking simplesamlphp/simplesamlphp-module-authx509 (v0.9.9)\n  - Locking simplesamlphp/simplesamlphp-module-authyubikey (v0.9.3)\n  - Locking simplesamlphp/simplesamlphp-module-cas (v0.9.1)\n  - Locking simplesamlphp/simplesamlphp-module-cdc (v0.9.2)\n  - Locking simplesamlphp/simplesamlphp-module-consent (v0.9.8)\n  - Locking simplesamlphp/simplesamlphp-module-consentadmin (v0.9.2)\n  - Locking simplesamlphp/simplesamlphp-module-discopower (v0.10.1)\n  - Locking simplesamlphp/simplesamlphp-module-exampleattributeserver (v1.0.0)\n  - Locking simplesamlphp/simplesamlphp-module-expirycheck (v0.9.4)\n  - Locking simplesamlphp/simplesamlphp-module-ldap (v0.9.17)\n  - Locking simplesamlphp/simplesamlphp-module-memcachemonitor (v0.9.3)\n  - Locking simplesamlphp/simplesamlphp-module-memcookie (v1.2.2)\n  - Locking simplesamlphp/simplesamlphp-module-metarefresh (v0.9.7)\n  - Locking simplesamlphp/simplesamlphp-module-negotiate (v0.9.12)\n  - Locking simplesamlphp/simplesamlphp-module-oauth (v0.9.3)\n  - Locking simplesamlphp/simplesamlphp-module-preprodwarning (v0.9.3)\n  - Locking simplesamlphp/simplesamlphp-module-radius (v0.9.4)\n  - Locking simplesamlphp/simplesamlphp-module-riak (v0.9.1)\n  - Locking simplesamlphp/simplesamlphp-module-sanitycheck (v0.9.1)\n  - Locking simplesamlphp/simplesamlphp-module-smartattributes (v0.9.2)\n  - Locking simplesamlphp/simplesamlphp-module-sqlauth (v0.9.4)\n  - Locking simplesamlphp/simplesamlphp-module-statistics (v0.9.6)\n  - Locking simplesamlphp/twig-configurable-i18n (v2.3.4)\n  - Locking symfony/cache (v5.4.2)\n  - Locking symfony/cache-contracts (v2.5.0)\n  - Locking symfony/config (v5.4.2)\n  - Locking symfony/console (v5.4.2)\n  - Locking symfony/dependency-injection (v5.4.2)\n  - Locking symfony/deprecation-contracts (v2.5.0)\n  - Locking symfony/error-handler (v5.4.2)\n  - Locking symfony/event-dispatcher (v5.4.0)\n  - Locking symfony/event-dispatcher-contracts (v2.5.0)\n  - Locking symfony/filesystem (v5.2.6)\n  - Locking symfony/finder (v5.4.2)\n  - Locking symfony/framework-bundle (v5.4.2)\n  - Locking symfony/http-foundation (v5.4.2)\n  - Locking symfony/http-kernel (v5.4.2)\n  - Locking symfony/polyfill-ctype (v1.24.0)\n  - Locking symfony/polyfill-intl-grapheme (v1.24.0)\n  - Locking symfony/polyfill-intl-normalizer (v1.24.0)\n  - Locking symfony/polyfill-mbstring (v1.24.0)\n  - Locking symfony/polyfill-php72 (v1.24.0)\n  - Locking symfony/polyfill-php73 (v1.24.0)\n  - Locking symfony/polyfill-php80 (v1.24.0)\n  - Locking symfony/polyfill-php81 (v1.24.0)\n  - Locking symfony/routing (v5.4.0)\n  - Locking symfony/service-contracts (v2.5.0)\n  - Locking symfony/string (v5.4.2)\n  - Locking symfony/var-dumper (v5.4.2)\n  - Locking symfony/var-exporter (v5.4.2)\n  - Locking symfony/yaml (v4.4.36)\n  - Locking twig/extensions (v1.5.4)\n  - Locking twig/twig (v2.14.10)\n  - Locking webmozart/assert (1.10.0)\n  - Locking whitehat101/apr1-md5 (v1.0.0)\nWriting lock file\nInstalling dependencies from lock file (including require-dev)\nPackage operations: 76 installs, 0 updates, 0 removals\n  - Downloading symfony/polyfill-php72 (v1.24.0)\n  - Downloading symfony/polyfill-mbstring (v1.24.0)\n  - Downloading symfony/polyfill-ctype (v1.24.0)\n  - Downloading twig/twig (v2.14.10)\n  - Downloading symfony/yaml (v4.4.36)\n  - Downloading symfony/polyfill-php80 (v1.24.0)\n  - Downloading symfony/var-exporter (v5.4.2)\n  - Downloading symfony/deprecation-contracts (v2.5.0)\n  - Downloading symfony/routing (v5.4.0)\n  - Downloading symfony/polyfill-php73 (v1.24.0)\n  - Downloading symfony/http-foundation (v5.4.2)\n  - Downloading psr/event-dispatcher (1.0.0)\n  - Downloading symfony/event-dispatcher-contracts (v2.5.0)\n  - Downloading symfony/event-dispatcher (v5.4.0)\n  - Downloading symfony/var-dumper (v5.4.2)\n  - Downloading psr/log (1.1.4)\n  - Downloading symfony/error-handler (v5.4.2)\n  - Downloading symfony/http-kernel (v5.4.2)\n  - Downloading symfony/polyfill-php81 (v1.24.0)\n  - Downloading symfony/finder (v5.4.2)\n  - Downloading symfony/filesystem (v5.2.6)\n  - Downloading psr/container (1.1.2)\n  - Downloading symfony/service-contracts (v2.5.0)\n  - Downloading symfony/dependency-injection (v5.4.2)\n  - Downloading symfony/config (v5.4.2)\n  - Downloading psr/cache (1.0.1)\n  - Downloading symfony/cache-contracts (v2.5.0)\n  - Downloading symfony/cache (v5.4.2)\n  - Downloading symfony/framework-bundle (v5.4.2)\n  - Downloading symfony/polyfill-intl-normalizer (v1.24.0)\n  - Downloading symfony/polyfill-intl-grapheme (v1.24.0)\n  - Downloading symfony/string (v5.4.2)\n  - Downloading symfony/console (v5.4.2)\n  - Downloading twig/extensions (v1.5.4)\n  - Downloading simplesamlphp/twig-configurable-i18n (v2.3.4)\n  - Downloading simplesamlphp/simplesamlphp (v1.19.4)\n  - Downloading simplesamlphp/composer-module-installer (v1.1.8)\n  - Downloading gettext/languages (2.9.0)\n  - Downloading webmozart/assert (1.10.0)\n  - Downloading simplesamlphp/simplesamlphp-module-statistics (v0.9.6)\n  - Downloading simplesamlphp/simplesamlphp-module-sqlauth (v0.9.4)\n  - Downloading simplesamlphp/simplesamlphp-module-smartattributes (v0.9.2)\n  - Downloading simplesamlphp/simplesamlphp-module-sanitycheck (v0.9.1)\n  - Downloading phpfastcache/riak-client (3.4.3)\n  - Downloading simplesamlphp/simplesamlphp-module-riak (v0.9.1)\n  - Downloading simplesamlphp/simplesamlphp-module-radius (v0.9.4)\n  - Downloading simplesamlphp/simplesamlphp-module-preprodwarning (v0.9.3)\n  - Downloading simplesamlphp/simplesamlphp-module-oauth (v0.9.3)\n  - Downloading simplesamlphp/simplesamlphp-module-ldap (v0.9.17)\n  - Downloading simplesamlphp/simplesamlphp-module-negotiate (v0.9.12)\n  - Downloading simplesamlphp/simplesamlphp-module-metarefresh (v0.9.7)\n  - Downloading simplesamlphp/simplesamlphp-module-memcookie (v1.2.2)\n  - Downloading simplesamlphp/simplesamlphp-module-memcachemonitor (v0.9.3)\n  - Downloading simplesamlphp/simplesamlphp-module-expirycheck (v0.9.4)\n  - Downloading simplesamlphp/simplesamlphp-module-exampleattributeserver (v1.0.0)\n  - Downloading simplesamlphp/simplesamlphp-module-discopower (v0.10.1)\n  - Downloading simplesamlphp/simplesamlphp-module-consent (v0.9.8)\n  - Downloading simplesamlphp/simplesamlphp-module-consentadmin (v0.9.2)\n  - Downloading simplesamlphp/simplesamlphp-module-cdc (v0.9.2)\n  - Downloading simplesamlphp/simplesamlphp-module-cas (v0.9.1)\n  - Downloading simplesamlphp/simplesamlphp-module-authyubikey (v0.9.3)\n  - Downloading simplesamlphp/simplesamlphp-module-authx509 (v0.9.9)\n  - Downloading simplesamlphp/simplesamlphp-module-authwindowslive (v0.9.1)\n  - Downloading simplesamlphp/simplesamlphp-module-authtwitter (v0.9.3)\n  - Downloading simplesamlphp/simplesamlphp-module-authorize (v0.9.4)\n  - Downloading simplesamlphp/simplesamlphp-module-authfacebook (v0.9.3)\n  - Downloading whitehat101/apr1-md5 (v1.0.0)\n  - Downloading simplesamlphp/simplesamlphp-module-authcrypt (v0.9.4)\n  - Downloading simplesamlphp/simplesamlphp-module-adfs (v0.9.9)\n  - Downloading robrichards/xmlseclibs (3.1.1)\n  - Downloading simplesamlphp/saml2 (v4.4.0)\n  - Downloading simplesamlphp/assert (v0.0.13)\n  - Downloading phpmailer/phpmailer (v6.5.3)\n  - Downloading gettext/gettext (v4.8.6)\n  0/74 [>---------------------------]   0%\n  3/74 [=>--------------------------]   4%\n 12/74 [====>-----------------------]  16%\n 20/74 [=======>--------------------]  27%\n 27/74 [==========>-----------------]  36%\n 33/74 [============>---------------]  44%\n 37/74 [==============>-------------]  50%\n 39/74 [==============>-------------]  52%\n 43/74 [================>-----------]  58%\n 44/74 [================>-----------]  59%\n 47/74 [=================>----------]  63%\n 51/74 [===================>--------]  68%\n 54/74 [====================>-------]  72%\n 58/74 [=====================>------]  78%\n 62/74 [=======================>----]  83%\n 63/74 [=======================>----]  85%\n 67/74 [=========================>--]  90%\n 73/74 [===========================>]  98%\n 74/74 [============================] 100%\n  - Installing symfony/polyfill-php72 (v1.24.0): Extracting archive\n  - Installing symfony/polyfill-mbstring (v1.24.0): Extracting archive\n  - Installing symfony/polyfill-ctype (v1.24.0): Extracting archive\n  - Installing twig/twig (v2.14.10): Extracting archive\n  - Installing symfony/yaml (v4.4.36): Extracting archive\n  - Installing symfony/polyfill-php80 (v1.24.0): Extracting archive\n  - Installing symfony/var-exporter (v5.4.2): Extracting archive\n  - Installing symfony/deprecation-contracts (v2.5.0): Extracting archive\n  - Installing symfony/routing (v5.4.0): Extracting archive\n  - Installing symfony/polyfill-php73 (v1.24.0): Extracting archive\n  - Installing symfony/http-foundation (v5.4.2): Extracting archive\n  - Installing psr/event-dispatcher (1.0.0): Extracting archive\n  - Installing symfony/event-dispatcher-contracts (v2.5.0): Extracting archive\n  - Installing symfony/event-dispatcher (v5.4.0): Extracting archive\n  - Installing symfony/var-dumper (v5.4.2): Extracting archive\n  - Installing psr/log (1.1.4): Extracting archive\n  - Installing symfony/error-handler (v5.4.2): Extracting archive\n  - Installing symfony/http-kernel (v5.4.2): Extracting archive\n  - Installing symfony/polyfill-php81 (v1.24.0): Extracting archive\n  - Installing symfony/finder (v5.4.2): Extracting archive\n  - Installing symfony/filesystem (v5.2.6): Extracting archive\n  - Installing psr/container (1.1.2): Extracting archive\n  - Installing symfony/service-contracts (v2.5.0): Extracting archive\n  - Installing symfony/dependency-injection (v5.4.2): Extracting archive\n  - Installing symfony/config (v5.4.2): Extracting archive\n  - Installing psr/cache (1.0.1): Extracting archive\n  - Installing symfony/cache-contracts (v2.5.0): Extracting archive\n  - Installing symfony/cache (v5.4.2): Extracting archive\n  - Installing symfony/framework-bundle (v5.4.2): Extracting archive\n  - Installing symfony/polyfill-intl-normalizer (v1.24.0): Extracting archive\n  - Installing symfony/polyfill-intl-grapheme (v1.24.0): Extracting archive\n  - Installing symfony/string (v5.4.2): Extracting archive\n  - Installing symfony/console (v5.4.2): Extracting archive\n  - Installing twig/extensions (v1.5.4): Extracting archive\n  - Installing simplesamlphp/twig-configurable-i18n (v2.3.4): Extracting archive\n  - Installing simplesamlphp/simplesamlphp (v1.19.4): Extracting archive\n  0/36 [>---------------------------]   0%\n 10/36 [=======>--------------------]  27%\n 20/36 [===============>------------]  55%\n 30/36 [=======================>----]  83%\n 35/36 [===========================>]  97%\n 36/36 [============================] 100%\n  - Installing simplesamlphp/composer-module-installer (v1.1.8): Extracting archive\n  - Installing gettext/languages (2.9.0): Extracting archive\n  - Installing webmozart/assert (1.10.0): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-statistics (v0.9.6): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-sqlauth (v0.9.4): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-smartattributes (v0.9.2): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-sanitycheck (v0.9.1): Extracting archive\n  - Installing phpfastcache/riak-client (3.4.3): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-riak (v0.9.1): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-radius (v0.9.4): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-preprodwarning (v0.9.3): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-oauth (v0.9.3): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-ldap (v0.9.17): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-negotiate (v0.9.12): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-metarefresh (v0.9.7): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-memcookie (v1.2.2): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-memcachemonitor (v0.9.3): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-expirycheck (v0.9.4): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-exampleattributeserver (v1.0.0): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-discopower (v0.10.1): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-consent (v0.9.8): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-consentadmin (v0.9.2): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-cdc (v0.9.2): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-cas (v0.9.1): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-authyubikey (v0.9.3): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-authx509 (v0.9.9): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-authwindowslive (v0.9.1): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-authtwitter (v0.9.3): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-authorize (v0.9.4): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-authfacebook (v0.9.3): Extracting archive\n  - Installing whitehat101/apr1-md5 (v1.0.0): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-authcrypt (v0.9.4): Extracting archive\n  - Installing simplesamlphp/simplesamlphp-module-adfs (v0.9.9): Extracting archive\n  - Installing robrichards/xmlseclibs (3.1.1): Extracting archive\n  - Installing simplesamlphp/saml2 (v4.4.0): Extracting archive\n  - Installing simplesamlphp/assert (v0.0.13): Extracting archive\n  - Installing phpmailer/phpmailer (v6.5.3): Extracting archive\n  - Installing gettext/gettext (v4.8.6): Extracting archive\n  0/37 [>---------------------------]   0%\n 10/37 [=======>--------------------]  27%\n 20/37 [===============>------------]  54%\n 29/37 [=====================>------]  78%\n 37/37 [============================] 100%\n26 package suggestions were added by new dependencies, use `composer suggest` to see details.\nPackage simplesamlphp/simplesamlphp-module-authfacebook is abandoned, you should avoid using it. No replacement was suggested.\nPackage simplesamlphp/simplesamlphp-module-authwindowslive is abandoned, you should avoid using it. No replacement was suggested.\nPackage simplesamlphp/simplesamlphp-module-oauth is abandoned, you should avoid using it. No replacement was suggested.\nPackage simplesamlphp/simplesamlphp-module-riak is abandoned, you should avoid using it. No replacement was suggested.\nPackage twig/extensions is abandoned, you should avoid using it. No replacement was suggested.\nGenerating autoload files\n32 packages you are using are looking for funding.\nUse the `composer fund` command to find out more!\nRemoving intermediate container af5ffb3ef4e9\n\n
Run Code Online (Sandbox Code Playgroud)\n

我该如何调试这个问题?

\n

Nic*_*ase 6

请查看Composer 脚本的文档。它解释得非常明显:

post-install-cmd:在存在锁定文件的情况下执行安装命令后发生。

如果您使用的composer install锁定文件存在(如控制台输出所示),则不会触发此事件。