Repository navigation
Closed
Labels
Description
Overview
Sometimes, when using client: filesystem: or client: network:, the path needs to be configurable (usually from an env var) but we can't have the action's CUE path set at runtime, or dependent on another action. That's because we don't support dynamic actions yet, so actions need to be known at load time.
Details
dagger.#Plan & {
actions: {
test: [string]: core.#Nop & {
input: "world"
}
// action with dynamic path here
test: (gen.output): _
// run action which depends on a dynamic path
run: core.#Nop & {
input: test[gen.output].output
}
// #GenString just produces a string in `output`
// from a core action
gen: #GenString
}
}
#GenString: {
_img: core.#Pull & {
source: "alpine"
}
_gen: core.#Exec & {
input: _img.output
args: ["sh", "-c", "echo hello > /out"]
}
_read: core.#ReadFile & {
input: _gen.output
path: "/out"
}
output: _read.contents
}This is what we're doing with Client API, and it doesn't work. actions.test isn't run:
➜ dagger do run
[✔] actions.gen
[✔] actions.runOf course it works if the value is known at compile time:
- gen: #GenString
+ gen: output: "hello"➜ dagger do run
[✔] actions.test.hello
[✔] actions.runWhat users want to do?
client: {
env: {
KUBECONFIG: string
OCP_PATH: string
}
filesystem: {
(env.KUBECONFIG): read: contents: dagger.#Secret
(env.OCP_PATH): write: contents: actions.loginOCP.output
}
}Related:
- [BUG] bash.#Run mounts failed with: mount "xxx" is not concrete #1823
- Mounts should support file paths #2200
Current workarounds
Use a command:
client: {
env: {
KUBECONFIG: string
OCP_PATH: string
}
commands: {
kubeconfig: {
name: "cat"
args: [env.KUBECONFIG]
stdout: dagger.#Secret
}
ocp: {
name: "sh"
args: ["-c", "cat > \(env.OCP_PATH)"]
stdin: actions.loginOCP.output
}
}
}Proposal
While we wait for dynamic actions, there's a backwards compatible way to tweak the API. Just use the fs path in the CUE path as a default, but allow setting a different one inside de action.
This allows you to:
client: {
env: {
KUBECONFIG: string
OCP_PATH: string
}
filesystem: {
kubeconfig: read: {
path: env.KUBECONFIG
contents: dagger.#Secret
}
ocp: write: {
path: env.OCP_PATH
contents: actions.loginOCP.output
}
}
}Same with client: network.
Pros:
- Still compatible with current API if you have a fixed path and want to use that;
- Frees you from having to maintain the path in all references, or to keep references shorter for long paths;
- Solves current issues by having the option of having a custom name instead of the fs path in the action CUE path;
Cons:
- Commit to new design even if issues are resolved (not an issue for me);
Activity
helderco commentedon Apr 14, 2022
helderco commentedon Apr 21, 2022
helderco commentedon Apr 21, 2022
There's two more cases the proposal would unlock. They're two sides of the same coin, but both have been requested.
Reading multiple times from the same dir
Writing multiple times to the same dir
helderco commentedon May 2, 2022
In #2385 I found a limitation in implementing dynamic paths when reading directories, i.e.,
client: filesystem: ...: read: contents: dagger.#FS: We need to know the path before running the plan to setup the BuildKit client (LocalDirs).To be clear, this only happens when reading directories. Not files, secrets nor when writing.
As of this moment there's no clear path forward.[-]Client API path issues[/-][+]Client API dynamic paths[/+]