Skip to content

Commit

Permalink
Fix CACHE when used with WITH DOCKER
Browse files Browse the repository at this point in the history
This fixes #2548

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
  • Loading branch information
alexcb committed Jan 5, 2023
1 parent 027f796 commit d4c64c7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable changes to [Earthly](https://github.com/earthly/earthly) will be doc
- Support for saving files larger than 64kB on failure within a `TRY/FINALLY` block. [#2452](https://github.com/earthly/earthly/issues/2452)
- Fixed race condition where `SAVE IMAGE` or `SAVE ARTIFACT AS LOCAL` commands were not always performed when contained in a target that was referenced by both a `FROM` (or `COPY`) and a `BUILD` command within the context of a `WAIT`/`END` block. [#2237](https://github.com/earthly/earthly/issues/2218)
- `WORKDIR` is lost when `--use-copy-link` feature is enabled with `GIT CLONE` or `COPY --keep-own` commands. [#2544](https://github.com/earthly/earthly/issues/2544)
- The `CACHE` command did not work when used inside a `WITH DOCKER` block. [#2549](https://github.com/earthly/earthly/issues/2549)

## v0.6.30 - 2022-11-22

Expand Down
5 changes: 5 additions & 0 deletions earthfile2llb/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,11 @@ func (c *Converter) WithDockerRun(ctx context.Context, args []string, opt WithDo

enableParallel := allowParallel && c.opt.ParallelConversion && c.ftrs.ParallelLoad

opt.extraRunOpts = nil
for _, cache := range c.persistentCacheDirs {
opt.extraRunOpts = append(opt.extraRunOpts, cache)
}

if c.ftrs.UseRegistryForWithDocker {
wdr := newWithDockerRunRegistry(c, enableParallel)
return wdr.Run(ctx, args, opt)
Expand Down
4 changes: 4 additions & 0 deletions earthfile2llb/withdockerrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type WithDockerOpt struct {
ComposeFiles []string
ComposeServices []string
TryCatchSaveArtifacts []debuggercommon.SaveFilesSettings
extraRunOpts []llb.RunOption
}

type withDockerRunTar struct {
Expand Down Expand Up @@ -217,6 +218,9 @@ func (w *withDockerRunTar) Run(ctx context.Context, args []string, opt WithDocke
"/var/earthly/dind", pllb.Scratch(), llb.HostBind(), llb.SourcePath("/tmp/earthly/dind")))
crOpts.extraRunOpts = append(crOpts.extraRunOpts, pllb.AddMount(
dockerdWrapperPath, pllb.Scratch(), llb.HostBind(), llb.SourcePath(dockerdWrapperPath)))
for _, extraRunOpt := range opt.extraRunOpts {
crOpts.extraRunOpts = append(crOpts.extraRunOpts, extraRunOpt)
}

var tarPaths []string
for index, tl := range w.tarLoads {
Expand Down
4 changes: 4 additions & 0 deletions earthfile2llb/withdockerrunreg.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ func (w *withDockerRunRegistry) Run(ctx context.Context, args []string, opt With
"/var/earthly/dind", pllb.Scratch(), llb.HostBind(), llb.SourcePath("/tmp/earthly/dind")))
crOpts.extraRunOpts = append(crOpts.extraRunOpts, pllb.AddMount(
dockerdWrapperPath, pllb.Scratch(), llb.HostBind(), llb.SourcePath(dockerdWrapperPath)))
for _, extraRunOpt := range opt.extraRunOpts {
crOpts.extraRunOpts = append(crOpts.extraRunOpts, extraRunOpt)
}

dindID, err := w.c.mts.Final.TargetInput().Hash()
if err != nil {
return errors.Wrap(err, "make dind ID")
Expand Down

0 comments on commit d4c64c7

Please sign in to comment.