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.

Random LABEL snp-multi-stage-id invalidates docker cache

See original GitHub issue

Expected behaviour

I’m currently writing second post about docker cache efficiency on SBT. My main focus is to use docker cache in CI environments as much as possible. Already managed great improvements but there is problem with random generated Labels.

LABEL snp-multi-stage="intermediate"
LABEL snp-multi-stage-id="44857d33-aef2-4d80-b811-7d1ed9b1891d"

Executing second command always invalidates cache which is not always expected. Especially when dockerAutoremoveMultiStageIntermediateImages := false is used. I suggest to use something deterministic like stage0-(packageName in Docker).value

Actual behaviour

Step 1/20 : FROM repo.mycompany.com/team/openjre:8u242 as stage0
[info]  ---> a020ce624573
[info] Step 2/20 : LABEL snp-multi-stage="intermediate"
[info]  ---> Using cache
[info]  ---> 9abeed0b5a9f
[info] Step 3/20 : LABEL snp-multi-stage-id="44857d33-aef2-4d80-b811-7d1ed9b1891d"
[info]  ---> Running in 072dfdce55ad
[info] Removing intermediate container 072dfdce55ad
[info]  ---> 554d25368747
[info] Step 4/20 : WORKDIR /opt/my-app
[info]  ---> Running in 49f3e275dc8c

As you can see cache works with the first label, but gets invalidated after second, random label. @mkurz What do you think about deterministic label?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
an-texcommented, Aug 17, 2021

If you can live without those labels, it’s possible to simply remove then as a workaround

dockerCommands := dockerCommands.value.filter {
  case Cmd("LABEL", args @ _*) => args.head.startsWith("snp-multi-stage")
  case _                       => true
}

Thanks for the workaround! There’s just a negation missing, it should be: case Cmd("LABEL", args @ _*) => !args.head.startsWith("snp-multi-stage")

In general I believe a deterministic id should be the default. More users are concerned with a fast build compared to ones inspecting their failed builds.

1reaction
stoievcommented, Aug 13, 2020

If you can live without those labels, it’s possible to simply remove then as a workaround

dockerCommands := dockerCommands.value.filter {
  case Cmd("LABEL", args @ _*) => args.head.startsWith("snp-multi-stage")
  case _                       => true
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

What causes a cache invalidation when building a Dockerfile?
Each command creates a new layer, that sits on top of the old one. Thus, layers are invalidated from the changed command, and...
Read more >
Docker Cache Invalidation (#26910) · Issues - gitlab-runner
The tl;dr is that the remote docker cache appears to be invalidated in a situation which it should not be. This triggers a...
Read more >
Optimizing builds with cache management
In other words, Docker will invalidate the cache for this layer. Image layer diagram, but now with the link between COPY and WORKDIR...
Read more >
Surgically Busting the Docker Cache - zwischenzugs
bustcache :).*/\1 $RANDOM/" Dockerfile && docker build -t tag . The perl command will ensure that the line is changed 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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found