Run a multiarch build using podman

When we want to create an image that can be deployed on multiple architectures we need to create an image with multi architecture support. For this project this time will use podman. In case you are using podman in a emulated environment like macosx for example where the podman machine will be a fedora coreos machine first you need to install the qemu-user-static package.

If running linux or any other environment where podman is not in emulated machine you can skip this section. After starting up the podman using podman machine start you need to ssh into the machine:

#podman machine ssh
#sudo su -
#rpm-ostree status
State: idle
Deployments:
  fedora:fedora/x86_64/coreos/next-devel
               Version: 36.20220511.dev.0 (2022-05-11T18:04:09Z)
                Commit: d2b9b4c6bca5a17034daa1a175420875f9d049db418212068e442c9fddd6fa7f
          GPGSignature: (unsigned)
#rpm-ostree install https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/36/Everything/x86_64/os/Packages/q/qemu-user-static-6.2.0-6.fc36.i686.rpm
...
#rpm-ostree status
Deployments:
* fedora:fedora/x86_64/coreos/next-devel
               Version: 36.20220511.dev.0 (2022-05-11T18:04:09Z)
            BaseCommit: d2b9b4c6bca5a17034daa1a175420875f9d049db418212068e442c9fddd6fa7f
          GPGSignature: (unsigned)
         LocalPackages: qemu-user-static-2:6.2.0-6.fc36.i686

 fedora:fedora/x86_64/coreos/next-devel
               Version: 36.20220511.dev.0 (2022-05-11T18:04:09Z)
                Commit: d2b9b4c6bca5a17034daa1a175420875f9d049db418212068e442c9fddd6fa7f
          GPGSignature: (unsigned)

Once qemu-user-static is installed you need to restart the podman machine by running:

#podman machine stop
#podman machine start

Now the podman is ready to create images with multi architecture support.
For this example I will be using a dockerfile for creating the openjdk:11 images.

#cat Dockerfile
FROM	alpine:3
LABEL	description="java 11"
ENV	TZ=UTC
RUN	apk add --no-cache bash openjdk11 libstdc++ ttf-dejavu fontconfig curl
CMD	["bash", "-c", "while true; do date; sleep 5; done"]
# podman build --manifest quay.io/.../openjdk:11 --rm --no-cache --platform linux/amd64 --platform linux/arm64 .
[linux/arm64] STEP 1/5: FROM alpine:3
[linux/arm64] STEP 2/5: LABEL	description="java 8"
--> 8d201aebead
[linux/arm64] STEP 3/5: ENV	TZ=UTC
--> 017b3e3d6b5
[linux/arm64] STEP 4/5: RUN	apk add --no-cache openjdk8 curl
...
[linux/arm64] COMMIT
--> 0f649f1d431
[linux/amd64] STEP 1/5: FROM alpine:3
...
[linux/amd64] COMMIT
--> d305fa9afb7
[Warning] one or more build args were not consumed: [TARGETARCH TARGETOS TARGETPLATFORM]
d305fa9afb7a08b9f457edd91413b255a7044e4468bfa86cdfe76311742dac9a
#podman manifest inspect quay.io/.../openjdk:11
podman manifest inspect quay.io/redcapcloud/openjdk:11
{
  "schemaVersion": 2,
  "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
  "manifests": [
    {
      "mediaType": "application/vnd.oci.image.manifest.v1+json",
      "size": 751,
      "digest": "sha256:3cd95636b8b01a68dd5bc690edccb359e1606808a9e75043f5ab1f02d6300235",
      "platform": {
        "architecture": "amd64",
        "os": "linux"
      }
    },
    {
      "mediaType": "application/vnd.oci.image.manifest.v1+json",
      "size": 751,
      "digest": "sha256:aca19b57709430e3fc7703b06c2761e8af33fce6170f0ff35b81503664c3c655",
      "platform": {
        "architecture": "arm64",
        "os": "linux",
        "variant": "v8"
      }
    }
  ]
}
#podman manifest push quay.io/.../openjdk:11 docker://quay.io/.../openjdk:11 --rm

Now you should see that in the quay.io repository you have an image with multiple childs.