Repository navigation
Description
Using platformVariants is extremely unwieldy to use:
dagger/docs/docs-graphql/schema.graphqls
Lines 196 to 201 in fca9e78
| """ | |
| Identifiers for other platform specific containers. | |
| Used for multi-platform image. | |
| """ | |
| platformVariants: [ContainerID!] = [] |
The idea is that you can construct multiple Container objects, and then compose them to together on Publish/Export to push a multi-platform image.
However, this feels like a weird abstraction - quite often, in our own CI in this repo, we end up calling a single function multiple times with different arch values, and then get a list to compose myself later.
This kind of works today, but really starts to fall flat with modules:
- With modules, if I want to return a multi-platform image, I can't! I have to instead return a list of
Containers, and then manually compose them again later. This means that I have to have a dedicated function for this, since I can'tterminalinto a list of containers, or do any standard operation I might want to with it. - I also can't
publisha multi-platform image from the CLI - I can only do it from an SDK.
I think we should rework platformVariants from being an option for certain operations, we should make it a property on a Container.
It should be possible to "merge" various Container options together, potentially using a withVariant option:
armv8Container := makeContainer("linux/arm64/v8")
amd64Container := makeContainer("linux/amd64")
multiplatformContainer := dag.Container().
WithVariant(armv8Container).
WithVariant(amd64Container)
armv8ContainerAgain := multiplatformContainer.Variant("linux/arm64/v8")This keeps everything exactly as composable as before, while making it a property of the container. If I call Publish()/Export() on this container, I get a multi-platform image. If I attempt to run a container using AsService().Up() or Terminal(), then this should select the most appropriate image for a platform.
A couple potential things to think about:
- What happens to the contents before a
WithVariantcall? e.g.dag.Container().From("alpine").WithExec([]string{"echo", "foo"}).WithVariant(...).- It could become the default platform (unless that's later overridden, in a
WithVariantcall) - It could be completely invalid,
WithVariantis only allowed as the first call in aContainer, similar toFrom.
- It could become the default platform (unless that's later overridden, in a
- What happens to
WithExeccalls after aWithVariantcall? e.g.dag.Container().WithVariant(...).WithExec([]string{"echo", "foo"}).- It could attempt to apply the given call to every variant (this is kinda cool!)
- It could also just be invalid - but if this is returned from a zenith function, it feels odd to have a
Containerthat can't really be treated just like any other container.
- What happens to
Fileaccess (and similar, likeEntries) after aWithVariantcall?- We could propagate the knowledge of multi-platform variants down into
File/Directory(this does feel neat - but then we need to resolve all the above as well for those as well) - Or we could just select the "default" platform in these cases.
- We could propagate the knowledge of multi-platform variants down into
Feels like a potentially largish change, so very happy to bikeshed and discuss - and ofc, happy to hear alternative proposals - but I think we do need to do something, since the current CLI and multi-platform images are just so miserable to get working together.
Activity
purpleclay commentedon Mar 27, 2024
@jedevc I am experiencing this right now. I just migrated to Dagger Modules, and now I am faced with building a multi-platform container or reaching for a different tool altogether. I am heading down the road of calling a
Build()function twice, specifying different platform variants.I am currently stuck on how to reassemble both of these containers for publishing a multi-platform image. Do you happen to have any pointers?
purpleclay commentedon Mar 27, 2024
I found this old article, https://archive.docs.dagger.io/0.9/406009/multiplatform-support/
verdverm commentedon Jul 16, 2024
I have a case where RUN step in a Dotnet Dockerfile needs to know what arch it is for
https://github.com/hofstadter-io/hof/blob/_dev/formatters/tools/csharpier/Dockerfile.debian#L10
We then pass both arches to
docker buildxin a single callhttps://github.com/hofstadter-io/hof/blob/_dev/.github/workflows/fmt.yml#L45
I have no idea where the 3rd (unknown/unknown) arch is coming from... ¯_(ツ)_/¯
https://github.com/hofstadter-io/hof/pkgs/container/fmt-csharpier/226851539?tag=v0.6.9
jedevc commentedon Jul 16, 2024
There was some discussion of this in discord: https://discord.com/channels/707636530424053791/1003718839739105300/1262464210823151638
Quoting @sipsma:
@shykes adds: