redhat-actions / buildah-build

GitHub Action to use 'buildah' to build a container image.
https://github.com/marketplace/actions/buildah-build
MIT License
137 stars 35 forks source link

Muilt-arch doesn't seem to work #60

Closed vilgotf closed 3 years ago

vilgotf commented 3 years ago

Version

redhat-action/buildah-build@v2

Describe the bug

Using archs: amd64,arm64 I expect it to build amd64 & arm64 images (like the docs state), but the command that is run is incorrect according to the buildah docs (--arch takes only one argument but it is given two)

Steps to reproduce, workflow links, screenshots

https://github.com/vilgotf/voice-pruner/runs/3013577143

tetchel commented 3 years ago

I think this is the same issue as https://github.com/redhat-actions/buildah-build/issues/24#issuecomment-792000579

Can you try the workarounds detailed at the bottom, there?

vilgotf commented 3 years ago

Using matrix build doesn't work since that builds & pushes amd64 and then builds & pushes arm64 (overwriting amd64 instead of adding to it). Pulling the base images before issuing buildah bud ... resulted in the same error when running locally (F34, buildah 1.21.0)

Also: I find it weird that buildah's docs don't mention that --arch allows multiple arguments, is this really supported?

tetchel commented 3 years ago

OK, I see what you mean. I know we had some users in the past doing the comma-separated archs, but maybe it wasn't working and we/they just "thought" it was.

Try passing just one arch at a time, like you say the buildah docs specify, while I ask around.

tetchel commented 3 years ago

So, it seems to me there are two issues here.

  1. Passing multiple comma-separated arguments to arch. As far as I can tell, you can pass anything to arch you like. It does not actually affect what architecture the image uses. You have to use the FROM clause to do that.

I used the following Containerfile for testing:

ARG ARCH=amd64
FROM ${ARCH}/alpine:3.14

RUN echo "hello world"

ENTRYPOINT [ "sh", "-c", "uname -a && echo -n 'Bits: ' && getconf LONG_BIT && echo 'goodbye world'" ]

then:

export ARCH=arm64v8
export TAG=quay.io/tetchell/buildah-multiarch:latest
buildah bud -t $TAG --arch $ARCH --build-arg ARCH=$ARCH -f Containerfile

# Note, the uname "machine" is aarch64
podman run quay.io/tetchell/buildah-multiarch:latest
Linux 98c394deb27b 5.12.11-200.fc33.x86_64 #1 SMP Wed Jun 16 16:10:53 UTC 2021 aarch64 Linux
Bits: 64
goodbye world

podman inspect quay.io/tetchell/buildah-multiarch:latest
[
    {
...        
        "Architecture": "arm64v8",

https://github.com/docker-library/official-images#architectures-other-than-amd64

I definitely agree with you that the README is terribly misleading and I will remove the comma-separated example, and replace "archs" with "arch" but leave the plural input intact (but undocumented) so as not to break existing users.

  1. "overwriting amd64 instead of adding to it"

If you want multiple images referred to by the same tag, you have to use buildah's manifest feature, and then push the manifest, not just the images. This is presently not supported by this action, so you would have to write a script for those steps yourself after building the images.

https://github.com/containers/buildah/blob/main/docs/buildah-manifest.md

There is a great breakdown of multi-arch support in this issue. https://github.com/containers/buildah/issues/1590

vilgotf commented 3 years ago

Would be great if manifest could be added to this action! (I worked around this here)

divyansh42 commented 3 years ago

Done in https://github.com/redhat-actions/buildah-build/pull/62