Fix local directory error handling

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-10-19 14:47:52 -07:00
parent 36f468577a
commit c08f619b02
3 changed files with 20 additions and 19 deletions

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"os" "os"
"path/filepath"
"strings" "strings"
"sync" "sync"
@ -116,13 +115,9 @@ func (c *Client) buildfn(ctx context.Context, st *state.State, env *environment.
lg := log.Ctx(ctx) lg := log.Ctx(ctx)
// Scan local dirs to grant access // Scan local dirs to grant access
localdirs := env.LocalDirs() localdirs, err := env.LocalDirs()
for label, dir := range localdirs { if err != nil {
abs, err := filepath.Abs(dir) return err
if err != nil {
return err
}
localdirs[label] = abs
} }
// buildkit auth provider (registry) // buildkit auth provider (registry)

View File

@ -3,6 +3,7 @@ package environment
import ( import (
"context" "context"
"fmt" "fmt"
"path/filepath"
"cuelang.org/go/cue" "cuelang.org/go/cue"
cueflow "cuelang.org/go/tools/flow" cueflow "cuelang.org/go/tools/flow"
@ -75,10 +76,11 @@ func (e *Environment) Computed() *compiler.Value {
// and return all referenced directory names. // and return all referenced directory names.
// This is used by clients to grant access to local directories when they are referenced // This is used by clients to grant access to local directories when they are referenced
// by user-specified scripts. // by user-specified scripts.
func (e *Environment) LocalDirs() map[string]string { func (e *Environment) LocalDirs() (map[string]string, error) {
dirs := map[string]string{} dirs := map[string]string{}
localdirs := func(code *compiler.Value) {
Analyze( localdirs := func(code *compiler.Value) error {
return Analyze(
func(op *compiler.Value) error { func(op *compiler.Value) error {
do, err := op.Lookup("do").String() do, err := op.Lookup("do").String()
if err != nil { if err != nil {
@ -91,7 +93,12 @@ func (e *Environment) LocalDirs() map[string]string {
if err != nil { if err != nil {
return err return err
} }
dirs[dir] = dir abs, err := filepath.Abs(dir)
if err != nil {
return err
}
dirs[dir] = abs
return nil return nil
}, },
code, code,
@ -101,10 +108,10 @@ func (e *Environment) LocalDirs() map[string]string {
// FIXME: use a common `flow` instance to avoid rescanning the tree. // FIXME: use a common `flow` instance to avoid rescanning the tree.
src := compiler.NewValue() src := compiler.NewValue()
if err := src.FillPath(cue.MakePath(), e.plan); err != nil { if err := src.FillPath(cue.MakePath(), e.plan); err != nil {
return nil return nil, err
} }
if err := src.FillPath(cue.MakePath(), e.input); err != nil { if err := src.FillPath(cue.MakePath(), e.input); err != nil {
return nil return nil, err
} }
flow := cueflow.New( flow := cueflow.New(
&cueflow.Config{}, &cueflow.Config{},
@ -113,10 +120,12 @@ func (e *Environment) LocalDirs() map[string]string {
) )
for _, t := range flow.Tasks() { for _, t := range flow.Tasks() {
v := compiler.Wrap(t.Value()) v := compiler.Wrap(t.Value())
localdirs(v.Lookup("#up")) if err := localdirs(v.Lookup("#up")); err != nil {
return nil, err
}
} }
return dirs return dirs, nil
} }
// Up missing values in environment configuration, and write them to state. // Up missing values in environment configuration, and write them to state.

View File

@ -205,9 +205,6 @@ import (
} }
} }
"mount": { "mount": {
if ssh == _|_ {
"/var/run/docker.sock": from: "docker.sock"
}
if ssh != _|_ { if ssh != _|_ {
if ssh.key != _|_ { if ssh.key != _|_ {
"/key": secret: ssh.key "/key": secret: ssh.key