diff --git a/client/client.go b/client/client.go index 63a8e3f7..c549ee09 100644 --- a/client/client.go +++ b/client/client.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "strings" + "sync" "go.opentelemetry.io/otel" "golang.org/x/sync/errgroup" @@ -103,6 +104,9 @@ func (c *Client) Do(ctx context.Context, state *state.State, fn DoFunc) error { } func (c *Client) buildfn(ctx context.Context, st *state.State, env *environment.Environment, fn DoFunc, ch chan *bk.SolveStatus) error { + // Close output channel + defer close(ch) + lg := log.Ctx(ctx) // Scan local dirs to grant access @@ -139,11 +143,35 @@ func (c *Client) buildfn(ctx context.Context, st *state.State, env *environment. Interface("attrs", opts.FrontendAttrs). Msg("spawning buildkit job") + wg := sync.WaitGroup{} + // Catch output from events + catchOutput := func(inCh chan *bk.SolveStatus) { + for e := range inCh { + ch <- e + } + wg.Done() + } + + // Catch solver's events + // Closed manually + eventsCh := make(chan *bk.SolveStatus) + wg.Add(1) + go catchOutput(eventsCh) + + // Catch build events + // Closed by buildkit + buildCh := make(chan *bk.SolveStatus) + wg.Add(1) + go catchOutput(buildCh) + resp, err := c.c.Build(ctx, opts, "", func(ctx context.Context, gw bkgw.Client) (*bkgw.Result, error) { + // Close events channel + defer close(eventsCh) + s := solver.New(solver.Opts{ Control: c.c, Gateway: gw, - Events: ch, + Events: eventsCh, Auth: auth, Secrets: secrets, NoCache: c.cfg.NoCache, @@ -184,7 +212,7 @@ func (c *Client) buildfn(ctx context.Context, st *state.State, env *environment. res := bkgw.NewResult() res.SetRef(ref) return res, nil - }, ch) + }, buildCh) if err != nil { return solver.CleanError(err) } @@ -196,6 +224,9 @@ func (c *Client) buildfn(ctx context.Context, st *state.State, env *environment. Str("value", v). Msg("exporter response") } + + // Wait until all the events are caught + wg.Wait() return nil } diff --git a/stdlib/universe.bats b/stdlib/universe.bats index c43df8cb..bfb92323 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -63,7 +63,6 @@ setup() { } @test "docker push and pull" { - skip "An occasional data race condition happen in the CI. Must be fix before execute that test" # Push image dagger -e docker-push up @@ -75,7 +74,6 @@ setup() { } @test "docker push: multi registry" { - skip "An occasional data race condition happen in the CI. Must be fix before execute that test" run dagger -e docker-push-multi-registry up }