Skip to content

platformVariants is unwieldy in modules #6675

Closed

Description

@jedevc

Using platformVariants is extremely unwieldy to use:

"""
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't terminal into a list of containers, or do any standard operation I might want to with it.
  • I also can't publish a 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:

  1. What happens to the contents before a WithVariant call? e.g. dag.Container().From("alpine").WithExec([]string{"echo", "foo"}).WithVariant(...).
    • It could become the default platform (unless that's later overridden, in a WithVariant call)
    • It could be completely invalid, WithVariant is only allowed as the first call in a Container, similar to From.
  2. What happens to WithExec calls after a WithVariant call? 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 Container that can't really be treated just like any other container.
  3. What happens to File access (and similar, like Entries) after a WithVariant call?
    • 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.

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.

cc @shykes @helderco @vito

Activity

  1. purpleclay commented on Mar 27, 2024

    @purpleclay
    Contributor

    @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?

  2. purpleclay commented on Mar 27, 2024

    @purpleclay
    Contributor

    @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?

    I found this old article, https://archive.docs.dagger.io/0.9/406009/multiplatform-support/

  3. jedevc commented on Jul 16, 2024

    @jedevc
    ContributorAuthor

    There was some discussion of this in discord: https://discord.com/channels/707636530424053791/1003718839739105300/1262464210823151638

    Quoting @sipsma:

    I don't think we can just have a single container be multiplatform. If you do a withExec then you'd be executing N containers (one for each platform, using qemu emulation when not matching the host platform), each of which have their own independent exitCode, stdout, stderr etc. which just doesn't make any sense at all with the Container API.

    IIRC I wanted to add a separate type for this like MultiplatformContainer but there were objections which left us in the state where you do the multiplatform publish with that weird arg that provides a list of platform variants.

    @shykes adds:

    Can I inject the question of interfaces here? 😁 what if Container were an interface and say ArmContainer, X86Container, MultiPlatformContainer were implementations?

  4. locked and limited conversation to collaborators on Mar 24, 2026
  5. converted this issue into a discussion #12434 on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions