Skip to content

replace shell command with chainable core api - #6390

Merged
sipsma merged 1 commit into
dagger:mainfrom
sipsma:chain-shell
Jan 23, 2024
Merged

sipsma merged 1 commit into
dagger:mainfrom
sipsma:chain-shell

Conversation

@sipsma

@sipsma sipsma commented Jan 10, 2024 •

Copy link
Copy Markdown
Contributor

This is one part of our efforts to consolidate dagger CLI commands. It removes dagger shell in favor of using a shell api chained from the core Container type.

For example, previously you'd do:
dagger shell my-ctr

Now you do:
dagger call my-ctr shell

This required some adjustments in the core API:

  1. Container has a new field withDefaultShell(args: [String!]) that can be used to configure the command to use for opening a shell with the container
  2. shellEndpoint: String! on Container is replaced with shell(args: [String!]) Terminal!.
    • If args are specified, they override the command to run in the container's shell
    • Otherwise, this defaults to the command specified via withDefaultShell
    • As a fallback, sh will be executed

Implementation details:

The new Terminal type currently only has a field for the existing websocket endpoint, so same basic idea as before in terms of how its implemented. However, because its an object now we have more leeway to easily adjust it in the future if more fields are desired.

This felt like the best solution possible in the short term while keeping options open in the long-term.

args is optional and allows specifying the exact command to run in the interactive container. If not set, it first defaults to the entrypoint of the container and falls back to sh if those aren't set.

@sipsma
sipsma requested a review from helderco January 10, 2024 22:47
@sipsma
sipsma requested review from a team as code owners January 10, 2024 22:47

@helderco helderco 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.

I love that this process reduces chances of conflict with extra flags in the CLI, moves the intention/verb to the end of the command and generally offloads more into core.

The TestModuleDaggerShell/args test failed due to a timeout, but tested the module locally and works well.

Comment thread core/schema/container.graphqls Outdated

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.

Even though this is technically a breaking change it should only have been used by the CLI so no need to flag the break (change log), right?

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.

Sorry just realized I never got back on this comment, but yes exactly correct.

@helderco helderco added this to the v0.9.7 milestone Jan 16, 2024
@shykes

shykes commented Jan 18, 2024 •

Copy link
Copy Markdown
Contributor

As you know, I'm fully on board with the idea of using chaining + core API to keep the number of CLI commands and flags as low as possible.

My only note is on the specifics of how shell decides what to execute. We already discussed this in Discord a while back, resurrecting the relevant parts here:

shykes:

Also Shell could use a simpler logic for determining what the hell gets executed (something that still confuses me with the current dagger shell). I think we should disregard entrypoint altogether, and just make it an argument to Shell, with a default value of sh if not specified
Things that would NOT affect what Container.Shell executes:

  • Past calls to Container.DefaultArgs
  • Past calls to Container.Entrypoint
  • Past calls to Container.WithExec
  • Entrypoint or Command in the base image

sipsma:

The one use case I sort of like having some default is if you want to drop right into a repl in the container, in which case it's nice if the container sets up the default for you. But I'm pretty low opinion here; I agree 100% on past calls to Container.WithExec not affecting it, and also agree that DefaultArgs is to confusing. I'd be okay with starting with Entrypoint not having any effect and going from there

shykes

Maybe there’s a WithDefaultShell?
I was brushing up on unix terminology for this stuff
We could have Container.Terminal(Shell Optional[string])

  • Container.WithDefaultShell
    Terminal(): open an interactive terminal to the container

How do you feel about the above @sipsma ?

@sipsma

sipsma commented Jan 20, 2024

Copy link
Copy Markdown
Contributor Author

How do you feel about the above @sipsma ?

@shykes Right yeah that's all coming back to me now :-) I like the idea of Container.WithDefaultShell and then not letting entrypoint/default-args affect any of this. I'll update with that.

@sipsma
sipsma requested review from helderco and shykes January 22, 2024 16:30
@sipsma

sipsma commented Jan 22, 2024

Copy link
Copy Markdown
Contributor Author

Updated to the withDefaultShell approach, PR description has new details on how it works

@shykes

shykes commented Jan 22, 2024

Copy link
Copy Markdown
Contributor

@sipsma how do you feel about this small bikeshedding change:

  • Before: shell: Terminal!
  • After: terminal: Terminal!

That clarifies the meaning of "shell" in the API:

  • The terminal is what you open and connect to for interactive sessions
  • The shell is the process you execute when opening a terminal

@sipsma

sipsma commented Jan 22, 2024

Copy link
Copy Markdown
Contributor Author

@sipsma how do you feel about this small bikeshedding change:

  • Before: shell: Terminal!
  • After: terminal: Terminal!

That clarifies the meaning of "shell" in the API:

  • The terminal is what you open and connect to for interactive sessions
  • The shell is the process you execute when opening a terminal

@shykes Yeah I considered the same thing but concluded that while it's more technically accurate, shell is faster to type than terminal in the CLI and thus I liked it a little bit more.

It's not that bad either way, really splitting hairs at this point. cc @helderco if you have any opinion either way.

This is one part of our efforts to consolidate dagger CLI commands. It
removes `dagger shell` in favor of using a `shell` api chained from the
core `Container` type.

For example, previously you'd do:
`dagger shell my-ctr`

Now you do:
`dagger call my-ctr shell`

This required some adjustments in the core API:
1. `Container` has a new field `withDefaultShell(args: [String!])` that
   can be used to configure the command to use for opening a shell with
   the container
1. `shellEndpoint: String!` on `Container` is replaced with
   `shell(args: [String!]) Terminal!`.
   * If `args` are specified, they override the command to run in the
     container's shell
   * Otherwise, this defaults to the command specified via
     `withDefaultShell`
   * As a fallback, `sh` will be executed

---

Implementation details:

The new `Terminal` type currently only has a field for the existing
websocket endpoint, so same basic idea as before in terms of how its
implemented. However, because its an object now we have more leeway to
easily adjust it in the future if more fields are desired.

This felt like the best solution possible in the short term while keeping
options open in the long-term.

`args` is optional and allows specifying the exact command to run in the
interactive container. If not set, it first defaults to the entrypoint of
the container and falls back to `sh` if those aren't set.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma

sipsma commented Jan 23, 2024

Copy link
Copy Markdown
Contributor Author

@shykes the overhead of keeping the PR open and rebasing etc. across all the others is getting to be a bit too much so I'm going to merge this one as is w/ shell, but happy to continue conversation about switching to terminal instead. It will be trivial to do in a followup if we decide to go that way.

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.

4 participants