-
Notifications
You must be signed in to change notification settings - Fork 152
Content for .NET Aspire - Release 8.1 #1384
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
Merged
Merged
Changes from 25 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
d7e7faa
Initial placeholder bits, to let other's help out
IEvangelist 3d1b0b9
Fix MD lint
IEvangelist 92fc076
Add elasticsearch bits
IEvangelist 62c943a
Add Redis host includes
IEvangelist d52b45c
Fix hosting packages
IEvangelist 69beee2
Fix the host toggles for zones
IEvangelist 51db798
Dockerfile docs.
mitchdenny e1d4c07
Add note for event hubs emulator.
mitchdenny 9d8d147
WIP: Python.
mitchdenny 0dcf2b9
Update the zone name
IEvangelist 4c395ae
Fix the 'missed one' :P
IEvangelist c098966
Sync Elasticsearch
IEvangelist 17908d7
Edit pass on withdockerfile content
IEvangelist 0ccb22d
Add Milvus
IEvangelist bcbbf72
Add Milvus to TOC
IEvangelist d557f53
A bit of clean for python
IEvangelist 67af292
Apply suggestions from code review
IEvangelist c4b6436
Added logos and overview entries
IEvangelist 73eeb56
Fix image
IEvangelist 240bcc0
Add snippets and address https://github.com/dotnet/docs-aspire/issues…
IEvangelist b479a5b
Lots of updates
IEvangelist 0f179f9
Getting closer but still broken
IEvangelist e61b938
Rename a bit
IEvangelist 757340d
A few more updates
IEvangelist 084dba8
Finialize python doc with screenshot.
mitchdenny 2742988
Apply suggestions from code review
IEvangelist f2bfa44
Let's go, looking good
IEvangelist b77c406
Add a section in the overview detailing RESP
IEvangelist d26b01b
Add Keycloak
IEvangelist e6db24d
A quick edit pass
IEvangelist 3eee16d
Added resource types
IEvangelist 45adb30
Add Azure Web PubSub component
IEvangelist a8a3545
Touch dates
IEvangelist 28b3dab
Bump all versions
IEvangelist 6c66e02
Fix alt-text
IEvangelist 074e36b
A few API fixes
IEvangelist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Python virtual environments | ||
.venv | ||
|
||
docs/_build/ | ||
.idea/ | ||
*.swp | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,7 @@ | |
"Docker", | ||
"Dockerfile", | ||
"EF Core", | ||
"Elasticsearch", | ||
"Entity Framework Core", | ||
"Git", | ||
"GitHub", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
--- | ||
title: Add Dockerfiles to your .NET app model | ||
description: Learn how to add Dockerfiles to your .NET app model. | ||
ms.date: 07/22/2024 | ||
--- | ||
|
||
# Add Dockerfiles to your .NET app model | ||
|
||
With .NET Aspire it's possible to specify a _Dockerfile_ to build when the [app host](../fundamentals/app-host-overview.md) is started using either the <xref:Aspire.Hosting.ResourceBuilderExtensions.AddDockerfile%2A> or <xref:Aspire.Hosting.ResourceBuilderExtensions.WithDockerfile%2A> extension methods. | ||
|
||
## Add a Dockerfile to the app model | ||
|
||
In the following example the <xref:Aspire.Hosting.ResourceBuilderExtensions.AddDockerfile%2A> extension method is used to specify a container by referencing the context path for the container build. | ||
|
||
```csharp | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var container = builder.AddDockerfile( | ||
"mycontainer", "relative/context/path"); | ||
``` | ||
|
||
Unless the context path argument is a rooted path the context path is interpreted as being relative to the app host projects directory (where the AppHost `*.csproj` folder is located). | ||
|
||
By default the name of the _Dockerfile_ which is used is `Dockerfile` and is expected to be within the context path directory. It's possible to explicitly specify the _Dockerfile_ name either as an absolute path or a relative path to the context path. | ||
|
||
This is useful if you wish to modify the specific _Dockerfile_ being used when running locally or when the app host is deploying. | ||
|
||
```csharp | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var container = builder.ExecutionContext.IsRunMode | ||
? builder.AddDockerfile( | ||
"mycontainer", "relative/context/path", "Dockerfile.debug") | ||
: builder.AddDockerfile( | ||
"mycontainer", "relative/context/path", "Dockerfile.release"); | ||
``` | ||
|
||
## Customize existing container resources | ||
|
||
When using <xref:Aspire.Hosting.ResourceBuilderExtensions.AddDockerfile%2A> the return value is an `IResourceBuilder<ContainerResource>`. .NET Aspire includes many custom resource types that are derived from <xref:Aspire.Hosting.ApplicationModel.ContainerResource>. | ||
|
||
Using the <xref:Aspire.Hosting.ResourceBuilderExtensions.WithDockerfile%2A> extension method it's possible to continue using these strongly typed resource types and customize the underlying container that is used. | ||
|
||
```csharp | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var pgsql = builder.AddPostgres("pgsql") | ||
.WithDockerfile("path/to/context") | ||
.WithPgAdmin(); | ||
``` | ||
|
||
## Pass build arguments | ||
|
||
The <xref:Aspire.Hosting.ResourceBuilderExtensions.WithBuildArg%2A> method can be used to pass arguments into the container image build. | ||
|
||
```csharp | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var container = builder.AddDockerfile("mygoapp", "relative/context/path") | ||
.WithBuildArg("GO_VERSION", "1.22"); | ||
``` | ||
|
||
The value parameter on the <xref:Aspire.Hosting.ResourceBuilderExtensions.WithBuildArg%2A> method can be a literal value (`boolean`, `string`, `int`) or it can be a resource builder for a [parameter resource](../fundamentals/external-parameters.md). The following code replaces the `GO_VERSION` with a parameter value that can be specified at deployment time. | ||
|
||
```csharp | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var goVersion = builder.AddParameter("goversion"); | ||
|
||
var container = builder.AddDockerfile("mygoapp", "relative/context/path") | ||
.WithBuildArg("GO_VERSION", goVersion); | ||
``` | ||
|
||
Build arguments correspond to the [`ARG` command](https://docs.docker.com/build/guide/build-args/) in _Dockerfiles_. Expanding the preceding example, this is a multi-stage _Dockerfile_ which specifies specific container image version to use as a parameter. | ||
|
||
```dockerfile | ||
# Stage 1: Build the Go program | ||
ARG GO_VERSION=1.22 | ||
FROM golang:${GO_VERSION} AS builder | ||
WORKDIR /build | ||
COPY . . | ||
RUN go build mygoapp.go | ||
|
||
# Stage 2: Run the Go program | ||
FROM mcr.microsoft.com/cbl-mariner/base/core:2.0 | ||
WORKDIR /app | ||
COPY --from=builder /build/mygoapp . | ||
CMD ["./mygoapp"] | ||
``` | ||
|
||
> [!NOTE] | ||
> Instead of hardcoding values into the container image, it's recommended to use environment variables for values that frequently change. This avoids the need to rebuild the container image whenever a change is required. | ||
|
||
## Pass build secrets | ||
|
||
In addition to build arguments it's possible to specify build secrets using <xref:Aspire.Hosting.ResourceBuilderExtensions.WithBuildSecret%2A> which are made selectively available to individual commands in the _Dockerfile_ using the `--mount=type=secret` syntax on `RUN` commands. | ||
|
||
```csharp | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var accessToken = builder.AddParameter("accesstoken", secret: true); | ||
|
||
var container = builder.AddDockerfile("myapp", "relative/context/path") | ||
.WithBuildSecret("ACCESS_TOKEN", accessToken); | ||
``` | ||
|
||
For example, consider the `RUN` command in a _Dockerfile_ which exposes the specified secret to the specific command: | ||
|
||
```dockerfile | ||
# The helloworld command can read the secret from /run/secrets/ACCESS_TOKEN | ||
RUN --mount=type=secret,id=ACCESS_TOKEN helloworld | ||
``` | ||
|
||
> [!CAUTION] | ||
> Caution should be exercised when passing secrets in build environments. This is often done when using a token to retrieve dependencies from private repositories or feeds before a build. It is important to ensure that the injected secrets are not copied into the final or intermediate images. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!-- | ||
https://github.com/dotnet/docs-aspire/issues/1049 | ||
|
||
We are introducing support for Garnet in this PR: | ||
|
||
dotnet/aspire#4324 | ||
|
||
It is presently a drop in alternative for Redis. We probably need an article that sites right alongside the Redis articles so that folks who might be looking for Redis content to understand how Garnet works can find it. | ||
|
||
The article should cover: | ||
|
||
AddGarnet | ||
WithDataVolume/WithBindMount | ||
WithPersistence | ||
It can probably cover off the client side pieces by just referring back to the Redis article although the Redis article might need to more clearly call out which is service code and which is app host code. | ||
|
||
Configuring Garnet using AddGarnet and using the data volume and persistence extension methods. | ||
|
||
Include links to: | ||
- https://github.com/microsoft/Garnet | ||
- https://microsoft.github.io/garnet/docs | ||
--> | ||
|
||
To model the Garnet resource in the app host, install the [Aspire.Hosting.Garnet](https://www.nuget.org/packages/Aspire.Hosting.Garnet) NuGet package in the [app host](xref:aspire/app-host) project. | ||
|
||
### [.NET CLI](#tab/dotnet-cli) | ||
|
||
```dotnetcli | ||
dotnet add package Aspire.Hosting.Garnet | ||
``` | ||
|
||
### [PackageReference](#tab/package-reference) | ||
|
||
```xml | ||
<PackageReference Include="Aspire.Hosting.Garnet" | ||
Version="[SelectVersion]" /> | ||
``` | ||
|
||
--- | ||
|
||
In your app host project, register .NET Aspire Garnet as a `GarnetResource` using the `AddGarnet` method and consume the service using the following methods: | ||
|
||
```csharp | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var cache = builder.AddGarnet("cache"); | ||
|
||
builder.AddProject<Projects.ExampleProject>() | ||
.WithReference(cache) | ||
``` | ||
|
||
The <xref:Aspire.Hosting.ResourceBuilderExtensions.WithReference%2A> method configures a connection in the `ExampleProject` project named `cache`. In the _:::no-loc text="Program.cs":::_ file of `ExampleProject`, the Garnet connection can be consumed using: | ||
|
||
```csharp | ||
builder.AddGarnet("cache"); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!-- | ||
https://github.com/dotnet/docs-aspire/issues/1049 | ||
|
||
We are introducing support for Valkey in this PR: | ||
|
||
dotnet/aspire#4324 | ||
|
||
It is presently a drop in alternative for Redis. We probably need an article that sites right alongside the Redis articles so that folks who might be looking for Redis content to understand how Valkey works can find it. | ||
|
||
The article should cover: | ||
|
||
AddValkey | ||
WithDataVolume/WithBindMount | ||
WithPersistence | ||
It can probably cover off the client side pieces by just referring back to the Redis article although the Redis article might need to more clearly call out which is service code and which is app host code. | ||
|
||
Configuring Valkey using AddValkey and using the data volume and persistence extension methods. | ||
|
||
Include links to: | ||
- https://github.com/valkey-io/valkey | ||
- https://valkey.io/docs/ | ||
--> | ||
|
||
To model the Valkey resource in the app host, install the [Aspire.Hosting.Valkey](https://www.nuget.org/packages/Aspire.Hosting.Valkey) NuGet package in the [app host](xref:aspire/app-host) project. | ||
|
||
### [.NET CLI](#tab/dotnet-cli) | ||
|
||
```dotnetcli | ||
dotnet add package Aspire.Hosting.Valkey | ||
``` | ||
|
||
### [PackageReference](#tab/package-reference) | ||
|
||
```xml | ||
<PackageReference Include="Aspire.Hosting.Valkey" | ||
Version="[SelectVersion]" /> | ||
``` | ||
|
||
--- | ||
|
||
In your app host project, register the .NET Aspire Valkey as a resource using the `AddValkey` method and consume the service using the following methods: | ||
|
||
```csharp | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var cache = builder.AddValkey("cache"); | ||
|
||
builder.AddProject<Projects.ExampleProject>() | ||
.WithReference(cache) | ||
``` | ||
|
||
The <xref:Aspire.Hosting.ResourceBuilderExtensions.WithReference%2A> method configures a connection in the `ExampleProject` project named `cache`. In the _:::no-loc text="Program.cs":::_ file of `ExampleProject`, the Valkey connection can be consumed using: | ||
|
||
```csharp | ||
builder.AddValkey("cache"); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.