Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GHA cache doesn't work when building multiple images #497

Closed
princemaple opened this issue Nov 12, 2021 · 10 comments
Closed

GHA cache doesn't work when building multiple images #497

princemaple opened this issue Nov 12, 2021 · 10 comments

Comments

@princemaple
Copy link

princemaple commented Nov 12, 2021

Is this by design and what is the recommended way of using it?

If it's a bug, please confirm. Thanks!

Looks like it's been confirmed as a bug.

# ...

  build:
    if: ${{ github.ref == 'refs/heads/main' }}
    runs-on: ubuntu-latest
    needs: test
    steps:
      - uses: actions/checkout@v2

      - uses: docker/setup-buildx-action@v1

      - name: Login to DockerHub
        uses: docker/login-action@v1
        with:
          registry: my-own-registry
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Build and push App
        uses: docker/build-push-action@v2
        with:
          push: true
          tags: my-own-registry/my-app:latest
          cache-from: type=gha
          cache-to: type=gha,mode=max

^ This takes 28s to finish after the first run

The following takes 4 minutes every single run. And the second app is actually simpler, so it shouldn't have taken much longer.

The truth is the cache is not used at all.

# ...

  build:
    if: ${{ github.ref == 'refs/heads/main' }}
    runs-on: ubuntu-latest
    needs: test
    steps:
      - uses: actions/checkout@v2

      - uses: docker/setup-buildx-action@v1

      - name: Login to DockerHub
        uses: docker/login-action@v1
        with:
          registry: my-own-registry
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Build and push App
        uses: docker/build-push-action@v2
        with:
          push: true
          tags: my-own-registry/my-app:latest
          cache-from: type=gha
          cache-to: type=gha,mode=max

      - name: Build and push App 2
        uses: docker/build-push-action@v2
        with:
          push: true
          tags: my-own-registry/my-other-app:latest
          cache-from: type=gha
          cache-to: type=gha,mode=max
@princemaple
Copy link
Author

princemaple commented Nov 12, 2021

I tried separating them into 2 jobs and the short job seems to break the cache for the longer job. So the whole action can only have one image cache?

My current workaround is remove caching for the shorter job. So I can have the time saving on the significantly longer job.

@princemaple princemaple changed the title GHA cache doesn't work when building multiple images in single job GHA cache doesn't work when building multiple images Nov 12, 2021
@qdev0
Copy link

qdev0 commented Nov 18, 2021

Deleting .dockerignore solved this for now. issue might be on my side.

This started happening to me today. last working build was able to load all build context but now it doesn't load all.

failing build context load:

#6 [internal] load build context
#6 transferring context: 560.45kB 0.0s done
#6 DONE 0.0s

working build context load:

#6 [internal] load build context
#6 transferring context: 46.94MB 1.7s done
#6 DONE 1.7s

this issue started happening since commit #9ed5823618d7aa277d31c9106594ecb63692bef4

I currently cannot push my images to dockerhub. I did not even change any content of code related to build

@mikhail-vl
Copy link

@quanton-dev, was you able to solve it? I have the same issue and it stopped working 7 days ago when the commit was made.

@crazy-max, any ideas why load build context is smaller than before?

@qdev0
Copy link

qdev0 commented Nov 23, 2021

I changed my I first deleted my .dockerignore and it works again and after that I configured my .dockerignore from this:

# Files in the root directory
**
!.git
!composer.*
!src
!bin
!config
!resources/locale/compiled
!util/docker/web
!util/openapi.php
!web
!templates
!plugins
!crowdin.yaml
!docker-compose.sample.yml
!sample.env

to this:

.devcontainer
.github
.run
frontend/node_modules
vendor

and works like normal. I had to do some research but couldnot find any kind of reason why it would change how it reads .dockerignore file. You might want to check your .dockerignore first. or is it related to this project? I don't know.

@mikhailredis as I can see in your mentioned issue repository you have similar .dockerignore might be related?

@mikhail-vl
Copy link

@quanton-dev, Thank you for the response. I have a very similar .dockerignore file with ignore everything and then exceptions.

@mikhail-vl
Copy link

@crazy-max, any ideas how .dockerignore may start affecting context in the latest version?

@crazy-max
Copy link
Member

crazy-max commented Nov 25, 2021

Yes this is a known issue with buildx 0.7.0. See docker/buildx#850 (comment) as a workaround in the meantime.

@mikhail-vl
Copy link

@crazy-max, thank you. I updated the .dockerignore file content already to fix the build.

I hope it's going to be fixes in the future versions.

@crazy-max
Copy link
Member

@mikhailredis Yes will be fixed with buildx 0.7.1 (docker/buildx#858).

@sjsakib
Copy link

sjsakib commented Jan 1, 2024

Hello, I am using build-push-action@v5 with setup-buildx-action@v3 and still facing this issue. Only one of the image would get cache hit.
Removing the .dockerignore didn't work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants