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.

Cache does not seem to be used

See original GitHub issue

Behaviour

Hi ! Thank you for your great peace of work here !

It looks like the cache feature is not used during docker build.

Or I may have misunderstood something ! 🤷‍♂️ (I’ve never used buildx yet, only Buildkit but without thinking about the caching part).

Thank you for your help !

Expected behaviour

I think Golang and Alpine images should almost always be retrieved by cache

Regarding the setup-buildx action, it would be great to use caching too so that we don’t loose around 13s on every action trigger

Actual behaviour

At this time it is not

Cache works well if I relaunch the action without making any changes

Configuration

name: ci
on: [pull_request,release]
jobs:
  docker-build-and-push:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout repository
        uses: actions/checkout@v2
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      -
        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: Login to Azure Container Registry
        uses: docker/login-action@v1
        with:
          registry: ${{ secrets.CONTAINER_REGISTRY_NAME }}
          username: ${{ secrets.CONTAINER_REGISTRY_USERNAME }}
          password: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
      -
        name: Build and push docker image
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          context: .
          push: true
          tags: ${{ secrets.CONTAINER_REGISTRY_NAME }}/${{ github.event.repository.name }}:${{ github.head_ref }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache

here is the Dockerfile:

FROM golang:1.15-alpine AS builder
WORKDIR /project
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o backend-ads-api ./cmd/...

FROM alpine:3.12
COPY --from=builder /project/backend-ads-api .
ENTRYPOINT ["/backend-ads-api"]

and the .dockerignore if it helps:

.git
.gitignore
.dockerignore
.github

.idea

Dockerfile

*test.go
README.md
LICENSE

Logs

logs_42.zip

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
crazy-maxcommented, Oct 9, 2020

@rmasclef

So why using buildx/buildkit when a “basic” docker **build** allows base image caching ?

Can you open an issue on buildkit repo? WDYT @tonistiigi?

Well, in our case, we are on a Github Team plan so we have 3000 minutes available every month. And as we have about 30 projects, every gained build second is clearly welcome don’t you think ?

This is perfectly understandable. Perhaps there is some room for caching the moby/buildkit image. Can you open an issue on setup-buildx repo about that? Thanks.

1reaction
rmasclefcommented, Oct 6, 2020

thank you for your answers 👍

Upstream so yeah for buildx/builkit.

So why using buildx/buildkit when a “basic” docker **build** allows base image caching ?

I don’t see how we could optimize this action even better and I don’t think that 13s vs 5s really makes much difference 😅

Well, in our case, we are on a Github Team plan so we have 3000 minutes available every month. And as we have about 30 projects, every gained build second is clearly welcome don’t you think ?

I know that, most of the time, we can optimize build time by optimizing the Dockerfile, but I don’t think I can optimize more in the case of a Go project though I’m really welcome to get advises on what I’ve done so far ! 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Do I Fix My Caching Problems Or Clear Web ...
How to clear the cache in commonly used browsers · Open your browser and and got to Tools > Safety menu. · Click...
Read more >
Github Actions restored cache is not being used
The node_modules seems to be cached but then the next job immediately fails due to missing dependencies. I ended up using this GitHub...
Read more >
[Cache] Somehow it doesn't seem to hit the cache #4166
However, the cache files seem to be generated properly, and it's likely that the cache was not hit or used properly.
Read more >
Help! I Don't See My Changes! - Clear the Cache
If you don't see your changes after updating your website, you may need to refresh by clearing your cache. Press Ctrl + F5...
Read more >
Isn't caching
Error on dynamic page: Seem that your website is not behind Cloudflare. If you have recently enabled the cache or it is your...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found