question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Description

The cache can grow very quickly with large images, since old entries are not deleted.

Configuration

[...]

      - name: Cache Docker layers
        uses: actions/cache@v2
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-

[...]

      - name: Build
        uses: docker/build-push-action@v2
        with:
          push: false
          tags: ${{ steps.prepare.outputs.image }}
          platforms: ${{ env.DOCKER_PLATFORMS }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache
          context: .

[...]

Logs

logs_37.zip

My solution

Add a clean-cache configuration option that runs the following command before exporting the layers docker system prune -f --filter "until=5h".

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:18
  • Comments:29 (10 by maintainers)

github_iconTop GitHub Comments

18reactions
crazy-maxcommented, Dec 14, 2020

@MarcelCoding

The cache can grow very quickly with large images, since old entries are not deleted.

Yes you’re right atm caches are copied over the existing cache so it keeps growing. Can you open an issue on buildkit repo about that please? In the meantime you can do this:

[...]

      - name: Cache Docker layers
        uses: actions/cache@v2
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-

[...]

      - name: Build
        uses: docker/build-push-action@v2
        with:
          push: false
          tags: ${{ steps.prepare.outputs.image }}
          platforms: ${{ env.DOCKER_PLATFORMS }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache-new
          context: .

[...]

      - name: Move cache
        run:
          rm -rf /tmp/.buildx-cache
          mv /tmp/.buildx-cache-new /tmp/.buildx-cache

cc. @tonistiigi

12reactions
ksurlcommented, Jul 29, 2021

does this mean I can remove my step for local cache setup and just use:

      - name: Checkout repo
        uses: actions/checkout@v2
      
      - name: Prepare docker image name
        id: image_names
        run: |
          IMAGES="${GITHUB_REPOSITORY/docker-/},ghcr.io/${GITHUB_REPOSITORY/docker-/}"
          echo ::set-output name=images::${IMAGES}

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v3
        with:
          images: ${{ steps.image_names.outputs.images }}
          tags: |
            type=ref,event=tag

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1
        with:
          platforms: all

      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1

      #- name: Set up build cache
        #uses: actions/cache@v2
        #with:
          #path: /tmp/.buildx-cache
          #key: ${{ runner.os }}-buildx-${{ github.sha }}
          #restore-keys: |
            #${{ runner.os }}-buildx-

      - name: Login to GitHub
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GHCR_TOKEN }}

      - name: Login to DockerHub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_HUB_USERNAME }}
          password: ${{ secrets.DOCKER_HUB_TOKEN }}

      - name: Build image
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          context: ./
          file: ./Dockerfile
          builder: ${{ steps.buildx.outputs.name }}
          push: true
          platforms: linux/amd64,linux/arm/v7,linux/arm64
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          #cache-from: type=local,src=/tmp/.buildx-cache
          cache-from: type=gha, scope=${{ github.workflow }}
          cache-to: type=gha, scope=${{ github.workflow }}
          #cache-to: type=local,dest=/tmp/.buildx-cache
Read more comments on GitHub >

github_iconTop Results From Across the Web

Efficient cache for gigabytes of data written in Go | Hacker News
BigCache does not handle collisions. When new item is inserted and it's hash collides with previously stored item, new item overwrites ...
Read more >
Why does the FF cache become excessively large, and how ...
Firefox will create a large cache if your hard drive or SSD has a lot of space. To constrain it: (1) In a...
Read more >
Writing a very fast cache service with millions of entries in Go
The BigCache provides shards, eviction and it omits GC for cache entries. As a result it is very fast cache even for large...
Read more >
Caches Are Key to Scaling - Medium
For a very large data set, that could put a pretty big load on your database. Local — Remote Cache. One of the...
Read more >
Huge size folder under wp-content\cache\asset-cleanup
For my website wp-content\cache\asset-cleanup\js\ folder after latest updates became to grow quickly. Now its size is 11 GB/22043 inodes! Pretty big even to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found