#[resolved] - How to get output of the work being done in a container?

1 messages · Page 1 of 1 (latest)

red verge
#

What version of Dagger are you using?

unique depot
#

hi! currently at 0.11.1

red verge
#

Have you tried the -v flag for verbose output? I'm not sure it will help you, but it was recently added so that the default output is sort of silent.

unique depot
#

let me do a quick run and see

#

haven't tried it yet

unique depot
#

and I'm not getting the stdout of commands other than the last one

red verge
#

Hmm. yeah. I wasn't sure it would help. I'm a Dagger beginner myself. So, sorry I couldn't help.

unique depot
#

no problem!

red verge
#

The crew are in the US, so they usually reply in the afternoon.

unique depot
#

@red verge there's -d that's more verbose but it includes information about the exchange between the client and dacker backend

red verge
#

[open] - How to get output of the work being done in a contair?

#

[open] - How to get output of the work being done in a container?

onyx patio
#

Hey @unique depot

At a high level what you’re looking for is the stdout method that exists on the container type.

could you share your code, there are a few ways to approach this and it will be easier to point you in the right direction with an existing code snippet.

unique depot
#

here's the command that I'm looking to introspect:

dagger -m github.com/Dudesons/daggerverse/infrabox call \                                                                                                         
terragrunt \
container \
with-exec --args "apk update" 
#

the stdout function does do this, but it requires a successful run and furthermore it only outputs the stdout of the very last command

subtle coral
#

Couple things off the top of my head that helped me inspect:

  • You can write logs to files in the container itself, which can be output later.
  • You can modify the function to return a Container instead of some other value, and have that function stop just before the point where you would run the command that's failing. Then you can invoke dagger call my-func [flags] terminal, and it will give you a default sh shell into that container when the function returns. Then you can run the failing command yourself and watch the output/inspect the environment there.
#

In my case, when a command called through WithExec() fails, at the end of the function I do get the whole log of that command if I've called Stdout(ctx) (Go SDK). I'm pretty sure I get output from earlier commands as well.

unique depot
#

Hm let me try that again

subtle coral
#

If a function returns a container, I think you're just able to call terminal on it to get a shell and try anything you want. Has been super helpful for me.

unique depot
onyx patio
#

terminal is great for debugging, but if you just want to see the output, call stdout as the last argument

#

Try this

dagger -m github.com/Dudesons/daggerverse/infrabox call \                                                                                                         
terragrunt \
container \
with-exec --args "apk update" stdout
subtle coral
#

I'm very unfamiliar with all the things you can do at the CLI level -- that's great! I only knew to do this via SDKs.

onyx patio
onyx patio
# unique depot

Yeah I did but that looks like a separate issue 😄 let me dig a bit

#

Ah, if you want to do with-exec you have to pass an array of arguments if there is more than one

Check this out to see for yourself (also good to always use the --help whenever you run into issues)

#

You should see this at the top

Flags:
      --args strings
                Command to run instead of the
                container's default command
                (e.g., ["run", "main.go"]).

                If empty, the container's
                default command is used.
unique depot
#

hm

#

fails with zsh, i'll try bash

subtle coral
#

In that case, I imagine under the hood his command was returning something like command not found, but how do we see more than the exit code here?

onyx patio
#

Hm sorry I am a bit lost too lets look at the code!

unique depot
onyx patio
unique depot
#

oh! so this is a module-level error?

#

let's try using terminal first brb

onyx patio
#

Yeah I was trying that too haha

#

It works for me inside the terminal :/

unique depot
#

yeah me too

#

i'll dig into the module's source a sec

onyx patio
#

I think the main issue is that when you call with_exec from code you have to pass in an array of strings, but I am not 100% sure how to handle this in the CLI

#

This is not actually a problem with this speecific module, its the way that with-exec works

#

This worked for me via the CLI

dagger -m github.com/Dudesons/daggerverse/infrabox call terragrunt container with-exec --args "apk,update" stdout
#

I think this DX is a bit clunky, we are working on improving it though.

unique depot
#

niiiiice! fantastic finally

onyx patio
#

Specifically, how is someone supposed to know that they need to pass in a list of strings - the way you wrote it initially is how I would have done it too.

unique depot
#

the error also was hard to parse

#

thanks a lot seriously

#

@subtle coral and also for the debugging tips!

onyx patio
unique depot
#

argh i would help out and do this myself if I had the time but i'm rushing and I already half-committed to making a scraper for making a wiki out of this discord

onyx patio