Solve sub build miss synchronous behavior

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2021-08-23 15:15:05 +02:00
parent 350e6ac5a2
commit 95468ce2b3
No known key found for this signature in database
GPG Key ID: 3C9847D981AAC1BF
2 changed files with 40 additions and 15 deletions

View File

@ -170,13 +170,22 @@ func (c *Client) buildfn(ctx context.Context, st *state.State, env *environment.
go catchOutput(buildCh) 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) {
eventsWg := sync.WaitGroup{}
closeCh := make(chan *bk.SolveStatus)
// Close events channel // Close events channel
defer close(eventsCh) defer func() {
close(closeCh)
eventsWg.Wait()
close(eventsCh)
}()
s := solver.New(solver.Opts{ s := solver.New(solver.Opts{
Control: c.c, Control: c.c,
Gateway: gw, Gateway: gw,
Events: eventsCh, Events: eventsCh,
EventsWg: &eventsWg,
CloseEvent: closeCh,
Auth: auth, Auth: auth,
Secrets: secrets, Secrets: secrets,
NoCache: c.cfg.NoCache, NoCache: c.cfg.NoCache,

View File

@ -6,6 +6,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
"sync"
bk "github.com/moby/buildkit/client" bk "github.com/moby/buildkit/client"
"github.com/moby/buildkit/client/llb" "github.com/moby/buildkit/client/llb"
@ -26,6 +27,8 @@ type Opts struct {
Control *bk.Client Control *bk.Client
Gateway bkgw.Client Gateway bkgw.Client
Events chan *bk.SolveStatus Events chan *bk.SolveStatus
EventsWg *sync.WaitGroup
CloseEvent chan *bk.SolveStatus
Auth *RegistryAuthProvider Auth *RegistryAuthProvider
Secrets session.Attachable Secrets session.Attachable
NoCache bool NoCache bool
@ -169,9 +172,22 @@ func (s Solver) Export(ctx context.Context, st llb.State, img *dockerfile2llb.Im
// Forward this build session events to the main events channel, for logging // Forward this build session events to the main events channel, for logging
// purposes. // purposes.
go func() { go func() {
select {
case <-s.opts.CloseEvent:
return
default:
for event := range ch { for event := range ch {
s.opts.Events <- event s.opts.Events <- event
} }
}
}()
// Add task to events
s.opts.EventsWg.Add(1)
// Resolve event
defer func() {
s.opts.EventsWg.Done()
}() }()
return s.opts.Control.Build(ctx, opts, "", func(ctx context.Context, c bkgw.Client) (*bkgw.Result, error) { return s.opts.Control.Build(ctx, opts, "", func(ctx context.Context, c bkgw.Client) (*bkgw.Result, error) {