Skip to content

core: Implicitly call entrypoint + defaultArgs when needed - #5039

Merged
helderco merged 4 commits into
dagger:mainfrom
helderco:engine/default-exec
Apr 28, 2023
Merged

helderco merged 4 commits into
dagger:mainfrom
helderco:engine/default-exec

Conversation

@helderco

@helderco helderco commented Apr 26, 2023 •

Copy link
Copy Markdown
Contributor

Fixes #4833, DAG-282

Before

You had to add an unintuitive WithExec(nil) to execute the entrypoint + defaultArgs, otherwise a “no command has been executed” error would be returned. This was confusing to some users.

_, err := client.Container().
    Build(src).
+   WithExec(nil).
    ExitCode(ctx)
db := client.Container().From("postgres").
     WithExposedPort(5432).
+    WithExec(nil)
ctr := app.WithServiceBinding("db", db)

After

Using ExitCode, Stdout, Stderr and WithServiceBinding will now implicitly add the WithExec(nil) to run default command:

// ✅ ExitCode → needs execution so use default exec
_, err := c.Container().From("alpine").ExitCode(ctx)
// ✅ WithServiceBinding → needs execution so use default exec
db := client.Container().From("postgres").WithExposedPort(5432)
ctr := app.WithServiceBinding("db", db)

Signed-off-by: Helder Correia

@helderco
helderco force-pushed the engine/default-exec branch 2 times, most recently from 7735071 to d3d09f4 Compare April 26, 2023 22:17
@helderco
helderco marked this pull request as ready for review April 27, 2023 11:11
@helderco
helderco marked this pull request as draft April 27, 2023 11:20
@helderco

Copy link
Copy Markdown
Contributor Author

I'm thinking container.Hostname() should also add WithExec(nil) otherwise it can become confusing.

@helderco
helderco force-pushed the engine/default-exec branch from d489e29 to 8bacbc8 Compare April 27, 2023 12:39
@helderco
helderco marked this pull request as ready for review April 27, 2023 12:52
@helderco
helderco requested a review from vito April 27, 2023 12:56
@helderco
helderco force-pushed the engine/default-exec branch from 8bacbc8 to f673079 Compare April 27, 2023 14:19
@helderco helderco linked an issue Apr 27, 2023 that may be closed by this pull request

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

This looks great! Just one nitpicky suggestion for one of the tests. Approving either way.

ep, err := srv.Endpoint(ctx)
require.NoError(t, err)

require.Equal(t, hn+":8000", ep)

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.

This seems like it would pass before the change, too. Maybe we could assert that the hostname is == to srv.WithExec(nil).Hostname(ctx) just to be super explicit?

edit: oh, I see you do that in another test below. Maybe that assertion could be moved here?

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.

This seems like it would pass before the change, too.

Not really. Before it would error. And this is making sure that both are adding WithExec(nil), not just one.

Notice that this test is replicating the one just above it, just replacing WithExec with WithDefaultArgs.

Maybe that assertion could be moved here?

Yes, if that makes it clearer. I added that later on. 🙂

Comment thread core/schema/container.go
return parent.WithExec(ctx, s.gw, s.baseSchema.platform, args.ContainerExecOpts)
}

func (s *containerSchema) withDefaultExec(ctx *router.Context, parent *core.Container) (*core.Container, 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.

I like this - handling it at the API layer keeps the core.Container type from having to just-in-time modify itself.

@vito

vito commented Apr 27, 2023 •

Copy link
Copy Markdown
Contributor

I'm thinking container.Hostname() should also add WithExec(nil) otherwise it can become confusing.

This is the kind of thing I was afraid of with Dagger having to figure out what you mean, but hopefully there aren't too many examples of this. I agree it seems sensible for it to assume the default command in these cases (Hostname and Endpoint).

@helderco

Copy link
Copy Markdown
Contributor Author

Yes, after learning a bit more on what actually happens I totally understand your arguments for not wanting this implicit behavior, especially after thinking about Hostname and Endpoint (like it was affecting parts I didn't think about).

I just remember the feeling of astonishment that the default command wasn't used, so I still think it's worth it to make it more intuitive.

Signed-off-by: Helder Correia <[email protected]>
@helderco
helderco merged commit 00540aa into dagger:main Apr 28, 2023
@helderco
helderco deleted the engine/default-exec branch April 28, 2023 10:53
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.

"Default exec"

2 participants