やろうとしたこと
gitlab-runnerで、毎回composer install
をする無駄なインターネットトラフィックが許せなかったので、ジョブとかパイプラインをまたいで永続的にキャッシュしたかった。
composer update
のタイミングでキャッシュを消せば良いので、永続化しても問題はなさそう。
環境
オンプレサーバのdocker-composeで、gitlab/gitlab-ce:latest
とgitlab/gitlab-runner:latest
を走らせている。
ハマりポイント
とりあえずCI/CDがちゃんと動くか試すか~と思って、実装途中のリポジトリでまだ失敗する状態で書いて試した(phpunit.xml
をまだ作ってない。)。
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/repository/.git/
From http://sealed.example.com
* [new ref] refs/pipelines/31 -> refs/pipelines/31
fd6b04b..138134d master -> origin/master
Checking out 138134d2 as master...
Removing composer.phar
Removing vendor/
Skipping Git submodules setup
Checking cache for cache-composer...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Successfully extracted cache
$ curl -sS https://getcomposer.org/download/${COMPOSER_VERSION}/composer.phar > composer.phar
$ php composer.phar -qn --prefer-dist install
$ vendor/bin/phpunit --configuration phpunit.xml
Could not read "phpunit.xml".
ERROR: Job failed: exit code 1
すると、キャッシュされるはずのvendor/
とcomposer.phar
がRemoving
されてしまっている????
勘違いポイント
3時間ぐらいネットの海をさまよっていると、同じような出力が載っているissueがあった。悩みポイントは自分のと違うっぽかったけど、git clean
という文字列で気が付いてしまった。
原因
このRemoving
はgit clean
が追跡対象外のファイルを消しているだけで、gitlab-runnerのキャッシュとは全く関係が無い。
テスト成功時のログを見てもわかるように、キャッシュが行われるタイミングはテストが成功した後なので、テストが失敗している限りキャッシュは行われない。
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/repository/.git/
From http://sealed.example.com
* [new ref] refs/pipelines/31 -> refs/pipelines/31
fd6b04b..138134d master -> origin/master
Checking out 138134d2 as master...
Removing composer.phar
Removing vendor/
Skipping Git submodules setup
Checking cache for cache-composer...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Successfully extracted cache
$ curl -sS https://getcomposer.org/download/${COMPOSER_VERSION}/composer.phar > composer.phar
$ php composer.phar -qn --prefer-dist install
$ php -v
PHP 7.2.24 (cli) (built: Oct 25 2019 05:17:56) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.8.0, Copyright (c) 2002-2019, by Derick Rethans
Creating cache cache-composer...
vendor/: found 5081 matching files
composer.phar: found 1 matching files
untracked: found 4278 files
No URL provided, cache will be not uploaded to shared cache server. Cache will be stored only locally.
Created cache
Job succeeded
生意気にもナウでヤングなCI/CD環境!とか調子に乗ってた罰ですかね、大人しく手動でテストして画面のハードコピーを証憑.xlsに貼る作業に戻ります……