作曲家缓存不适用于 bitbucket 管道构建
composer cache not working on bitbucket pipeline build
我在我的 bitbucket 管道中得到了这个:
pipelines:
branches:
develop:
- step:
caches:
- composer
name: unit tests - Delivery
image: totersapp/laravel-docker:phpredis
script:
- echo "memory_limit=512M" > /usr/local/etc/php/conf.d/memory-limit-php.ini
- ln -f -s .env.pipelines .env
- composer install
services:
- postgres
- redis
每次 运行 它都在下载相同的文件(即使是在第二个 运行)。有什么想法吗?
这是作曲家安装的日志:
+ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 199 installs, 0 updates, 0 removals
- Installing kylekatarnls/update-helper (1.2.0): Downloading (connecting...)Downloading (0%) Downloading (100%)
- Installing ocramius/package-versions (1.4.2): Downloading (connecting...)Downloading (0%) Downloading (30%)Downloading (35%)Downloading (65%)Downloading (95%)Downloading (100%)
- Installing symfony/polyfill-ctype (v1.13.1): Downloading (connecting...)Downloading (0%) Downloading (100%)
更新:无法覆盖默认值
基于 我试过这个:
- step:
caches:
- composer
image: totersapp/laravel-docker:phpredis
script:
- composer install
..
definitions:
caches:
composer: /composer/cache
我的问题是我试图用 custom 缓存目录(在本例中是 /composer/cache
)调用 composer,但我又没有一种在提供自定义缓存目录作为选项的同时调用 composer install 命令的方法(即本例中 bitbucket 教程对 bundle 所做的操作:
- bundle install --path vendor/bundle
换句话说,我不能运行这样的事情:
- composer install --cache-directory /composer/cache
更新 2:composer.json 和 composer.lock
之间的差异
- 首先作为完整性检查,我只是 cloned Nico 的 repo
Haase,和 运行 管道,passed ✅
- 我复制粘贴了他bitbucket-pipelines.yml into mine, and I copied and pasted his composer.json的内容,我运行管道。失败 ❌
但我在 composer 安装日志中得到了这个:
+ composer install --ignore-platform-reqs --no-scripts
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Package operations: 199 installs, 0 updates, 0 removals
- Installing kylekatarnls/update-helper (1.2.0): Downloading (connecting...)Downloading (0%) Downloading (100%)
- Installing ocramius/package-versions (1.4.2): Downloading (connecting...)Downloading (0%) Downloading (30%)Downloading (35%)Downloading (65%)Downloading (95%)Downloading (100%)
- Installing symfony/polyfill-ctype (v1.13.1): Downloading (connecting...)Downloading (0%) Downloading (100%)
- 所以我认为是 b/c composer.lock 文件与 composer.json 不同步,所以我将
composer update
添加到我的管道中。这是从缓存中加载的! ✅但在这里失败了❌:
composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 108 installs, 0 updates, 0 removals
- Installing ocramius/package-versions (1.4.2): Downloading (connecting...)Downloading (0%) Downloading (30%)Downloading (35%)Downloading (65%)Downloading (80%)Downloading (100%)
- Installing symfony/flex (v1.6.0): Downloading (connecting...)Downloading (100%)
Symfony operations: 1 recipe (4c6f09f5995a77b64f54dd80675d3bfe)
- Configuring symfony/flex (>=1.0): From github.com/symfony/recipes:master
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "5.0.*"
Prefetching 106 packages
- Downloading (0%) (5%) (10%) (16%) (21%) (31%) (36%) (41%) (47%) (52%) (57%) (65%) (70%) (75%) (80%) (85%) (90%) (95%) (100%)
Package operations: 106 installs, 0 updates, 0 removals
- Installing psr/container (1.0.0): Loading from cache
- Installing symfony/service-contracts (v2.0.1): Loading from cache
..
..
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 1
!! Fatal Error: composer.lock was created for PHP version 7.2.9 or higher but the current PHP version is 7.1.32.
注意:在我原来的 composer.json 文件中,我找到了这一行
"config": {
..
"cache-dir": "~/.cache/composer",
},
所以我删除了那行,但这也没有帮助。
仍在挖掘(为了记录这是我的 composer.json looks like,我保留了 cache-dir
部分以供参考)
根据a question on the Bitbucket forums, this can happen if the docker image you are using is putting the downloaded files in a unusual position. According to the documentation about caches, the usual directory that is cached is ~/.composer/cache
, while the docker file of the image使用/composer
。
请尝试使用以下配置。它包含一个自定义缓存(需要自定义名称!),将自定义的作曲家文件夹放入缓存中:
pipelines:
branches:
develop:
- step:
caches:
- composer-custom
definitions:
caches:
composer-custom: /composer/cache
正如您在 https://bitbucket.org/haasenico/composer-cache/addon/pipelines/home#!/results/4 上看到的那样,缓存已被使用并且似乎适用于我的简短示例
为了完成这项工作,我基本上遵循了 Nico Haase 的 ,但我还必须执行以下操作:
- 从我的 composer.json
中删除 "cache-dir": "~/.cache/composer"
- 确保保存的缓存文件与composer.json中发生的任何事情同步..你不能要求composer.json加载依赖项包含不相关内容的缓存文件。为此,我只是删除了所有缓存文件并重新开始,这次成功了!
我在我的 bitbucket 管道中得到了这个:
pipelines:
branches:
develop:
- step:
caches:
- composer
name: unit tests - Delivery
image: totersapp/laravel-docker:phpredis
script:
- echo "memory_limit=512M" > /usr/local/etc/php/conf.d/memory-limit-php.ini
- ln -f -s .env.pipelines .env
- composer install
services:
- postgres
- redis
每次 运行 它都在下载相同的文件(即使是在第二个 运行)。有什么想法吗?
这是作曲家安装的日志:
+ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 199 installs, 0 updates, 0 removals
- Installing kylekatarnls/update-helper (1.2.0): Downloading (connecting...)Downloading (0%) Downloading (100%)
- Installing ocramius/package-versions (1.4.2): Downloading (connecting...)Downloading (0%) Downloading (30%)Downloading (35%)Downloading (65%)Downloading (95%)Downloading (100%)
- Installing symfony/polyfill-ctype (v1.13.1): Downloading (connecting...)Downloading (0%) Downloading (100%)
更新:无法覆盖默认值
基于
- step:
caches:
- composer
image: totersapp/laravel-docker:phpredis
script:
- composer install
..
definitions:
caches:
composer: /composer/cache
我的问题是我试图用 custom 缓存目录(在本例中是 /composer/cache
)调用 composer,但我又没有一种在提供自定义缓存目录作为选项的同时调用 composer install 命令的方法(即本例中 bitbucket 教程对 bundle 所做的操作:
- bundle install --path vendor/bundle
换句话说,我不能运行这样的事情:
- composer install --cache-directory /composer/cache
更新 2:composer.json 和 composer.lock
之间的差异- 首先作为完整性检查,我只是 cloned Nico 的 repo Haase,和 运行 管道,passed ✅
- 我复制粘贴了他bitbucket-pipelines.yml into mine, and I copied and pasted his composer.json的内容,我运行管道。失败 ❌
但我在 composer 安装日志中得到了这个:
+ composer install --ignore-platform-reqs --no-scripts
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Package operations: 199 installs, 0 updates, 0 removals
- Installing kylekatarnls/update-helper (1.2.0): Downloading (connecting...)Downloading (0%) Downloading (100%)
- Installing ocramius/package-versions (1.4.2): Downloading (connecting...)Downloading (0%) Downloading (30%)Downloading (35%)Downloading (65%)Downloading (95%)Downloading (100%)
- Installing symfony/polyfill-ctype (v1.13.1): Downloading (connecting...)Downloading (0%) Downloading (100%)
- 所以我认为是 b/c composer.lock 文件与 composer.json 不同步,所以我将
composer update
添加到我的管道中。这是从缓存中加载的! ✅但在这里失败了❌:
composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 108 installs, 0 updates, 0 removals
- Installing ocramius/package-versions (1.4.2): Downloading (connecting...)Downloading (0%) Downloading (30%)Downloading (35%)Downloading (65%)Downloading (80%)Downloading (100%)
- Installing symfony/flex (v1.6.0): Downloading (connecting...)Downloading (100%)
Symfony operations: 1 recipe (4c6f09f5995a77b64f54dd80675d3bfe)
- Configuring symfony/flex (>=1.0): From github.com/symfony/recipes:master
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "5.0.*"
Prefetching 106 packages
- Downloading (0%) (5%) (10%) (16%) (21%) (31%) (36%) (41%) (47%) (52%) (57%) (65%) (70%) (75%) (80%) (85%) (90%) (95%) (100%)
Package operations: 106 installs, 0 updates, 0 removals
- Installing psr/container (1.0.0): Loading from cache
- Installing symfony/service-contracts (v2.0.1): Loading from cache
..
..
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 1
!! Fatal Error: composer.lock was created for PHP version 7.2.9 or higher but the current PHP version is 7.1.32.
注意:在我原来的 composer.json 文件中,我找到了这一行
"config": {
..
"cache-dir": "~/.cache/composer",
},
所以我删除了那行,但这也没有帮助。
仍在挖掘(为了记录这是我的 composer.json looks like,我保留了 cache-dir
部分以供参考)
根据a question on the Bitbucket forums, this can happen if the docker image you are using is putting the downloaded files in a unusual position. According to the documentation about caches, the usual directory that is cached is ~/.composer/cache
, while the docker file of the image使用/composer
。
请尝试使用以下配置。它包含一个自定义缓存(需要自定义名称!),将自定义的作曲家文件夹放入缓存中:
pipelines:
branches:
develop:
- step:
caches:
- composer-custom
definitions:
caches:
composer-custom: /composer/cache
正如您在 https://bitbucket.org/haasenico/composer-cache/addon/pipelines/home#!/results/4 上看到的那样,缓存已被使用并且似乎适用于我的简短示例
为了完成这项工作,我基本上遵循了 Nico Haase 的
- 从我的 composer.json 中删除
- 确保保存的缓存文件与composer.json中发生的任何事情同步..你不能要求composer.json加载依赖项包含不相关内容的缓存文件。为此,我只是删除了所有缓存文件并重新开始,这次成功了!
"cache-dir": "~/.cache/composer"