Merge pull request #779 from TomChv/fix-docker-push-data-race
Fix data race condition on op.#PushContainer
This commit is contained in:
commit
18c4978f07
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
"golang.org/x/sync/errgroup"
|
"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 {
|
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)
|
lg := log.Ctx(ctx)
|
||||||
|
|
||||||
// Scan local dirs to grant access
|
// 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).
|
Interface("attrs", opts.FrontendAttrs).
|
||||||
Msg("spawning buildkit job")
|
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) {
|
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{
|
s := solver.New(solver.Opts{
|
||||||
Control: c.c,
|
Control: c.c,
|
||||||
Gateway: gw,
|
Gateway: gw,
|
||||||
Events: ch,
|
Events: eventsCh,
|
||||||
Auth: auth,
|
Auth: auth,
|
||||||
Secrets: secrets,
|
Secrets: secrets,
|
||||||
NoCache: c.cfg.NoCache,
|
NoCache: c.cfg.NoCache,
|
||||||
@ -184,7 +212,7 @@ func (c *Client) buildfn(ctx context.Context, st *state.State, env *environment.
|
|||||||
res := bkgw.NewResult()
|
res := bkgw.NewResult()
|
||||||
res.SetRef(ref)
|
res.SetRef(ref)
|
||||||
return res, nil
|
return res, nil
|
||||||
}, ch)
|
}, buildCh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return solver.CleanError(err)
|
return solver.CleanError(err)
|
||||||
}
|
}
|
||||||
@ -196,6 +224,9 @@ func (c *Client) buildfn(ctx context.Context, st *state.State, env *environment.
|
|||||||
Str("value", v).
|
Str("value", v).
|
||||||
Msg("exporter response")
|
Msg("exporter response")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait until all the events are caught
|
||||||
|
wg.Wait()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,6 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "docker push and pull" {
|
@test "docker push and pull" {
|
||||||
skip "An occasional data race condition happen in the CI. Must be fix before execute that test"
|
|
||||||
# Push image
|
# Push image
|
||||||
dagger -e docker-push up
|
dagger -e docker-push up
|
||||||
|
|
||||||
@ -75,7 +74,6 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "docker push: multi registry" {
|
@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
|
run dagger -e docker-push-multi-registry up
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user