Interview Prep/CI/CD/Build Tools and Artifact Repositories

What are Docker layer caching strategies in CI?

AdvancedConceptBuild Tools and Artifact Repositories
Answer

Fresh runners have empty Docker caches, so you must export and import the cache. With BuildKit: --cache-to/--cache-from type=registry,ref=...:buildcache,mode=max stores layers in a registry (works anywhere), type=gha uses the GitHub cache, and type=local uses a directory you cache yourself. Order the Dockerfile so rarely changing layers (dependency manifests and install) come before frequently changing ones (source copy).

docker buildx build \
  --cache-from type=registry,ref=registry.example.com/api:buildcache \
  --cache-to type=registry,ref=registry.example.com/api:buildcache,mode=max \
  -t registry.example.com/api:$GIT_SHA --push .
All CI/CD questions Roadmap: CI/CD fundamentals

More on Build Tools and Artifact Repositories