Building my application on ARM and 32bits machine in same time?

Hello guys!

I’m having a problem building my Raspberry PI application for multiple containers.

In one of the containers I have a multi-stage build for a web application with React and WPE Webkit. The container build process succeeds.

On the other I have a multi-stage build for an application in C# Mono, however I have problems in the first compile step that does not work on an ARM machine.

Is it possible to merge the two architectures using resin.io in the build of my application containers?

My Dockerfile:


FROM resin/raspberrypi3-debian:stretch as builder #This not working... :( I need a not ARM machine here
WORKDIR /usr/src/app
RUN apt update && apt install -y apt-transport-https dirmngr \
     && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
     && echo "deb https://download.mono-project.com/repo/debian stable-stretch main" | tee /etc/apt/sources.list.d/mono-official-stable.list \
     && apt update && apt-get install -y mono-devel
ADD . ./
RUN msbuild /t:Build /p:Configuration=Release

FROM resin/raspberrypi3-debian:stretch
WORKDIR /usr/app
RUN apt update && apt install -y apt-transport-https dirmngr \
      && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
     && echo "deb https://download.mono-project.com/repo/debian stable-raspbianstretch main" | tee /etc/apt/sources.list.d/mono-official-stable.list \
     && apt update && apt-get install -y mono-devel \
     && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/src/app/MyApplication/bin/Release /usr/app
CMD ["mono", "./MyApplication.exe"]

Currently I build on my machine and I commit the binary file, but I want to escape this process.

Can someone help me?

Hi,

I tried to reproduce this with a simple hello world Mono application and the problem I found when building it, was that msbuild is not available in this step:

RUN msbuild /t:Build /p:Configuration=Release

After checking the mono-devel package, it seems like it only recommends the msbuild package, but does not depend on it, so msbuild is not available in the container at that time. I was able to get the builder working by also installing msbuild

RUN apt update && apt install -y apt-transport-https dirmngr \
 && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
 && echo "deb https://download.mono-project.com/repo/debian stable-stretch main" | tee /etc/apt/sources.list.d/mono-official-stable.list \
 && apt update && apt-get install -y mono-devel msbuild 

If my response is not really helping, can you give use more details on what exactly is failing and provide us with a small example, so that we can investigate the problem.

Cheers,
Andreas

Hello @afitzek!

Thanks for your help!

I created a new project on resin and a new on visual studio for mac and try to build with this
Dockerfile:

FROM resin/raspberrypi3-debian:stretch as builder
WORKDIR /usr/src/app
RUN apt-get update && apt-get install -y apt-transport-https dirmngr \
    && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
    && echo "deb https://download.mono-project.com/repo/debian stable-stretch main" | tee /etc/apt/sources.list.d/mono-official-stable.list \
    && apt-get update && apt-get install -y mono-devel msbuild
ADD . ./
RUN msbuild /t:Build /p:Configuration=Release

FROM resin/raspberrypi3-debian:stretch
WORKDIR /usr/app
RUN apt update && apt install -y apt-transport-https dirmngr \
    && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
    && echo "deb https://download.mono-project.com/repo/debian stable-raspbianstretch main" | tee /etc/apt/sources.list.d/mono-official-stable.list \
    && apt update && apt-get install -y mono-devel \
    && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/src/app/MyProject/bin/Release /usr/app
CMD ["mono", "./MyProject.exe"]

My result is this:

I changed the Dockerfile to build on my mac(I switched from resin debian to oficial debian)

FROM debian:stretch as builder
WORKDIR /usr/src/app
RUN apt-get update && apt-get install -y apt-transport-https dirmngr \
    && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
    && echo "deb https://download.mono-project.com/repo/debian stable-stretch main" | tee /etc/apt/sources.list.d/mono-official-stable.list \
    && apt-get update && apt-get install -y mono-devel msbuild
ADD . ./
RUN msbuild /t:Build /p:Configuration=Release

FROM debian:stretch
WORKDIR /usr/app
RUN apt update && apt install -y apt-transport-https dirmngr \
    && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
    && echo "deb https://download.mono-project.com/repo/debian stable-raspbianstretch main" | tee /etc/apt/sources.list.d/mono-official-stable.list \
    && apt update && apt-get install -y mono-devel \
    && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/src/app/MyProject/bin/Release /usr/app
CMD ["mono", "./MyProject.exe"]

The msbuild works as expected and the container works!

This leads me to believe that my problem is with the machine architecture used at the time of the build. In the case of my real application, I have several unsupported platform errors returned by msbuild, however if I build the project on my mac and run in raspberry the application works normally.

I will test using a raspbian image, but I have no ideas how to work around this problem … :frowning:

Any idea?

Hi @augustopimenta!

If you’re okay with building the image locally, you can try doing this:

FROM debian:stretch as builder
... run the build steps

FROM resin/raspberrypi3-debian:stretch
RUN [ "cross-build-start" ]
... run additional build steps
RUN [ "cross-build-end" ]
CMD ["mono", "./MyProject.exe"]

This will allow you to run the ARM part of the build emulated on your machine, and you can use balena build and balena deploy on our CLI to deploy this to your fleet (see https://www.balena.io/docs/reference/cli/#build-source- )