New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
engine: nested exec simplifications and service fixes #7213
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aaa722f
engine: consolidate IDs and re-use servers for nested execs
sipsma adc52ea
namespace services by server, not by client
vito a8785b8
fix routing of host services to correct client
sipsma df07531
deregister secret tokens once client disconnects
sipsma 67c1050
add integ test coverage
sipsma File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5628,6 +5628,118 @@ func TestModuleUnicodePath(t *testing.T) { | |
require.JSONEq(t, `{"test":{"hello":"hello"}}`, out) | ||
} | ||
|
||
func TestModuleStartServices(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😍 |
||
t.Parallel() | ||
|
||
// regression test for https://github.com/dagger/dagger/pull/6914 | ||
t.Run("use service in multiple functions", func(t *testing.T) { | ||
t.Parallel() | ||
c, ctx := connect(t) | ||
|
||
out, err := c.Container().From(golangImage). | ||
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). | ||
WithWorkdir("/work"). | ||
With(daggerExec("init", "--source=.", "--name=test", "--sdk=go")). | ||
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ | ||
Contents: `package main | ||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
type Test struct { | ||
} | ||
func (m *Test) FnA(ctx context.Context) (*Sub, error) { | ||
svc := dag.Container(). | ||
From("python"). | ||
WithMountedDirectory( | ||
"/srv/www", | ||
dag.Directory().WithNewFile("index.html", "hey there"), | ||
). | ||
WithWorkdir("/srv/www"). | ||
WithExposedPort(23457). | ||
WithExec([]string{"python", "-m", "http.server", "23457"}). | ||
AsService() | ||
ctr := dag.Container(). | ||
From("alpine:3.18.6"). | ||
WithServiceBinding("svc", svc). | ||
WithExec([]string{"wget", "-O", "-", "http://svc:23457"}) | ||
out, err := ctr.Stdout(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if out != "hey there" { | ||
return nil, fmt.Errorf("unexpected output: %q", out) | ||
} | ||
return &Sub{Ctr: ctr}, nil | ||
} | ||
type Sub struct { | ||
Ctr *Container | ||
} | ||
func (m *Sub) FnB(ctx context.Context) (string, error) { | ||
return m.Ctr. | ||
WithExec([]string{"wget", "-O", "-", "http://svc:23457"}). | ||
Stdout(ctx) | ||
} | ||
`, | ||
}). | ||
With(daggerCall("fnA", "fnB")). | ||
Stdout(ctx) | ||
require.NoError(t, err) | ||
require.Equal(t, "hey there", strings.TrimSpace(out)) | ||
}) | ||
|
||
// regression test for https://github.com/dagger/dagger/issues/6951 | ||
t.Run("service in multiple containers", func(t *testing.T) { | ||
t.Parallel() | ||
c, ctx := connect(t) | ||
|
||
_, err := c.Container().From(golangImage). | ||
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). | ||
WithWorkdir("/work"). | ||
With(daggerExec("init", "--source=.", "--name=test", "--sdk=go")). | ||
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ | ||
Contents: `package main | ||
import ( | ||
"context" | ||
) | ||
type Test struct { | ||
} | ||
func (m *Test) Fn(ctx context.Context) *Container { | ||
redis := dag.Container(). | ||
From("redis"). | ||
WithExposedPort(6379). | ||
AsService() | ||
cli := dag.Container(). | ||
From("redis"). | ||
WithoutEntrypoint(). | ||
WithServiceBinding("redis", redis) | ||
ctrA := cli.WithExec([]string{"sh", "-c", "redis-cli -h redis info >> /tmp/out.txt"}) | ||
file := ctrA.Directory("/tmp").File("/out.txt") | ||
ctrB := dag.Container(). | ||
From("alpine"). | ||
WithFile("/out.txt", file) | ||
return ctrB.WithExec([]string{"cat", "/out.txt"}) | ||
} | ||
`, | ||
}). | ||
With(daggerCall("fn", "stdout")). | ||
Sync(ctx) | ||
require.NoError(t, err) | ||
}) | ||
} | ||
|
||
func daggerExec(args ...string) dagger.WithContainerFunc { | ||
return func(c *dagger.Container) *dagger.Container { | ||
return c.WithExec(append([]string{"dagger", "--debug"}, args...), dagger.ContainerWithExecOpts{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 - I think this comment has been outdated for a while, should be fine to simplify. I might have only even noticed it while testing Bass's Dockerfile
# syntax
support, which has always been janky because of weird Docker <-> Buildkit <-> buildx versioning weirdness anyway (oci-layout://
source doesn't work for example, so no Container.import). Either way, the c2c networking code doesn't use a networks API cap anymore.edit: oh wait, this is my own change lol. well I APPROVE