0

As it is right now, it's possible to docker build an image using the community.docker collection:

(Example from documentation)

- name: Build an image and push it to a private repo
  community.docker.docker_image:
    build:
      path: ./sinatra
    name: registry.ansible.com/chouseknecht/sinatra
    tag: v1
    push: yes
    source: build

My question is simple. According to their documentation, the platform field only seems to allow for one architecture:

Platform in the format os[/arch[/variant]].

(Notice "platform" and not "platforms" and that type is "string" and not a list of strings)

Is it possible to multiarch build (for example, an amd64 and arm) using the community.docker collection? Of course, I can use shell/command instead using something like:

- name: Multiarch build
  shell: |
    docker buildx build --platform amd64,arm --push -t myimage .

But is it possible using what's available now within the collection?

Blender Fox
  • 4,442
  • 2
  • 17
  • 30
  • What you could try is, add a `loop/with_items` statement including the list of your platforms. – user1098490 Feb 03 '22 at 10:17
  • If I understand your comment, that would only make an image specific to one platform -- each loop would override the previous image. So if looped with `amd64` then `arm`, I would end up with one image, for `arm` only and not a multiarch image that covers both architectures. – Blender Fox Feb 03 '22 at 10:49
  • Alright, it might be my understanding of docker and the use of `--platform` which is unclear. So docker won't create two images ?. After checking `docker buildx build --help` shows `--platform stringArray`, have you tried supply a stringArray to the `platform` options in the module? – user1098490 Feb 03 '22 at 11:02
  • `docker buildx build --platform {a,b,c}` will build a single image but build it for multiple architectures. When docker does a pull, it will try to pull the version of that image that matches the architecture of the running host, or the only one available if there is no others. I don't see a way of doing this with the current docker collection – Blender Fox Feb 03 '22 at 11:14

1 Answers1

0

I'm new to using Ansible to building Docker images, but I wanted to do this too and agree that specifying multiple platforms doesn't appear to be supported, so I put in a feature request on their GitHub here: https://github.com/ansible-collections/community.docker/issues/467.

Just to see what happened, I tried setting build.platform to "linux/arm64,linux/amd64", and the answer is that nothing happens. Ansible said that it was okay and nothing changed, even when I made an edit to the Dockerfile that should've triggered a build. I found that the same happens if I specify an invalid platform name.