I'm trying to implement a workflow using dagger where the command runs a single-use container, which opens an interactive TUI, which saves a file to the container, and then (hopefully) return the file in dagger. I know I can use .Terminal to open an interactive terminal, but I can't seem to find a way to export files/directories from the terminal session after it exits. Is there some way to do this in dagger?
#Use dagger for one-off commands
1 messages · Page 1 of 1 (latest)
I think right now Terminal is really only useful for debugging, or kicking off an interactive session.
I don't think there is any way to do something after the terminal exits. Can you tell me more about your specific use case?
Could you pass whatever parts needs to be interactive as params instead?
Sure! The use-case I have in mind is building out a module for configuring OpenWRT. It has a make menuconfig command which opens a TUI for configuring the build. Once that's finished, it outputs a .config file which can be used later for building the flashable image.
In general, if you already have a .config file there's no need for the TUI, but if you are starting from scratch, it would be useful to have a command which let's a user open the tui in a running build container, and output the resulting .config.
Ref: https://openwrt.org/docs/guide-developer/toolchain/use-buildsystem
Makes sense, I agree that would be great. Could you please open an issue in GH for this?
I think all the building blocks are there, there just needs to be a way to "continue" upon exiting terminal
Alternatively I think this could also be solved if we supported "live" directories similar to how docker-compose works: https://github.com/dagger/dagger/issues/6990 because in that scenario you may mount your local directory as a "synced dir" and then whatever happens in your session would persist.
Yup, I could make an issue for it.
Re: the live environments. This could operate as a workaround, but I think being able to access the fs (files, directories) of container after it exits the .Terminal session would be great. This would allow for either
a) exporting the file to the host system, or even
b) using the dagger.File in dagger to continue an operation, for example continuing with the build after the user confirms and saves their .config file
FWIW if you use the Terminal call in the SDK chaining, the pipeline continues after the terminal exits
so yes, @marble shuttle there's currently a way to achieve this. The only caveat is that you'll have to put the .config generated file in a cache volume to use it afterwards in the subsequent steps.
here's an example:
func (l *Lala) Test() *dagger.Container {
return dag.Container().From("alpine").
WithExec([]string{"apk", "add", "bash"}).
WithMountedCache("/cache", dag.CacheVolume("cache")).
Terminal(dagger.ContainerTerminalOpts{
Cmd: []string{"bash", "-c", `
read -p "Enter name: "
echo $REPLY > /cache/reply
`},
}).WithExec([]string{"cat", "/cache/reply"})
}
That's an alternative I was considering. Thanks for the concrete example @timid moth, I'll try it out when I get the chance!
you can still export the resulting file as well if you copy the file from the cache volume to a directory in the container and then call File($path) on that
LMK if that makes sense
Yup, makes sense