0

I'm maintaining an .net 6 web api application.

It's being deploy as a docker/OCI image built using buildah.

Until now there's only been built images for amd64. A few member of our team is using Macs with apple silicon, and would like to be able to pull built images, that are natively compatible with the ARM CPU in our machines.

We're able to build the image locally and deploy it to our local Rancher Desktop cluster, but it's a somewhat cumbersome task to do this individually, when a build server (potentially) could do it for you.

I've tried to update the way the image is built:

buildah bud --jobs=2 --platform=linux/arm64,linux/amd64 --storage-driver overlay --isolation chroot --manifest ${imageName}:${TAG} -f ${dockerFilePath} ${context}
buildah manifest push --all --rm ${imageName}:${TAG} docker://${registry}/${imageName}:${TAG}

and it looks like it's working. In our registry I can see both an amd64 and arm64 image.

Buildah host should have QEMU-user-static installed. The dockerfile for the buildah image:

FROM fedora:38

RUN dnf upgrade -y
RUN dnf install -y qemu-user-static
RUN dnf install -y buildah

But when I pull the image and try to start it, I get the following exception: System.BadImageFormatException: Could not load file or assembly '{project dll}'. An attempt was made to load a program with an incorrect format.

It looks to me like there's some incompatibility with the built artifacts and the runtime in the image.

Dockerfile:

FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0-alpine as build
ARG TARGETARCH

# Include XML documentation files in NuGet output
ENV NUGET_XMLDOC_MODE=none

WORKDIR /build

... COPY statements ... (omitted)

WORKDIR /build/{project folder}

# I read somewhere that .NET runtime identifier couldn't understand "amd64". (can't find the link)
RUN if [ "$TARGETARCH" = "amd64" ]; then \
    RESOLVEDARCH="x64" ; \
    else \
    RESOLVEDARCH="${TARGETARCH}" ; \
    fi \
    &&  dotnet restore -r linux-$RESOLVEDARCH --ignore-failed-sources -s https://api.nuget.org/v3/index.json -s {link to internal nuget repository}

RUN if [ "$TARGETARCH" = "amd64" ]; then \
    RESOLVEDARCH="x64" ; \
    else \
    RESOLVEDARCH="${TARGETARCH}" ; \
    fi \
    && dotnet publish -r linux-$RESOLVEDARCH --no-restore --configuration Release --no-self-contained -o /app .

FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine

WORKDIR /app
COPY --from=build /app .

ENTRYPOINT [ "dotnet", "{project}.dll" ]

Anyone who's experienced (and solved) anything similar?

ComkeenDk
  • 181
  • 1
  • 1
  • 8

0 Answers0