Skip to content

Commit 38c0121

Browse files
committed
docs: Add details and examples for remote cache with Builder Instances
1 parent 7433e00 commit 38c0121

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

docs/examples.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,41 @@ steps:
381381
**To keep the daemon or state, use the `keep-daemon` or `keep-state` parameters.**
382382
**These parameter are only applicable with specific Drivers, for detail see [`docker buildx rm`](https://docs.docker.com/reference/cli/docker/buildx/rm/).**
383383

384+
### Reusing caches from remote regestries
385+
386+
A newly spawned agent won't contain any of the docker caches for the first run which will result in a long build step. To mitigate this you can reuse caches from a remote registry, but requires pushing cache and manifests to a registry using a Builder Driver that supports cache exports e.g., `docker-container` - the `docker` driver does not support this by default. This requires use of the `cache-from`, `cache-to`, `name` and `use` parameters but will use the `create` and `driver` parameters to create the Builder Instance across multiple Agents:
387+
388+
```yaml
389+
steps:
390+
- label: ":docker: Build an image and push cache"
391+
plugins:
392+
- docker-compose#v5.4.1:
393+
build: app
394+
push: app:${DOCKER_REGISTRY}/${IMAGE_REPO}:cache
395+
cache-from:
396+
- type=registry,ref=${DOCKER_REGISTRY}/${IMAGE_REPO}:cache
397+
cache-to:
398+
- type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=${DOCKER_REGISTRY}/${IMAGE_REPO}:cache
399+
driver:
400+
name: container
401+
use: true
402+
create: true
403+
driver: docker-container
404+
- wait
405+
406+
- label: ":docker: Build an image using remote cache"
407+
plugins:
408+
- docker-compose#v5.4.1:
409+
build: app
410+
cache-from:
411+
- type=registry,ref=${DOCKER_REGISTRY}/${IMAGE_REPO}:cache
412+
driver:
413+
name: container
414+
use: true
415+
create: true
416+
driver: docker-container
417+
```
418+
419+
The first Step will build the Image using a Builder Instance with the `docker-container` driver and push the image cache to the remote registry, as specified by `cache-to`, with additional cache export options being used to export all the layers of intermediate steps with the image manifests. More details cache export options [here](https://github.com/moby/buildkit?tab=readme-ov-file#registry-push-image-and-cache-separately).
420+
421+
The second Step will build the Image using a Builder Instance with the `docker-container` driver and use remote registry for the image cache, as specified by `cache-from`, speeding up Image building process.

0 commit comments

Comments
 (0)