client: take localdirs as argument

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-11-24 16:13:30 -08:00
parent b5e2ba63c6
commit cdcb09126b
8 changed files with 10 additions and 16 deletions

View File

@ -75,7 +75,7 @@ func New(ctx context.Context, host string, cfg Config) (*Client, error) {
type DoFunc func(context.Context, solver.Solver) error
// FIXME: return completed *Route, instead of *compiler.Value
func (c *Client) Do(ctx context.Context, pctx *plancontext.Context, fn DoFunc) error {
func (c *Client) Do(ctx context.Context, pctx *plancontext.Context, localdirs map[string]string, fn DoFunc) error {
lg := log.Ctx(ctx)
eg, gctx := errgroup.WithContext(ctx)
@ -90,13 +90,13 @@ func (c *Client) Do(ctx context.Context, pctx *plancontext.Context, fn DoFunc) e
// Spawn build function
eg.Go(func() error {
return c.buildfn(gctx, pctx, fn, events)
return c.buildfn(gctx, pctx, localdirs, fn, events)
})
return eg.Wait()
}
func (c *Client) buildfn(ctx context.Context, pctx *plancontext.Context, fn DoFunc, ch chan *bk.SolveStatus) error {
func (c *Client) buildfn(ctx context.Context, pctx *plancontext.Context, localdirs map[string]string, fn DoFunc, ch chan *bk.SolveStatus) error {
wg := sync.WaitGroup{}
// Close output channel
@ -111,11 +111,6 @@ func (c *Client) buildfn(ctx context.Context, pctx *plancontext.Context, fn DoFu
// buildkit auth provider (registry)
auth := solver.NewRegistryAuthProvider()
localdirs := map[string]string{}
for _, dir := range pctx.Directories.List() {
localdirs[dir.Path] = dir.Path
}
// Setup solve options
opts := bk.SolveOpt{
LocalDirs: localdirs,

View File

@ -198,7 +198,7 @@ var computeCmd = &cobra.Command{
lg.Fatal().Msg("unable to create environment")
}
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
err = cl.Do(ctx, env.Context(), env.Context().Directories.Paths(), func(ctx context.Context, s solver.Solver) error {
// check that all inputs are set
checkInputs(ctx, env)

View File

@ -83,7 +83,7 @@ var editCmd = &cobra.Command{
}
cl := common.NewClient(ctx)
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
err = cl.Do(ctx, env.Context(), env.Context().Directories.Paths(), func(ctx context.Context, s solver.Solver) error {
// check for cue errors by scanning all the inputs
_, err := env.ScanInputs(ctx, true)
if err != nil {

View File

@ -47,7 +47,7 @@ var listCmd = &cobra.Command{
}
cl := common.NewClient(ctx)
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
err = cl.Do(ctx, env.Context(), env.Context().Directories.Paths(), func(ctx context.Context, s solver.Solver) error {
inputs, err := env.ScanInputs(ctx, false)
if err != nil {
return err

View File

@ -59,7 +59,7 @@ func updateEnvironmentInput(ctx context.Context, cmd *cobra.Command, target stri
}
cl := common.NewClient(ctx)
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
err = cl.Do(ctx, env.Context(), env.Context().Directories.Paths(), func(ctx context.Context, s solver.Solver) error {
// the inputs are set, check for cue errors by scanning all the inputs
_, err := env.ScanInputs(ctx, true)
if err != nil {

View File

@ -46,7 +46,7 @@ var listCmd = &cobra.Command{
}
cl := common.NewClient(ctx)
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
err = cl.Do(ctx, env.Context(), env.Context().Directories.Paths(), func(ctx context.Context, s solver.Solver) error {
return ListOutputs(ctx, env, true)
})

View File

@ -89,8 +89,7 @@ func Execute() {
)
if len(os.Args) > 1 {
tr := otel.Tracer("cmd")
ctx, span = tr.Start(ctx, os.Args[1])
ctx, span = otel.Tracer("dagger").Start(ctx, os.Args[1])
// Record the action
span.AddEvent("command", trace.WithAttributes(
attribute.String("args", strings.Join(os.Args, " ")),

View File

@ -66,7 +66,7 @@ var upCmd = &cobra.Command{
lg.Fatal().Msg("unable to create environment")
}
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
err = cl.Do(ctx, env.Context(), env.Context().Directories.Paths(), func(ctx context.Context, s solver.Solver) error {
// check that all inputs are set
if err := checkInputs(ctx, env); err != nil {
return err