Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish linux/arm64 images #564

Open
davidmortiz opened this issue Jul 23, 2024 · 3 comments
Open

Publish linux/arm64 images #564

davidmortiz opened this issue Jul 23, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@davidmortiz
Copy link

davidmortiz commented Jul 23, 2024

Is your feature request related to a problem? Please describe.
A number of developers are now doing .NET development on Windows and Mac machines that aren't x86. I've noticed that you do offer ARM64 builds of Grate but only x86 docker images. QEMU emulation is fairly slow and doesn't appear to be officially supported by the .NET framework. It would be great to have native ARM images to get rid of emulation layer entirely from our local development process.

Describe the solution you'd like
Grate should publish linux/arm64 images

Describe alternatives you've considered
Alternatively, you could provide Alpine packages which would be sufficient as well but slightly less convenient as mentioned in #81

Additional context

@erikbra
Copy link
Owner

erikbra commented Jul 24, 2024

Yes, definitely :) (I work on arm64 a lot myself). I have looked at this one: https://www.meziantou.net/create-a-multi-arch-docker-image-for-a-dotnet-application.htm, but haven't got around to actually doing it yet. It is probably a lot easier now that we have M1 build agents available in github

@erikbra erikbra added the enhancement New feature or request label Jul 24, 2024
@erikbra
Copy link
Owner

erikbra commented Jul 24, 2024

This one was a bit more complex than first thought, as there are no github actions runners that run on arm64 that have docker installed (the M1 agents don't have docker installed), so I'll need to migrate to using the dotnet publish to docker feature. This probably takes a bit more time, to make the image compatible

@JaDuyve
Copy link
Contributor

JaDuyve commented Dec 11, 2024

Hi @erikbra,

I was wondering if adding these two small changes to Dockerfile and build.yml workflow would enable building the docker image for linux/arm64 and linux/amd64 architecture.
I find this blog post an interesting guide https://devblogs.microsoft.com/dotnet/improving-multiplatform-container-support/

Change to Dockerfile

During build of docker image the environment variables $TARGETOS and $TARGETARCH are by default provided. If nothing if added to build commando it will contain the values of what the build environment contains. By adding the platform parameter to the docker build commando you can influence what these 2 environment variables will contain and what the architecture the bases will be (ex. --platform linux/amd64 or --platform linux/arm64)

I think this should work as the GitHub Action runs on ubuntu-latest.

Altering this line

RUN dotnet publish ./src/grate/grate.csproj --os $OS --arch $ARCH -c release --self-contained -p:SelfContained=true -o ./publish/app

With this line

RUN dotnet publish ./src/grate/grate.csproj --os $TARGETOS --arch $TARGETARCH -c release --self-contained -p:SelfContained=true -o ./publish/app

Change to build.yml workflow

uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355

By adding

    - name: Build and push Docker image
      uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
      with:
        file: ./installers/docker/Dockerfile
        context: .
        platforms: linux/amd64,linux/arm64  # add this line
        push: true
        tags: ${{ steps.meta.outputs.tags }}
        labels: ${{ steps.meta.outputs.labels }}

More information you can find here https://docs.docker.com/build/ci/github-actions/multi-platform/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants