cache icon indicating copy to clipboard operation
cache copied to clipboard

Docker caching

Open tuler opened this issue 5 years ago • 48 comments

Should we try to use this cache action to cache docker layers, doing trickery with docker save and docker load, or are you working on a different path for Docker caching?

tuler avatar Nov 01 '19 13:11 tuler

You're welcome to use this for caching docker layers! If you get something figured out we can add it as an example usage of this action.

are you working on a different path for Docker caching?

Nothing is in scope right now for v1 of this action that's specific to the Docker scenario, but it might already work.

Related: https://github.com/actions/toolkit/issues/197

joshmgross avatar Nov 01 '19 14:11 joshmgross

I think I can do something with ghaction-docker-buildx action and use the local --output.

crazy-max avatar Nov 01 '19 15:11 crazy-max

I tried but I hit the file limit, discussed at https://github.com/actions/cache/issues/6

tuler avatar Nov 01 '19 20:11 tuler

Since docker is now natively integrated in Github actions, I think it would be nice if there was an option to enable docker caching globally, like CircleCI does.

steebchen avatar Nov 02 '19 15:11 steebchen

@tuler also tried to cache with a tarball on https://github.com/actions/cache/issues/33. It seems to be a good solution.

https://github.com/actions/cache/pull/37 also was opened.

peaceiris avatar Nov 02 '19 23:11 peaceiris

Opened PR https://github.com/actions/cache/pull/37 with an example for Docker layer caching.

peter-evans avatar Nov 03 '19 00:11 peter-evans

@steebchen I agree. Docker caching should be natively supported, not through this action.

tuler avatar Nov 04 '19 00:11 tuler

cc: @neovintage

hamelsmu avatar Nov 04 '19 22:11 hamelsmu

The cache file limit has been increased from 400 MB to 2 GB, so this may be more viable than previously due to docker layers being larger than the previous limit.

joshmgross avatar Jan 06 '20 22:01 joshmgross

@steebchen I agree. Docker caching should be natively supported, not through this action.

Seems like a lot of people agree to that statement. Where is the proper place to post such a request? In the runner repo? Perhaps someone in the inner circle should post it as a feature request in the appropriate place and post a link here?

DannyBen avatar Jan 31 '20 12:01 DannyBen

@DannyBen See https://github.com/actions/cache/issues/81 where we're tracking Docker caching of actions

joshmgross avatar Jan 31 '20 15:01 joshmgross

Any update of the progress?

Sytten avatar Apr 14 '20 00:04 Sytten

+1

jimgreer avatar May 03 '20 22:05 jimgreer

👋 Hi all, right now we are focusing on other priorities and there are no updates for docker caching. We appreciate your feedback and revisit priorities based on user feedback, so please continue sending us your input.

joshmgross avatar May 05 '20 14:05 joshmgross

What's bothering me most is that all Github Actions (which are based on Docker) are always rebuild from scratch, in every single action. I've never worked in projects as big as GitHub, but I can't imagine how caching is not the solution here – just for the reason that it costs bandwidth to fetch the images each time. I'd also be happy to upgrade to a more expensive plan or pay for the cache storage costs.

(edit: I just realised I already commented in this thread... :smile:)

steebchen avatar May 05 '20 17:05 steebchen

Working example for me using buildx here: https://github.com/actions/cache/issues/260#issuecomment-638469605

crazy-max avatar Jun 03 '20 21:06 crazy-max

My ci processes use several pre-built docker images, some of them are very large - 3.5GB! github actions pulls these images again and again on every run burning a lot of time and cpu. A built in cache thats got a reasonable expiry behind each repo is really required here. Sooo much dealing with github actions seems to be spent working around paradigm/api failures or missing features. This is a big one, please give us some better options.

jeacott1 avatar Oct 28 '20 00:10 jeacott1

Hello, I am wondering if this issue has bubbled back up on the action/cache's priority list? I am wondering if there is a difficult technical challenge blocking this feature, as on its surface it seems like it would be a huge benefit to both users running actions and reduce load on GH infrastructure.

mikelax avatar Nov 25 '20 21:11 mikelax

@mikelax Would https://github.com/satackey/action-docker-layer-caching work for your case? It's built on top of this action.

dhadka avatar Nov 26 '20 16:11 dhadka

@mikelax Would https://github.com/satackey/action-docker-layer-caching work for your case? It's built on top of this action.

This linked action says it will use following method to take care of caching:

This GitHub Action uses the docker save / docker load command and the @actions/cache library.

While ago, @dtinth published an article Caching Docker builds in GitHub Actions: Which approach is the fastest? 🤔 A research. (https://dev.to/dtinth/caching-docker-builds-in-github-actions-which-approach-is-the-fastest-a-research-18ei). He found the docker save/load method is far from the best solution. Worth taking a look whether you are trying to cut some seconds.

piotrkubisa avatar Nov 26 '20 16:11 piotrkubisa

Hoping this bubbles up the priority list soon!

kaka-ruto avatar Feb 04 '21 13:02 kaka-ruto

Would love to see this built-in as well.

potatoqualitee avatar Jun 23 '21 10:06 potatoqualitee

I would also love to see a solution for this. I've had a few actions spend hundreds of billable minutes trying to pull docker images, and its costing a significant amount of money. I'd much rather have the docker layers cached.

But when I try to cache the docker folder, I get this warning. Warning: EACCES: permission denied, scandir '/var/lib/docker'

cdhanna avatar Oct 26 '21 17:10 cdhanna

Hi, I wrote the article mentioned above which has been outdated and superseded by another Evil Martians’ article.

TL;DR — Docker has published an official action docker/build-push-action which has an option to make Docker Buildx use GitHub Cache API directly as a cache storage, skipping the need to use a local-filesystem-based cache such as actions/cache entirely. With this settings my build time dropped from 5 minutes to 1 minute.

          cache-from: type=gha
          cache-to: type=gha,mode=max

dtinth avatar Oct 27 '21 05:10 dtinth

While the setup-buildx suggestion works when you're building your own docker images, AFAICT it doesn't work when you're using docker images as container services. It would be great if this was supported.

ErikSchierboom avatar Dec 03 '21 12:12 ErikSchierboom

The setup-buildx line of actions is also a beast to try to use if you have your test services and container under test setup through docker-compose. There is no obvious way to get the docker provided actions to work with the cache.

basicdays avatar Dec 09 '21 18:12 basicdays

Would love to see this feature as well in 2022 .

rahulbirari-cpi avatar Jan 21 '22 01:01 rahulbirari-cpi

Need this.

rojvv avatar Mar 25 '22 14:03 rojvv

Upvote

evencheng-invitae avatar Mar 29 '22 00:03 evencheng-invitae

The cache option on docker/build-push-action works great for building images.

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

jobs:
  build-and-upload-docker-image:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    permissions:
      contents: read
      packages: write
    outputs:
      docker-tag: ${{ steps.meta.outputs.tags }}

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

      - name: Log in to the Container registry
        uses: docker/login-action@v1
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@v3
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

      - name: Build and push
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          push: true
          file: Dockerfile.prod
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: |
            type=registry,ref=${{ steps.meta.outputs.tags }}
            type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:master
          cache-to: type=inline

However, I have a use case for running tests in a dockerized setup.

jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    needs: [build-and-upload-docker-image]

    steps:
    - uses: actions/checkout@v2

    - name: Log in to the Container registry
      uses: docker/login-action@v1
      with:
        registry: ${{ env.REGISTRY }}
        username: ${{ github.actor }}
        password: ${{ secrets.PACKAGE_ACCESS_TOKEN }}

    - name: Run tests
      run: docker-compose run web yarn test

Here every run pulls dependencies defined in docker-compose (e.g. postgres, redis, etc). Could caching of those be supported natively or by an action?

thisismydesign avatar Apr 13 '22 12:04 thisismydesign