OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.14k stars 587 forks source link

Failure when containerizing my project using Docker BuildX. Unable to create multi-arch images #26077

Closed Amshu-k closed 10 months ago

Amshu-k commented 1 year ago

Describe the bug
I've a Java project which uses the following Dockerfile:

FROM icr.io/appcafe/open-liberty@sha256:d85e1748a88d5ac4e516f4c91c5b98e941e5ddc4429c7f378695a1d9948b26a2

# ARG and ENV lines required to support both docker buildx/docker build 
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
ENV BUILDPLATFORM=${BUILDPLATFORM:-linux/amd64}
ENV TARGETOS=${TARGETOS:-linux}
ENV TARGETARCH=${TARGETARCH:-amd64}

ARG VERSION=1.0
ARG REVISION=SNAPSHOT

COPY --chown=1001:0 \
    src/main/liberty/config \
    /config/

RUN features.sh

COPY --chown=1001:0 \
    target/application-service.war \
    /config/apps

RUN configure.sh

Usually, to containerize my application, I do the following steps:

  1. mvn clean compile package
  2. docker build -t localhost:myapplication:latest . This works perfectly fine on my computer which is of arch amd64.

I want to create multi-arch image, but I'm running into issues here. I'm doing the following steps:

  1. mvn clean compile package
  2. I'm using the Docker BuildX feature to build a multi-arch image (amd64, s390x and ppc64le) with the following command:
    docker buildx build --progress=plain --push --platform linux/amd64,linuxs390x,linux/ppc64le -t localhost:myapplication:latest .

    The image build always fails at this point. (It fails for both ppc64le and s390x), The line RUN features.sh doesn't fail for amd64.

    > [linux/s390x 3/8] RUN features.sh:
    ------
    Dockerfile:32
    --------------------
    30 |         /config/
    31 |     
    32 | >>> RUN features.sh
    33 |     
    34 |     COPY --chown=1001:0 \

Steps to Reproduce

  1. mvn clean compile package
  2. docker buildx build --progress=plain --push --platform linux/amd64,linuxs390x,linux/ppc64le -t localhost:myapplication:latest .

Expected behavior
Docker image should be created using Docker BuildX

Diagnostic information:

I suspect that I need to execute the 1st step (mvn clean compile package) in the matching architecture for the second step to succeed.

My questions: Aren't the files created in the first step architecture agnostic? If not, then we cannot create images for other architectures.

leochr commented 1 year ago

As a first step, I'll suggest adding ARG VERBOSE=true to your Dockerfile (prior to RUN features.sh) and see if that provides any additional information about the failure

idlewis commented 1 year ago

To run features.sh in a crossplatform build, I would expect you to be using an emulator such as QEMU in your docker build. This is described in the docker documentation here: https://docs.docker.com/build/building/multi-platform/#qemu Can you confirm if that is what you are doing?

Although features.sh is script and hence cross platform, it needs the bash interpreter to run, and the interpreter is not cross platform and will be a native binary inside each container.

idlewis commented 10 months ago

Closing as there has been no further updates for 1 month.