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,16 +170,25 @@ 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,
Auth: auth,
Secrets: secrets,
NoCache: c.cfg.NoCache,
Control: c.c,
Gateway: gw,
Events: eventsCh,
EventsWg: &eventsWg,
CloseEvent: closeCh,
Auth: auth,
Secrets: secrets,
NoCache: c.cfg.NoCache,
})
// Compute output overlay

View File

@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"strings"
"sync"
bk "github.com/moby/buildkit/client"
"github.com/moby/buildkit/client/llb"
@ -23,12 +24,14 @@ type Solver struct {
}
type Opts struct {
Control *bk.Client
Gateway bkgw.Client
Events chan *bk.SolveStatus
Auth *RegistryAuthProvider
Secrets session.Attachable
NoCache bool
Control *bk.Client
Gateway bkgw.Client
Events chan *bk.SolveStatus
EventsWg *sync.WaitGroup
CloseEvent chan *bk.SolveStatus
Auth *RegistryAuthProvider
Secrets session.Attachable
NoCache bool
}
func New(opts Opts) Solver {
@ -169,11 +172,24 @@ 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() {
for event := range ch {
s.opts.Events <- event
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) {
res, err := c.Solve(ctx, bkgw.SolveRequest{
Definition: def,