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

Support .NET Native Container Image build #2632

Closed
bradygaster opened this issue Aug 15, 2023 · 5 comments · Fixed by #4573
Closed

Support .NET Native Container Image build #2632

bradygaster opened this issue Aug 15, 2023 · 5 comments · Fixed by #4573
Assignees
Labels
aca Azure Container Apps inner loop
Milestone

Comments

@bradygaster
Copy link

As of .NET 7, .NET developers can build their apps into containers natively. It would be great if, when using AZD in the absence of Docker, that an image could be built natively.

I'm not sure an ACR push could be implemented without Docker on the machine, but, if there's a way AZD could support .NET's native container features, it'd be great.

@savannahostrowski
Copy link

@weikanglim This seems also, in spirit, related to our Buildpack work. Wondering if you have thoughts here.

Buildpacks currently require Docker on the user's machine.

@rajeshkamal5050 rajeshkamal5050 added this to the Germanium milestone Aug 16, 2023
@rajeshkamal5050 rajeshkamal5050 added aca Azure Container Apps inner loop labels Aug 16, 2023
@weikanglim
Copy link
Contributor

weikanglim commented Aug 16, 2023

If Azure Container App service ends up supporting remote build in the future, the containerization could happen remotely which wouldn't require docker installed. Users will do development locally without containerization.

Otherwise, I could see how the native MSBuild/.NET solution for source-to-container ends up being a better experience for developers already familiar with MSBuild. The minimal support to enable this is a property we can set when invoking dotnet publish to include a filepath for writing out the built docker image ID. That way azd can pick up the newly built image before pushing.

@baronfel
Copy link
Member

Note that starting in .NET 8 RC1 we will fully support pushing directly to ACR as part of the publish - so if you prefer you could sidestep any usage of Docker locally for .NET projects. The big blocker for us was supporting Docker OAuth Token Authentication (we only had username/password and non-Oauth token methods before).

Happy to work with you all to enable any data points neccesary to make this happen!

@spboyer
Copy link
Member

spboyer commented Oct 25, 2023

Using the following command dotnet publish --os linux --arch x64 /t:PublishContainer -c Release as an example, we can use .NET SDK to produce the image build locally in lieu of Docker. For any .NET 7+ applications, this should be the default for local builds.

More info on .NET Publish as Container

@rajeshkamal5050 rajeshkamal5050 modified the milestones: Germanium, On Deck Mar 22, 2024
ellismg added a commit to ellismg/azure-dev that referenced this issue May 24, 2024
When deploying to a host that requires a container image, if the
`language` of a project was `dotnet` we required the use of Docker to
both build and push the container image. If the user had not authored
a Dockerfile, we would try to use Oryx to build the container image
"from source".

With .NET 8, the SDK itself now has good support for both building a
container image for an app and pushing it to a remote registry. We
leveraged this for our Aspire work but non Aspire dotnet projects
couldn't leverage this.

This change fixes the situation. If your language is `dotnet` and your
host requires a container, we'll now use `dotnet publish
/t:PublishContainer` to build and push the container image.

This does mean that the typical "Build" and "Package" steps behave
differently for these apps now.  Since our "Publish" step now both
builds and pushes the container image, we defer the the work we would
have done in "Build" and "Package" into the "Publish" step. Doing this
allows us to eschew the need for a local Docker daemon to be installed
and running.

The .NET tooling does support creating a `.tgz` which could later be
`docker load`'ed, and you could imagine that "Build" or "Package"
produces such a thing, but doesn't allow us to use this as the input
to a publish, so for now we don't spend time producing this artifact
which would be unused by the downstream publish step.

Fixes Azure#2632
@ellismg ellismg assigned ellismg and unassigned weikanglim Aug 8, 2024
@ellismg ellismg modified the milestones: On Deck, Dilithium, Aug 2024 Aug 8, 2024
@ellismg
Copy link
Member

ellismg commented Aug 8, 2024

I had a draft of this in #3954 and will continue along with that, so I'm taking this one from you for now, @weikanglim.

@rajeshkamal5050 rajeshkamal5050 modified the milestones: Aug 2024, Sep 2024 Aug 21, 2024
@ellismg ellismg modified the milestones: Sep 2024, Oct 2024 Oct 14, 2024
@rajeshkamal5050 rajeshkamal5050 modified the milestones: Oct 2024, Nov 2024 Nov 8, 2024
ellismg added a commit to ellismg/azure-dev that referenced this issue Nov 21, 2024
The `dotnet` tool has native support for producing (and pushing) a
container image. This does not require a local docker daemon and in
general "does the right thing" and is the prefered way for .NET
customers to produce container
images. https://learn.microsoft.com/dotnet/core/docker/publish-as-container
gives a good overview of how this support works and we've been using
it to build and push container images for Aspire apps.

This change updates things such that we can use this support when
building a non Aspire based .NET app. If a `Dockerfile` exists, we
respect it, but otherwise instead of trying to use Oryx to produce a
container image, we will use `dotnet publish`.

A new recorded test was added - it builds on top of the existing
`containerapp` sample, and the test aranges to remove the `Dockerfile`
file from the template before running `up`.

Fixes Azure#2632
ellismg added a commit to ellismg/azure-dev that referenced this issue Nov 22, 2024
The `dotnet` tool has native support for producing (and pushing) a
container image. This does not require a local docker daemon and in
general "does the right thing" and is the prefered way for .NET
customers to produce container
images. https://learn.microsoft.com/dotnet/core/docker/publish-as-container
gives a good overview of how this support works and we've been using
it to build and push container images for Aspire apps.

This change updates things such that we can use this support when
building a non Aspire based .NET app. If a `Dockerfile` exists, we
respect it, but otherwise instead of trying to use Oryx to produce a
container image, we will use `dotnet publish`.

A new recorded test was added - it builds on top of the existing
`containerapp` sample, and the test aranges to remove the `Dockerfile`
file from the template before running `up`.

Fixes Azure#2632
ellismg added a commit to ellismg/azure-dev that referenced this issue Nov 22, 2024
The `dotnet` tool has native support for producing (and pushing) a
container image. This does not require a local docker daemon and in
general "does the right thing" and is the prefered way for .NET
customers to produce container
images. https://learn.microsoft.com/dotnet/core/docker/publish-as-container
gives a good overview of how this support works and we've been using
it to build and push container images for Aspire apps.

This change updates things such that we can use this support when
building a non Aspire based .NET app. If a `Dockerfile` exists, we
respect it, but otherwise instead of trying to use Oryx to produce a
container image, we will use `dotnet publish`.

In addition, we now use 8080 as the default port of a `dotnet` based
application (with no Dockerfile) as that's the default port used by
the standard ASP.NET base image.

A new recorded test was added - it builds on top of the existing
`containerapp` sample, and the test aranges to remove the `Dockerfile`
file from the template before running `up`.

Fixes Azure#2632
Fixes Azure#4583
ellismg added a commit that referenced this issue Nov 22, 2024
The `dotnet` tool has native support for producing (and pushing) a
container image. This does not require a local docker daemon and in
general "does the right thing" and is the prefered way for .NET
customers to produce container
images. https://learn.microsoft.com/dotnet/core/docker/publish-as-container
gives a good overview of how this support works and we've been using
it to build and push container images for Aspire apps.

This change updates things such that we can use this support when
building a non Aspire based .NET app. If a `Dockerfile` exists, we
respect it, but otherwise instead of trying to use Oryx to produce a
container image, we will use `dotnet publish`.

In addition, we now use 8080 as the default port of a `dotnet` based
application (with no Dockerfile) as that's the default port used by
the standard ASP.NET base image.

A new recorded test was added - it builds on top of the existing
`containerapp` sample, and the test aranges to remove the `Dockerfile`
file from the template before running `up`.

Fixes #2632
Fixes #4583
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aca Azure Container Apps inner loop
Projects
None yet
7 participants