Skip to content

Latest commit

 

History

History
91 lines (74 loc) · 3.39 KB

File metadata and controls

91 lines (74 loc) · 3.39 KB

Cache

More info about cache on BuildKit and Buildx repositories.

Inline cache:

In most cases you want to use the type=inline cache exporter. However, note that the inline cache exporter only supports min cache mode. To enable max cache mode, push the image and the cache separately by using the registry cache exporter as shown in the next example.

"docker": {
  "executor": "@nx-tools/nx-docker:build",
  "options": {
    "push": true,
    "tags": ["user/app:latest"],
    "cache-from": ["type=registry,ref=user/app:latest"],
    "cache-to": ["type=inline"]
  }
}

Registry cache

You can import/export cache from a cache manifest or (special) image configuration on the registry with the type=registry cache exporter.

"docker": {
  "executor": "@nx-tools/nx-docker:build",
  "options": {
    "push": true,
    "tags": ["user/app:latest"],
    "cache-from": ["type=registry,ref=user/app:buildcache"],
    "cache-to": ["type=registry,ref=user/app:buildcache,mode=max"]
  }
}

GitHub cache

Cache backend API

🧪 This cache exporter is considered EXPERIMENTAL until further notice. Please provide feedback on BuildKit repository if you encounter any issues. Since buildx 0.6.0 and BuildKit 0.9.0, you can use the type=gha cache exporter.

GitHub Actions cache exporter backend uses the GitHub Cache API to fetch and upload cache blobs. That's why this type of cache should be exclusively used in a GitHub Action workflow as the url ($ACTIONS_CACHE_URL) and token ($ACTIONS_RUNTIME_TOKEN) attributes are populated when a workflow is started.

"docker": {
  "executor": "@nx-tools/nx-docker:build",
  "options": {
    "push": true,
    "tags": ["user/app:latest"],
    "cache-from": ["type=gha"],
    "cache-to": ["type=gha,mode=max"]
  }
}

Local cache

⚠️ At the moment caches are copied over the existing cache so it keeps growing. The Move cache step is used as a temporary fix (see moby/buildkit#1896).

You can also leverage GitHub cache using actions/cache and type=local cache exporter with this action:

"docker": {
  "executor": "@nx-tools/nx-docker:build",
  "options": {
    "push": true,
    "tags": ["user/app:latest"],
    "cache-from": ["type=local,src=/tmp/.buildx-cache"],
    "cache-to": ["type=local,dest=/tmp/.buildx-cache-new,mode=max"]
  }
}