fix dependencies between tasks

due to using an old snapshot of cue.Value, components relying on
dependent tasks were failing because of non-concretness.

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-02-01 19:12:38 -08:00 committed by Solomon Hykes
parent af9581c28a
commit 78601fefd6
7 changed files with 195 additions and 16 deletions

View File

@ -280,24 +280,30 @@ func (env *Env) Walk(ctx context.Context, fn EnvWalkFunc) (*Value, error) {
} }
// Cueflow match func // Cueflow match func
flowMatchFn := func(v cue.Value) (cueflow.Runner, error) { flowMatchFn := func(v cue.Value) (cueflow.Runner, error) {
lg := lg. if _, err := NewComponent(env.cc.Wrap(v, flowInst)); err != nil {
With().
Str("path", v.Path().String()).
Logger()
ctx := lg.WithContext(ctx)
lg.Debug().Msg("Env.Walk: processing")
// FIXME: get directly from state Value ? Locking issue?
val := env.cc.Wrap(v, flowInst)
c, err := NewComponent(val)
if os.IsNotExist(err) { if os.IsNotExist(err) {
// Not a component: skip // Not a component: skip
return nil, nil return nil, nil
} }
if err != nil {
return nil, err return nil, err
} }
return cueflow.RunnerFunc(func(t *cueflow.Task) error { return cueflow.RunnerFunc(func(t *cueflow.Task) error {
lg := lg.
With().
Str("path", t.Path().String()).
Logger()
ctx := lg.WithContext(ctx)
c, err := NewComponent(env.cc.Wrap(t.Value(), flowInst))
if err != nil {
return err
}
for _, dep := range t.Dependencies() {
lg.
Debug().
Str("dependency", dep.Path().String()).
Msg("dependency detected")
}
return fn(ctx, c, NewFillable(t)) return fn(ctx, c, NewFillable(t))
}), nil }), nil
} }

View File

@ -165,7 +165,10 @@ func (op *Op) Exec(ctx context.Context, fs FS, out *Fillable) (FS, error) {
Dir string Dir string
Always bool Always bool
} }
op.v.Decode(&cmd)
if err := op.v.Decode(&cmd); err != nil {
return fs, err
}
// marker for status events // marker for status events
// FIXME // FIXME
opts = append(opts, llb.WithCustomName(op.v.Path().String())) opts = append(opts, llb.WithCustomName(op.v.Path().String()))

View File

@ -64,6 +64,7 @@ func (s *Script) Execute(ctx context.Context, fs FS, out *Fillable) (FS, error)
log. log.
Ctx(ctx). Ctx(ctx).
Warn(). Warn().
Err(err).
Int("op", idx). Int("op", idx).
// FIXME: tell user which inputs are missing (by inspecting references) // FIXME: tell user which inputs are missing (by inspecting references)
Msg("script is missing inputs and has not been fully executed") Msg("script is missing inputs and has not been fully executed")

View File

@ -0,0 +1,51 @@
package testing
A: {
result: string
#dagger: compute: [
{
do: "fetch-container"
ref: "alpine"
},
{
do: "exec"
args: ["sh", "-c", """
echo '{"result": "from A"}' > /tmp/out
""",
]
dir: "/"
},
{
do: "export"
// Source path in the container
source: "/tmp/out"
format: "json"
},
]
}
B: {
result: string
#dagger: compute: [
{
do: "fetch-container"
ref: "alpine"
},
{
do: "exec"
args: ["sh", "-c", """
echo "{\\"result\\": \\"dependency \(A.result)\\"}" > /tmp/out
""",
]
dir: "/"
},
{
do: "export"
// Source path in the container
source: "/tmp/out"
format: "json"
},
]
}

View File

@ -0,0 +1,52 @@
package testing
A: {
result: string
#dagger: compute: [
{
do: "fetch-container"
ref: "alpine"
},
{
do: "exec"
args: ["sh", "-c", """
echo '{"result": "from A"}' > /tmp/out
""",
]
dir: "/"
},
{
do: "export"
// Source path in the container
source: "/tmp/out"
format: "json"
},
]
}
B: {
result: string
#dagger: compute: [
{
do: "fetch-container"
ref: "alpine"
},
{
do: "exec"
env: DATA: A.result
args: ["sh", "-c", """
echo "{\\"result\\": \\"dependency $DATA\\"}" > /tmp/out
""",
]
dir: "/"
},
{
do: "export"
// Source path in the container
source: "/tmp/out"
format: "json"
},
]
}

View File

@ -0,0 +1,55 @@
package testing
import "encoding/json"
A: {
string
#dagger: compute: [
{
do: "fetch-container"
ref: "alpine"
},
{
do: "exec"
args: ["sh", "-c", """
echo '{"hello": "world"}' > /tmp/out
""",
]
dir: "/"
},
{
do: "export"
// Source path in the container
source: "/tmp/out"
format: "string"
},
]
}
unmarshalled: json.Unmarshal(A)
B: {
result: string
#dagger: compute: [
{
do: "fetch-container"
ref: "alpine"
},
{
do: "exec"
args: ["sh", "-c", """
echo "{\\"result\\": \\"unmarshalled.hello=\(unmarshalled.hello)\\"}" > /tmp/out
""",
]
dir: "/"
},
{
do: "export"
// Source path in the container
source: "/tmp/out"
format: "json"
},
]
}

View File

@ -41,6 +41,17 @@ test::compute(){
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/success/overload/wrapped "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/success/overload/wrapped
} }
test::dependencies(){
local dagger="$1"
test::one "Dependencies: simple direct dependency" --exit=0 --stdout='{"A":{"result":"from A"},"B":{"result":"dependency from A"}}' \
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/dependencies/simple
test::one "Dependencies: interpolation" --exit=0 --stdout='{"A":{"result":"from A"},"B":{"result":"dependency from A"}}' \
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/dependencies/interpolation
test::one "Dependencies: json.Unmarshal" --exit=0 --stdout='{"A":"{\"hello\": \"world\"}\n","B":{"result":"unmarshalled.hello=world"},"unmarshalled":{"hello":"world"}}' \
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/dependencies/unmarshal
}
test::fetchcontainer(){ test::fetchcontainer(){
local dagger="$1" local dagger="$1"