我在我的 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安装的日志:
+ 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%)
更新:无法覆盖默认值
基于这个答案 https://stackoverflow.com/a/59542186/766570我试过这个:
- step:
caches:
- composer
image: totersapp/laravel-docker:phpredis
script:
- composer install
..
definitions:
caches:
composer: /composer/cache
我的问题是我试图用custom缓存目录(在本例中是/composer/cache
)但话又说回来,我没有办法在提供自定义缓存目录作为选项时调用composer安装命令(即,这就是bitbucket教程在本例中对bundle所做的事情:
- bundle install --path vendor/bundle
换句话说,我不能运行这样的东西:
- composer install --cache-directory /composer/cache
更新2:composer.json和composer.lock之间的差异
- 首先作为健全性检查,我只是cloned https://bitbucket.org/toters/composer-cache/src/master/的回购协议尼科
哈斯 https://stackoverflow.com/users/1116230/nico-haase,并运行管道,passed https://bitbucket.org/toters/composer-cache/addon/pipelines/home#!/results/3 ✅
- 我复制并粘贴了他的内容bitbucket-pipelines.yml https://bitbucket.org/toters/composer-cache/src/master/bitbucket-pipelines.yml到我的,我复制并粘贴了他的作曲家.json https://bitbucket.org/toters/composer-cache/src/master/composer.json,我运行了管道。失败❌
但我在作曲家安装日志中得到了这个:
+ 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%)
- 所以我认为这是因为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好像 https://bitbucket.org/snippets/toters/onrA6z,我保留了cache-dir
部分内容供参考)