From 3e9ad64f68a1b4dae7ad60e8903919afec0e20a5 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Tue, 13 Jul 2021 17:18:59 +0200 Subject: [PATCH] Cache backend API example Signed-off-by: CrazyMax --- docs/advanced/cache.md | 49 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/docs/advanced/cache.md b/docs/advanced/cache.md index 0c0592ddd..2c47c3021 100644 --- a/docs/advanced/cache.md +++ b/docs/advanced/cache.md @@ -2,6 +2,8 @@ * [Registry cache](#registry-cache) * [GitHub cache](#github-cache) + * [Cache backend API (experimental)](#cache-backend-api-experimental) + * [Local cache](#local-cache) > More info about buildx cache: https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#cache-from @@ -46,13 +48,52 @@ jobs: ## GitHub cache +### Cache backend API (experimental) + +Since [buildx](https://github.com/docker/buildx) 0.6 and [BuildKit](https://github.com/moby/buildkit) 0.9 you can use +the new [`type=gha` cache exporter](https://github.com/moby/buildkit/tree/master#github-actions-cache-experimental): + +```yaml +name: ci + +on: + push: + branches: + - 'master' + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: user/app:latest + cache-from: type=gha + cache-to: type=gha +``` + +### Local cache + > :warning: At the moment caches are copied over the existing cache so it [keeps growing](https://github.com/docker/build-push-action/issues/252). > The `Move cache` step is used as a temporary fix (see https://github.com/moby/buildkit/issues/1896). -> :rocket: There is a new cache backend using GitHub cache being developed that will lighten your workflow. -> More info: https://github.com/docker/buildx/pull/535 - -You can leverage [GitHub cache](https://docs.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows) +You can also leverage [GitHub cache](https://docs.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows) using [actions/cache](https://github.com/actions/cache) with this action: ```yaml