2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gitlab-runnerでキャッシュが消されてしまう(ような気がした)

Last updated at Posted at 2019-12-13

やろうとしたこと

gitlab-runnerで、毎回composer installをする無駄なインターネットトラフィックが許せなかったので、ジョブとかパイプラインをまたいで永続的にキャッシュしたかった。
composer updateのタイミングでキャッシュを消せば良いので、永続化しても問題はなさそう。

環境

オンプレサーバのdocker-composeで、gitlab/gitlab-ce:latestgitlab/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.pharRemovingされてしまっている????

勘違いポイント

3時間ぐらいネットの海をさまよっていると、同じような出力が載っているissueがあった。悩みポイントは自分のと違うっぽかったけど、git cleanという文字列で気が付いてしまった。

原因

このRemovinggit 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に貼る作業に戻ります……

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?