dotnet / sdk-container-builds

Libraries and build tooling to create container images from .NET projects using MSBuild
https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container
MIT License
180 stars 39 forks source link

The AOT containerization story is too difficult #516

Open baronfel opened 1 year ago

baronfel commented 1 year ago

Right now the AOT stack + this tooling makes it easy to package an AOT'd application for one OS/Arch - the current one. Other OS/arch combinations are blocked by the Native AOT requirement to be on that OS/arch. There are AOT-provisioned .NET SDK container images available starting in .NET 8 that can be used to generate images for:

but it take a bit of finagling. Here's an example of a command that can be used to generate an image using these SDK images, pushing to github registry:

docker run --rm --pull=always \
          -v $(pwd)/src:/src \
          -v ~/.docker/config.json:/root/.docker/config.json:ro \
          -w /src/aot-sample \
          mcr.microsoft.com/dotnet/nightly/sdk:8.0-jammy-aot \
          sh -c "
            dotnet publish /t:PublishContainer \
              -p ContainerRegistry=ghcr.io \
              -p ContainerRepository=baronfel/aot-sample \
              -p ContainerImageTag=jammy-x64 \
              --use-current-runtime"

The full example can be seen at baronfel/sdk-container-demo.

There's a lot going on here:

This is a lot of coordination. We should provide some kind of orchestration here to make it easier to do these AOT steps in these containerized environments to reduce the pain of adopting AOT.

cc @davidfowl @richlander

baronfel commented 1 year ago

I was thinking on this last night, and there may not be a specific dependency on the container targets here - really the logic could look something like: