Repository navigation
Closed as not planned
Labels
kind/bugSomething isn't working
Description
Context
@Alvise88 is porting his config to Dagger Europa.
His use case is: read a file from the host and modify it using dagger.
Issue
The first implementation doesn't seem to work because no action is being referenced. That way, dagger do doesn't seem to run.
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
client: filesystem: "test.txt": {
read: contents: string
write: contents: read.contents
}
}
But, it's not the subject of this issue: what we did is that we created a new action that would use the client filesystem as intermediary steps.
However, when testing, we realized that client: filesystem: "test.txt": write: contents couldn't be inlined in a string:
For all the repro cases below, you need to create a
test.txtfile withfoowritten inside
No string interpolation - this works
package main
import(
"dagger.io/dagger"
"universe.dagger.io/alpine"
"universe.dagger.io/docker"
)
dagger.#Plan & {
client: filesystem: "./test.txt": {
read: contents: string
write: contents: actions.hosts.export.contents // works
}
actions: hosts: {
configuration: client.filesystem."/etc/hosts".read.contents
image: docker.#Build & {
steps: [
alpine.#Build & {
packages: "docker-cli": {}
packages: "curl": {}
},
docker.#Run & {
always: true
command: {
name: "sh"
flags: "-c": "echo -n bar > /foo.txt"
}
},
]
}
export: dagger.#ReadFile & {
input: image.output.rootfs
path: "foo.txt"
}
}
}
With string interpolation - this doesn't work
package main
import(
"dagger.io/dagger"
"universe.dagger.io/alpine"
"universe.dagger.io/docker"
)
dagger.#Plan & {
client: filesystem: "./test.txt": {
read: contents: string
write: contents: "\(actions.hosts.export.contents)" // This doesn't work
}
actions: hosts: {
configuration: client.filesystem."/etc/hosts".read.contents
image: docker.#Build & {
steps: [
alpine.#Build & {
packages: "docker-cli": {}
packages: "curl": {}
},
docker.#Run & {
always: true
command: {
name: "sh"
flags: "-c": "echo -n bar > /foo.txt"
}
},
]
}
export: dagger.#ReadFile & {
input: image.output.rootfs
path: "foo.txt"
}
}
}
Current solution
- Enforce the
stringtype of theclient: filesystem: write:
write: contents: "\(actions.hosts.export.contents)" // This doesn't work
becomes
write: contents: "\(actions.hosts.export.contents)" // This works now
write: contents: string
or
write: contents: "\(actions.hosts.export.contents)" & string // This works now
- Do not inline in the client API, but directly in your actions
Potential root causes
@helderco thought this might be related to the dagger do fixes that @aluzzardi and @jlongtine implemented recently.
Metadata
Metadata
Assignees
Labels
kind/bugSomething isn't working
Activity
helderco commentedon Mar 11, 2022
I was about to create an issue for this. I made a simple test:
This should be added to
tests/plan/do. It doesn't have to do with theclient.filesystemtask per se, it's just that the task runner doesn't pick up the output with the interpolated reference.jlongtine commentedon Mar 11, 2022
So, pretty sure I understand what's happening here.
If you
cue eval@helderco's test, you'll get this disjunction:Because
"\(actions.test.contents)"isn't concrete yet. Our first pass of allowing tasks doesn't see it as a task (because it isn't one yet). Thus, it isn't put in the "allow" list, even though it's dependent on the action we are running. So... it's then disallowed from running when"\(actions.test.contents)"becomes concrete, the disjunction resolves, and it becomes a task we can run.helderco commentedon Mar 31, 2022
Related to cue-lang/cue#629, tracked in #493
helderco commentedon Apr 10, 2022
There's an easy and more appropriate solution:
As for the unexpected behavior of the interpolation, I'll defer to the #493 issue.
helderco commentedon Apr 11, 2022
On second thought, the usage of interpolation here shouldn't fail on plan load. Intuitively it should get resolved as a string, but it isn't. We should drill down the repro into pure CUE and see if it's really about cue-lang/cue#629 or something else.
grouville commentedon Jan 5, 2023
Closing, as Cue API is not a priority for now