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:
parent
af9581c28a
commit
78601fefd6
@ -280,24 +280,30 @@ func (env *Env) Walk(ctx context.Context, fn EnvWalkFunc) (*Value, error) {
|
||||
}
|
||||
// Cueflow match func
|
||||
flowMatchFn := func(v cue.Value) (cueflow.Runner, error) {
|
||||
lg := lg.
|
||||
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) {
|
||||
// Not a component: skip
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
if _, err := NewComponent(env.cc.Wrap(v, flowInst)); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
// Not a component: skip
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
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))
|
||||
}), nil
|
||||
}
|
||||
|
@ -165,7 +165,10 @@ func (op *Op) Exec(ctx context.Context, fs FS, out *Fillable) (FS, error) {
|
||||
Dir string
|
||||
Always bool
|
||||
}
|
||||
op.v.Decode(&cmd)
|
||||
|
||||
if err := op.v.Decode(&cmd); err != nil {
|
||||
return fs, err
|
||||
}
|
||||
// marker for status events
|
||||
// FIXME
|
||||
opts = append(opts, llb.WithCustomName(op.v.Path().String()))
|
||||
|
@ -64,6 +64,7 @@ func (s *Script) Execute(ctx context.Context, fs FS, out *Fillable) (FS, error)
|
||||
log.
|
||||
Ctx(ctx).
|
||||
Warn().
|
||||
Err(err).
|
||||
Int("op", idx).
|
||||
// FIXME: tell user which inputs are missing (by inspecting references)
|
||||
Msg("script is missing inputs and has not been fully executed")
|
||||
|
51
examples/tests/dependencies/interpolation/main.cue
Normal file
51
examples/tests/dependencies/interpolation/main.cue
Normal 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"
|
||||
},
|
||||
]
|
||||
}
|
52
examples/tests/dependencies/simple/main.cue
Normal file
52
examples/tests/dependencies/simple/main.cue
Normal 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"
|
||||
},
|
||||
]
|
||||
}
|
55
examples/tests/dependencies/unmarshal/main.cue
Normal file
55
examples/tests/dependencies/unmarshal/main.cue
Normal 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"
|
||||
},
|
||||
]
|
||||
}
|
@ -41,6 +41,17 @@ test::compute(){
|
||||
"$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(){
|
||||
local dagger="$1"
|
||||
|
||||
|
Reference in New Issue
Block a user