Skip to content

use TUI for dagger do, dagger query, dagger listen - #5151

Merged
vito merged 21 commits into
dagger:mainfrom
vito:integrate-tui
May 19, 2023
Merged

vito merged 21 commits into
dagger:mainfrom
vito:integrate-tui

Conversation

@vito

@vito vito commented May 17, 2023 •

Copy link
Copy Markdown
Contributor

This PR extracts the TUI setup from dagger run and implements it for all other commands that start an engine.

It also does a few other things:

  • The inline TUI is now on by default, and the _EXPERIMENTAL_DAGGER_TUI env has been removed.
  • The interactive tree TUI is now behind a _EXPERIMENTAL_DAGGER_INTERACTIVE_TUI env.
  • The interactive tree TUI has been converted to read from a Progrock event stream instead of Buildkit.
  • When stdout and stderr are both a non-TTY, the Buildkit console output format will be used instead. This should be replaced with a Progrock equivalent in the future, but this is a cheap stopgap in the meantime.
    • --debug is no longer required to see console output. It seems a little odd to me to be completely silent by default when there's no TTY, but maybe there was a good reason for this?

vito added 16 commits May 17, 2023 14:13
don't need TCP support anymore

Signed-off-by: Alex Suraci <[email protected]>
TODO: groups

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
* track numeric offset rather than current entry
* highlight non-current but same vertexes

Signed-off-by: Alex Suraci <[email protected]>
* inline TUI now default, not experimental
* interactive TUI now enabled by _EXPERIMENTAL_DAGGER_INTERACTIVE_TUI
* console output now used if stdout/stderr is not a TTY

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
this was a temporary experiment; don't think this is _quite_ what we
want, since it still clips output at the vterm height

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito requested a review from sipsma May 17, 2023 20:15
@vito

vito commented May 17, 2023 •

Copy link
Copy Markdown
Contributor Author

@sipsma So this is sort of implemented for dagger do - but I haven't figured out how to route the actual command's progress through to the outer TUI. Instead it seems to be rendering the console-style output to the command's vertex, and I haven't found where that's happening. There's also kind of funny looking output, with a vertex showing up for each intermediate command.

asciicast

(Code)

Side notes from experimentation:

  • Need some way to configure includes/excludes for the project dir, so I can have it ignore go.work.
  • The command ends up being cached, which is neat but pretty aggressive, considering the command I'm running uses cache busters that end up being ineffective because the entire outer command gets cached.

@sipsma

sipsma commented May 17, 2023

Copy link
Copy Markdown
Contributor

Instead it seems to be rendering the console-style output to the command's vertex, and I haven't found where that's happening.

Yeah I suspected this might cause problems, I think it's due to the fact that the command is executing as a nested session served from the shim: https://github.com/sipsma/dagger/blob/0ef2bb305d8e9c177698b1e61aab58b05eaed078/cmd/shim/main.go#L533-L533

Not 100% sure though, let me know if that makes sense to you. If that is indeed the problem, my guess is that we will want some way of forwarding events from that nested session to the outer session.

Coincidentally, I have been banging my head against a similar-ish problem while trying to add support for interacting with the caller's Host from within command code. I've flipflopped around quite a bit, but am currently settling in on an approach where the "inner" session has the ability to selectively call the "outer" session via socket forwarding. More to it than that, but that's the gist relevant here.

I don't know if that would exactly solve the problem here, but if not maybe a similar approach could be taken where we create a socket that enables forwarding of events from the command to the outer session?

There's also kind of funny looking output, with a vertex showing up for each intermediate command.

That's behaving as intended. Each resolver is executed and cached individually. I could see it possibly making sense to display it differently though, but no immediate ideas.

Need some way to configure includes/excludes for the project dir, so I can have it ignore go.work.

Yeah that makes sense. My immediate thought is to put this in dagger.json. I'll create a linear issue

The command ends up being cached, which is neat but pretty aggressive, considering the command I'm running uses cache busters that end up being ineffective because the entire outer command gets cached.

Yep, we specifically designed this so that you can get maximal caching in the same way you get caching for any Exec. If your command only makes Dagger API calls, this doesn't really matter since those will be cached. But commands are just code, so you are also free to import libraries and do whatever expensive work you want to do directly in the language you're using, no "shelling out" via WithExec required. We want caching to apply to all that too.

For use cases that need to always run, we probably should just add a --no-cache or similar flag to dagger do for now. In the longer term, I hope that the most common use cases for no-cache get subsumed into more formalized features, e.g. we could add "deployments" as a concept sibling to commands and artifacts and setup official mechanisms for only running the deployment when external state is out of sync. But even then we'll still need a fallback option, so --no-cache probably makes sense. I'll add a linear issue for that too.

@vito

vito commented May 18, 2023

Copy link
Copy Markdown
Contributor Author

Not 100% sure though, let me know if that makes sense to you. If that is indeed the problem, my guess is that we will want some way of forwarding events from that nested session to the outer session.

Ah-ha, yeah that has to be it. I added a engineConf.LogOutput = nil to engine.Start and it was still happening so I was starting to question my understanding of the universe. It would make sense for it to be the shim doing this, since I didn't re-build the engine image where the shim binary lives.

Coincidentally, I have been banging my head against a similar-ish problem while trying to add support for interacting with the caller's Host from within command code. I've flipflopped around quite a bit, but am currently settling in on an approach where the "inner" session has the ability to selectively call the "outer" session via socket forwarding. More to it than that, but that's the gist relevant here.

I don't know if that would exactly solve the problem here, but if not maybe a similar approach could be taken where we create a socket that enables forwarding of events from the command to the outer session?

Yeah, after a quick look that's what comes to mind for me too. I can try mounting a socket and sending Progrock status updates over it.

@gerhard

gerhard commented May 18, 2023

Copy link
Copy Markdown
Contributor

Based on the conversation, I don't think that this is ready to be merged so that it goes out in today's release. If I don't hear otherwise in the next few hours, leaving this for next week.

@gerhard

gerhard commented May 18, 2023

Copy link
Copy Markdown
Contributor

Note to self: this (loosely related) issue is worth checking out before next week's release:

vito added 2 commits May 18, 2023 11:11
Signed-off-by: Alex Suraci <[email protected]>
still not quite perfect DX but better than nothing

Signed-off-by: Alex Suraci <[email protected]>
@vito

vito commented May 18, 2023

Copy link
Copy Markdown
Contributor Author

@sipsma Proxying through a socket worked!

asciicast

@sipsma

sipsma commented May 18, 2023

Copy link
Copy Markdown
Contributor

Proxying through a socket worked!

Awesome!

This doesn't need to be in this PR, but another consideration with dagger do is that before we even invoke the users commands we have to build their project. If uncached, that can involve pulling base images for their language and running a few execs with that, so it can take a while and we want to make sure there's not dead air.

On the other hand, those steps are really internal to the implementation of projects, so it feels like it would be nice to not display them prominently maybe. Like we want to show that the project is building, but not necessarily every little step involved, at least by default.

If we updated those project build steps to all be under a certain pipeline label would that help organize it all in the TUI too? Just spitballing.

@sipsma sipsma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just a few non-blocking nits

Comment thread core/project.go
}

func (p *Project) getResolver(ctx context.Context, gw bkgw.Client) (graphql.FieldResolveFn, error) {
func (p *Project) getResolver(ctx context.Context, gw bkgw.Client, progSock *Socket) (graphql.FieldResolveFn, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not a blocker, but the same problem you solved here applies to any dagger exec where ExperimentalPrivilegedNesting is true, so it would be good to make the same change in core/container.go too someday.

(Honestly, this project code should probably be refactored to just call that container code so we can get rid of the duplication, but I can take care of that separately. There's some other refactorization we need here anyways to enable sdk-specific cache mounts.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Had to pass the socket through a few places because of the default-exec behavior, but nothing too crazy.

Comment thread engine/engine.go
return "", nil, nil, err
}

return progSock, progW, l.Close, nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unix sock won't be deleted from the fs when it's closed, so we could toss in an os.Remove with the cleanup too. Otherwise I suppose over time you will keep accumulating leftover sockets indefinitely, which is mostly harmless but technically takes up inodes I suppose.

@vito vito May 18, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go stdlib will unlink on close for Unix sockets:

https://github.com/golang/go/blob/72f448cb48069ddeb0c30e726fc3b9d113aaf51e/src/net/unixsock_posix.go#L193

I confirmed they're being cleaned up locally, but it's definitely possible to leak them over time if you aggressively kill the dagger process, and I had one leaked probably from a SIGQUIT I sent earlier. Maybe this could be switched to TCP? 🤔

edit: also strictly speaking this should probably be in RuntimeDir rather than CacheHome

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go stdlib will unlink on close for Unix sockets:

Oh cool, I had no idea, that's very nice of it!

I confirmed they're being cleaned up locally, but it's definitely possible to leak them over time if you aggressively kill the dagger process, and I had one leaked probably from a SIGQUIT I sent earlier. Maybe this could be switched to TCP? 🤔

Eh I wouldn't worry about it then. I was just concerned that like 1000 runs of dagger would result in 1000 sockets, but if it only rarely leaks it really doesn't matter in practice I don't think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 sounds good! I think putting it in xdg.RuntimeDir should help too, since that tends to be a directory that gets blown away when the machine reboots, so any leaks won't last for long.

vito added 3 commits May 18, 2023 16:34
* silence RPC logs
* print all output on completion

Signed-off-by: Alex Suraci <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants