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)
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
defer close(eventsCh)
defer func() {
close(closeCh)
eventsWg.Wait()
close(eventsCh)
}()
s := solver.New(solver.Opts{
Control: c.c,
Gateway: gw,
Events: eventsCh,
EventsWg: &eventsWg,
CloseEvent: closeCh,
Auth: auth,
Secrets: secrets,
NoCache: c.cfg.NoCache,

View File

@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"strings"
"sync"
bk "github.com/moby/buildkit/client"
"github.com/moby/buildkit/client/llb"
@ -26,6 +27,8 @@ type Opts struct {
Control *bk.Client
Gateway bkgw.Client
Events chan *bk.SolveStatus
EventsWg *sync.WaitGroup
CloseEvent chan *bk.SolveStatus
Auth *RegistryAuthProvider
Secrets session.Attachable
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
// purposes.
go func() {
select {
case <-s.opts.CloseEvent:
return
default:
for event := range ch {
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) {