Open coryb opened 1 year ago
Can you reproduce this with just LLB? i.e. _first
will be execSt.Root()
whereas first
will be execSt.GetMount(...)
.
Pretty sure this is just an an issue with how hlb generates the state. At least this does what I expect with LLB:
func main() {
ctx := context.Background()
c, err := client.New(context.Background(), "docker-container://buildkitd")
if err != nil {
panic(err)
}
defer c.Close()
localCwd, _ := os.Getwd()
execFirst := llb.Image("busybox").Run(
llb.Shlex("echo first"),
llb.AddMount(localCwd, llb.Scratch()),
)
_first := execFirst.Root()
first := execFirst.GetMount(localCwd)
second := _first.Run(
llb.Shlex("echo second"),
llb.AddMount(localCwd, first),
).GetMount(localCwd)
def, err := second.Marshal(ctx, llb.LinuxAmd64)
if err != nil {
panic(err)
}
ch := make(chan *client.SolveStatus)
eg, ctx := errgroup.WithContext(ctx)
eg.Go(func() error {
_, err = c.Solve(ctx, def, client.SolveOpt{}, ch)
return err
})
eg.Go(func() error {
_, err = progressui.DisplaySolveStatus(context.TODO(), "", nil, os.Stdout, ch)
return err
})
err = eg.Wait()
if err != nil {
panic(err)
}
}
Running that I see:
#1 docker-image://docker.io/library/busybox:latest
#1 resolve docker.io/library/busybox:latest
#1 resolve docker.io/library/busybox:latest 0.3s done
#1 DONE 0.3s
#2 echo first
#2 CACHED
#3 echo second
#0 0.051 second
#3 DONE 0.1s
When we run the
second
target from this HLB:we will see something like:
Note the
echo first
is evaluated twice, if we addnoCache
it will runecho first
twice in two different containers. The duplication goes away when we remove this lineI am at a loss for how to fix this. It seems the
first
mount is getting evaluated twice once hasForceNoOutput
applied and one has the Bind logic applied. I am not sure why the Bind logic would not be applied in both locations.We should probably revert #347 and #348 unless anyone has ideas on how to work around this.