Repository navigation
Multiplatform support - #3119
Conversation
77df16c to
376587d
Compare
👷 Deploy request for cloak-docs pending review.Visit the deploys page to approve it
|
shykes
left a comment
There was a problem hiding this comment.
Amazing that we can get this feature so quickly :) As we know from 0.2, this is one of the most consistently requested features.
I left a couple comments below.
540b7fe to
62c33f8
Compare
|
Just to update on this, focusing intensely on preview launch items, so this PR is suffering as a result. I think it will make the most sense to rebase this on top of the new API (Container/Directory/etc.). As part of that we can also get resolution on the issues discussed here: #3119 (comment) |
This comment was marked as outdated.
This comment was marked as outdated.
|
After writing the implementation more I'm resigning to an even simpler design. The problem with the previous one described in this older comment is that supporting A) The new platform only applies going forward for new steps in the containerThis just isn't very useful and is confusing. E.g. this would either fail or output the original default platform c.Container().From("alpine").WithPlatform("non-default-platform").Exec("uname -a").Stdout()B) The platform specified applies "retroactively" to the LLB DAG of the previous container steps.E.g. the following would result in the output of "non-default-platform" even though the non default platform was specified after you pulled the image and defined the exec: c.Container().From("alpine").Exec("uname -a").WithPlatform("non-default-platform").Stdout()This is more intuitive in some ways but ends up being an enormous rabbit hole for a number of different reasons both in terms of UX and implementation details. Mostly things involving mounts and requirements around cross-compilation where a directory/file needs to initially be the buildkit host platform but then converted into a different platform while not triggering a re-run of its history using emulation. I'm happy to explain more for anyone interested, not writing out in detail yet for sake of time. New even simpler solution: scalar Platform
extend type Query {
"""
The default platform of the builder.
"""
defaultPlatform: Platform!
"""
Load a container from ID.
Null ID returns an empty container (scratch).
Optional platform argument initializes new containers to execute and publish as that platform. Platform defaults to that of the builder's host.
"""
container(id: ContainerID, platform: Platform): Container!
}
type Container {
"the platform associated with the Container"
platform: Platform!
"same publish as before, but now with the option to include extra Containers that will be used as different platform variants in a multi-arch image."
publish(address: String!, platformVariants: [ContainerID!]) String
}Use CasesEmulated Build + Pushvar variants []dagger.ContainerID
for _, plat := range []string{"linux/amd64", "linux/arm64"} {
builtDir, _ := c.Container(plat).
From("builder:latest").
WithMountedDirectory("/src", srcDir).
WithMountedDirectory("/output", c.Directory()).
Exec("build /src -o /output").
Directory("/output")
variants = append(variants, c.Container(play).WithFS(builtDir).ID())
}
c.Container().Publish("my-multiarch-image:latest", variants)Emulated Testfor _, plat := range []string{"linux/amd64", "linux/arm64"} {
_, err := c.Container(plat).
From("builder:latest").
WithMountedDirectory("/src", srcDir).
Exec("build /src -o /output").
Exec("test /output/bin").
ExitCode(ctx)
if err != nil {
panic(err)
}
}Cross Compilation + Pushvar variants []dagger.ContainerID
for _, plat := range []string{"linux/amd64", "linux/arm64"} {
// NOTE: container has no platform override, so it is using the host platform
builtDir, _ := c.Container().From("builder:latest").
WithMountedDirectory("/src", srcDir).
WithMountedDirectory("/output", c.Directory()).
WithEnv("PLATFORM", plat).
Exec("build /src --platform $PLATFORM -o /output").
Directory("/output")
variants = append(variants, c.Container(plat).WithFS(builtDir).ID())
}
c.Container().Publish("my-multiarch-image:latest", variants)ExtensionsThe main reason I was avoiding this solution previously was that it puts extensions in a corner. This approach forces all extensions that output container/directory/file/etc. to always accept platform as an arg for their APIs and explicitly+correctly handle them. For instance, Alpine Build would have to accept platform because it returns Container. And every user extension ever written that returns or otherwise uses container will have to accept platform as an arg and handle it correctly.
The only viable solution to the above in the longer term that I can think of is the previous approach where we allow changing the default platform with a field right under Query. However, we can defer that for now. We can safely add it in the future and call it We can also consider just reverting back to that approach now too, though I agree it's more one-way-door-y than the approach of putting platform into Container+Directory APIs. |
c1eef42 to
6f23011
Compare
|
Pushed code implementing the highly simplified design. Unsurprisingly, the code is highly simplified too. Small TODOs/follow-ups listed in the description but it's working and ready to review. Please let me know if there's concerns with the API ASAP so any adjustments can be made early. The tests are good examples of how to us it for emulation, cross-compilation and for multiplatform image push: https://github.com/dagger/dagger/blob/11accbf00512cb890005c0d3bcbfe47349176b1b/core/integration/platform_test.go |
|
Sorry for being late to the party. Will try to sneak out and check it out over the weekend, or monday at the latest. |
6f23011 to
0c4c4f8
Compare
Agreed. We can find solutions for this later on. I think |
shykes
left a comment
There was a problem hiding this comment.
Makes sense, bummer that we can't use withPlatform but I understand the tradeoff. This is nice and simple.
Just a reminder that this is one of the most requested Dagger features since 0.1, and we never managed to ship it until now... So 1) this is an accomplishment to celebrate :) and 2) we should highlight it in the docs, for example with a guide. We should not assume users will find it on their own.
| // It's not incredibly efficient to call shimSource every time, but llb.State in general | ||
| // is not designed to handle being marshalled multiple times with different args (e.g. platform) | ||
| // and will fail in surprising ways. |
There was a problem hiding this comment.
😆 I was wondering if we would run into this, I remember hitting it too.
Includes emulation support, support for cross-compilation (converting host dirs into other platforms) and multiplatform image push. Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
11accbf to
8680fda
Compare
Signed-off-by: Erik Sipsma [email protected]
See comment on simplified design based on new API here: #3119 (comment)
Followups ups (after PR)