Layer Cache - CI/CD用語集の定義
layer cacheは、入力が変わっていないcontainer buildのステップを再利用します。cache missは以降のすべてのレイヤーを無効化するため、Dockerfileの命令の順序がcacheの有効性を直接左右します。
layer cacheはcontainer buildの各命令の結果を保存し、変更されていないレイヤーをbuild間で再利用できるようにします。レイヤーはその命令や入力が変わったときにのみ再buildされ、それ以降のすべてのレイヤーも一緒に再buildされます。
layer cachingは高速なイメージbuildの主要なレバーであり、安定したステップを揮発性のステップより前に配置するとヒットが最大化します。
順序付けのルール
めったに変わらないステップ(システムパッケージのインストール、lockfileのコピーと依存関係のインストール)を、頻繁に変わるステップ(アプリケーションのソースのコピー)より前に配置します。そうすればソースの変更は最後の数レイヤーだけを無効化します。
CIでの位置づけ
エフェメラルなrunnerは空のlayer cacheで始まるため、pipelineはcacheをregistryにエクスポートするか、BuildKitのcacheバックエンドを使って実行間で引き継ぎます。
関連ガイド
Content-Addressable Cache - CI/CD Glossary DefinitionContent-Addressable Cache: A content-addressable cache stores each artifact under a key derived from a hash o…
Rootless BuildKit - CI/CD Glossary DefinitionRootless BuildKit: Rootless BuildKit is a mode of the BuildKit builder that constructs container images witho…
Pull-Through Registry Cache - CI/CD Glossary DefinitionPull-Through Registry Cache: A pull-through registry cache is a local registry mirror that fetches an image f…