Composer post-未执行安装脚本

Composer post-install scripts not executed

我正在尝试构建一个 docker 图像,其中包含 PHP 应用程序。

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

所以我将这些步骤写成 bash 命令并放在 composer.json post-install-cmd 部分。

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

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

在我的 Dockerfile 中,我包含了 运行ning composer install 的步骤:

FROM php:7.4.20-fpm

RUN apt-get update && apt-get install -y git zlib1g-dev libzip-dev libpng-dev libicu-dev g++ zip unzip

RUN docker-php-ext-install zip gd intl

RUN docker-php-ext-configure intl

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

ADD code /code

WORKDIR /code

RUN composer install

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

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

如果我运行一个来自这个图像的容器并在上面输入一个bash

 docker container run -ti my-image:local bash

然后我尝试 运行

# composer install

瞧!脚本被执行。

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

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

如何调试这个问题?

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

post-install-cmd: occurs after the install command has been executed with a lock file present.

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