Skip to content

Faster docker builds with S3-backed cache

RunsOn comes with an integrated S3 cache backend, which is what allows much faster and unlimited GitHub Actions caching with our drop-in Magic Cache feature.

This S3 cache backend can also be used directly with the type=s3 cache backend for Docker Buildx, to cache Docker layers. In my tests it appears to be faster than going through the type=gha backend, slightly slower than the Ephemeral Registry. But I recommend you try the different options and pick the one that works best for you.

Using the S3 cache for docker layer caching

Section titled “Using the S3 cache for docker layer caching”

Simply configure the S3 buildx cache backend and you’re good to go:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: "Build and push image"
uses: docker/build-push-action@v4
with:
context: "."
push: true
tags: <your-tag>
cache-from: type=s3,blobs_prefix=cache/${{ github.repository }}/,manifests_prefix=cache/${{ github.repository }}/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }}
cache-to: type=s3,blobs_prefix=cache/${{ github.repository }}/,manifests_prefix=cache/${{ github.repository }}/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }},mode=max

Authentication is handled automatically, as long as your GitHub Actions workflow is running on a RunsOn runner. Buildx will use the IAM role of the runner to access the S3 bucket.

Note that all RunsOn runners have the IAM role to access the S3 bucket. This means you can share layers across repositories and workflows within a single organization, but make sure you are ok with this.

If you require stronger isolation, you can configure multiple RunsOn stacks and use environments to isolate different workflows.