Skip to content

Instantly share code, notes, and snippets.

@richlander
Created July 29, 2023 01:04
Show Gist options
  • Save richlander/973ac31c55ddef9476ff376c0eeee234 to your computer and use it in GitHub Desktop.
Save richlander/973ac31c55ddef9476ff376c0eeee234 to your computer and use it in GitHub Desktop.
Publish native AOT container images with the SDK -- look ma, no Dockerfile, no Clang

Publish native AOT container images with the SDK -- look ma, no Dockerfile, no Clang

This machine doesn't have and doesn't want clang. Can we push native aot images to a registry anyway? Of course.

Problem:

MSBuild version 17.8.0-preview-23377-03+24ee0c75a for .NET
  Determining projects to restore...
  Restored /home/rich/git/dotnet-docker/samples/releasesapi-aot/releasesapi.csproj (in 253 ms).
/home/rich/dotnet/sdk/8.0.100-rc.1.23378.3/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(314,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/home/rich/git/dotnet-docker/samples/releasesapi-aot/releasesapi.csproj]
  releasesapi -> /home/rich/git/dotnet-docker/samples/releasesapi-aot/bin/Release/net8.0/linux-x64/releasesapi.dll
/home/rich/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.0-rc.1.23376.5/build/Microsoft.NETCore.Native.Unix.targets(186,5): error : Platform linker ('clang' or 'gcc') not found in PATH. Ensure you have all the required prerequisites documented at https://aka.ms/nativeaot-prerequisites. [/home/rich/git/dotnet-docker/samples/releasesapi-aot/releasesapi.csproj]

Solution:

rich@vancouver:~/git/dotnet-docker/samples/releasesapi-aot$ docker run --rm -it -v $(pwd):/source -v /home/rich/.docker:/root/.docker -w /source mcr.microsoft.com/dotnet/aot-sdk:latest dotnet publish /p:PublishProfile=DefaultContainer /p:ContainerBaseImage=mcr.microsoft.com/dotnet/runtime-deps:8.0-preview-jammy-chiseled /p:ContainerRegistry=maplesugar.azurecr.io
MSBuild version 17.7.0+5785ed5c2 for .NET
  Determining projects to restore...
  Restored /source/releasesapi.csproj (in 4.77 sec).
/usr/share/dotnet/sdk/8.0.100-preview.6.23330.14/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(314,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/source/releasesapi.csproj]
  releasesapi -> /source/bin/Release/net8.0/linux-x64/releasesapi.dll
  releasesapi -> /source/bin/Release/net8.0/linux-x64/publish/
  Building image 'releasesapi' with tags latest on top of base image mcr.microsoft.com/dotnet/runtime-deps:8.0-preview-jammy-chiseled
  Uploading layer sha256:a253d5a1e257f9f936b736e65aea1c3a06188f403be94a81eb0ebf4159ed7445 to maplesugar.azurecr.io
  Uploading layer sha256:92328e46c4489e4eeb427a67f2fa60dbbf38b644e1d39dd9f57cb9bb386bfe6d to maplesugar.azurecr.io
  Finished uploading layer sha256:a253d5a1e257f9f936b736e65aea1c3a06188f403be94a81eb0ebf4159ed7445 to maplesugar.azurecr.io
  Finished uploading layer sha256:92328e46c4489e4eeb427a67f2fa60dbbf38b644e1d39dd9f57cb9bb386bfe6d to maplesugar.azurecr.io
  Uploading config to registry at blob sha256:0b10fe76d5b4115c14f649333b955f40cdc56519c81d153e91421f29d5dda137
  Uploaded config to registry
  Uploading manifest to registry maplesugar.azurecr.io as blob sha256:e358c641c830cecdc788a383e304cd80059fe875be11fdb2d2edc2dc808447af
  Uploaded manifest to maplesugar.azurecr.io
  Uploading tag latest to maplesugar.azurecr.io
  Uploaded tag latest to maplesugar.azurecr.io
  Pushed image 'maplesugar.azurecr.io/releasesapi:latest' to registry 'maplesugar.azurecr.io'
rich@vancouver:~/git/dotnet-docker/samples/releasesapi-aot$ 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment