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

Content for .NET Aspire - Release 8.1 #1384

Merged
merged 36 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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 Jul 19, 2024
3d1b0b9
Fix MD lint
IEvangelist Jul 19, 2024
92fc076
Add elasticsearch bits
IEvangelist Jul 19, 2024
62c943a
Add Redis host includes
IEvangelist Jul 19, 2024
d52b45c
Fix hosting packages
IEvangelist Jul 19, 2024
69beee2
Fix the host toggles for zones
IEvangelist Jul 19, 2024
51db798
Dockerfile docs.
mitchdenny Jul 22, 2024
e1d4c07
Add note for event hubs emulator.
mitchdenny Jul 22, 2024
9d8d147
WIP: Python.
mitchdenny Jul 22, 2024
0dcf2b9
Update the zone name
IEvangelist Jul 19, 2024
4c395ae
Fix the 'missed one' :P
IEvangelist Jul 22, 2024
c098966
Sync Elasticsearch
IEvangelist Jul 22, 2024
17908d7
Edit pass on withdockerfile content
IEvangelist Jul 22, 2024
0ccb22d
Add Milvus
IEvangelist Jul 22, 2024
bcbbf72
Add Milvus to TOC
IEvangelist Jul 22, 2024
d557f53
A bit of clean for python
IEvangelist Jul 22, 2024
67af292
Apply suggestions from code review
IEvangelist Jul 22, 2024
c4b6436
Added logos and overview entries
IEvangelist Jul 22, 2024
73eeb56
Fix image
IEvangelist Jul 22, 2024
240bcc0
Add snippets and address https://github.com/dotnet/docs-aspire/issues…
IEvangelist Jul 22, 2024
b479a5b
Lots of updates
IEvangelist Jul 22, 2024
0f179f9
Getting closer but still broken
IEvangelist Jul 22, 2024
e61b938
Rename a bit
IEvangelist Jul 22, 2024
757340d
A few more updates
IEvangelist Jul 22, 2024
084dba8
Finialize python doc with screenshot.
mitchdenny Jul 23, 2024
2742988
Apply suggestions from code review
IEvangelist Jul 23, 2024
f2bfa44
Let's go, looking good
IEvangelist Jul 23, 2024
b77c406
Add a section in the overview detailing RESP
IEvangelist Jul 23, 2024
d26b01b
Add Keycloak
IEvangelist Jul 23, 2024
e6db24d
A quick edit pass
IEvangelist Jul 23, 2024
3eee16d
Added resource types
IEvangelist Jul 23, 2024
45adb30
Add Azure Web PubSub component
IEvangelist Jul 23, 2024
a8a3545
Touch dates
IEvangelist Jul 23, 2024
28b3dab
Bump all versions
IEvangelist Jul 23, 2024
6c66e02
Fix alt-text
IEvangelist Jul 23, 2024
074e36b
A few API fixes
IEvangelist Jul 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"Docker",
"Dockerfile",
"EF Core",
"Elasticsearch",
"Entity Framework Core",
"Git",
"GitHub",
Expand Down
105 changes: 105 additions & 0 deletions docs/app-host/withdockerfile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
title: Add Dockerfiles to your .NET app model
description: Learn how to add Dockerfiles to your .NET app model.
ms.date: 07/19/2024
---

# Add Dockerfiles to your .NET app model

Using .NET Aspire it is possible to specify a _Dockerfile_ to build when the apphost is started using either the <xref:Aspire.Hosting.ResourceBuilderExtensions.AddDockerfile%2A> or <xref:Aspire.Hosting.ResourceBuilderExtensions.WithDockerfile%2A> extension methods.

In the example below 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 interpretted 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 is 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 vs. deployment.

```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");
```

## Customizing 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 is 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();
```

## Passing 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. 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 in _Dockerfiles_. Expanding the example above, this is a mult-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: Build arguments hardcode values into the produced container image which means that the container image needs to rebuilt whenever a change is required. This is often not desirable and the use of environment variables is recommended to values that change frequently.

## Passing build secrets

In addition to build arguments it is 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);
```

Example of `RUN` command in Dockerfile which exposes the specified secret to the specific command:

```
# The helloworld command can read the secret from /run/secrets/ACCESS_TOKEN
RUN --mount=type=secret,id=ACCESS_TOKEN helloworld
```

> NOTE: Caution should be used whenever secrets are handed in build environments. Common scenarios include using a token to restore dependencies from private repositories/feeds prior to a build occuring. The injected secrets should not be copied into the final or intermediate images.
56 changes: 56 additions & 0 deletions docs/caching/includes/garnet-app-host.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!--
mitchdenny marked this conversation as resolved.
Show resolved Hide resolved
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 the .NET Aspire Garnet as a resource using the `AddGarnet` method and consume the service using the following methods:
IEvangelist marked this conversation as resolved.
Show resolved Hide resolved

```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");
```
15 changes: 15 additions & 0 deletions docs/caching/includes/redis-app-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,18 @@ dotnet add package Aspire.Hosting.Redis
---

In your app host project, register the .NET Aspire Stack Exchange Redis as a resource using the <xref:Aspire.Hosting.RedisBuilderExtensions.AddRedis%2A> method and consume the service using the following methods:

```csharp
var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddRedis("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 Redis connection can be consumed using:

```csharp
builder.AddRedis("cache");
```
56 changes: 56 additions & 0 deletions docs/caching/includes/valkey-app-host.md
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");
```
72 changes: 60 additions & 12 deletions docs/caching/stackexchange-redis-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: .NET Aspire Stack Exchange Redis component
description: This article describes the .NET Aspire Stack Exchange Redis component features and capabilities
ms.topic: how-to
ms.date: 07/17/2024
zone_pivot_groups: resp-host
---

# .NET Aspire Stack Exchange Redis component
Expand Down Expand Up @@ -49,41 +50,64 @@ public class ExampleService(IConnectionMultiplexer connectionMultiplexer)

## App host usage

:::zone pivot="redis"

[!INCLUDE [redis-app-host](includes/redis-app-host.md)]

```csharp
var builder = DistributedApplication.CreateBuilder(args);
:::zone-end
:::zone pivot="garnet"

var redis = builder.AddRedis("redis");
[!INCLUDE [garnet-app-host](includes/garnet-app-host.md)]

builder.AddProject<Projects.ExampleProject>()
.WithReference(redis)
```
:::zone-end
:::zone pivot="valkey"

The <xref:Aspire.Hosting.ResourceBuilderExtensions.WithReference%2A> method configures a connection in the `ExampleProject` project named `redis`. In the _:::no-loc text="Program.cs":::_ file of `ExampleProject`, the Redis connection can be consumed using:
[!INCLUDE [valkey-app-host](includes/valkey-app-host.md)]

```csharp
builder.AddRedis("cache");
```
:::zone-end

## Configuration

The .NET Aspire Stack Exchange Redis component provides multiple options to configure the Redis connection based on the requirements and conventions of your project.

### Use a connection string

:::zone pivot="redis"

When using a connection string from the `ConnectionStrings` configuration section, you can provide the name of the connection string when calling `builder.AddRedis`:

```csharp
builder.AddRedis("RedisConnection");
builder.AddRedis("cache");
```

:::zone-end
:::zone pivot="garnet"

When using a connection string from the `ConnectionStrings` configuration section, you can provide the name of the connection string when calling `builder.AddGarnet`:

```csharp
builder.AddGarnet("cache");
```

:::zone-end
:::zone pivot="valkey"

[!INCLUDE [valkey-app-host](includes/valkey-app-host.md)]

When using a connection string from the `ConnectionStrings` configuration section, you can provide the name of the connection string when calling `builder.AddValkey`:

```csharp
builder.AddValkey("cache");
```

:::zone-end

And then the connection string will be retrieved from the `ConnectionStrings` configuration section:

```json
{
"ConnectionStrings": {
"RedisConnection": "localhost:6379"
"cache": "localhost:6379"
}
}
```
Expand Down Expand Up @@ -115,12 +139,36 @@ The .NET Aspire Stack Exchange Redis component supports <xref:Microsoft.Extensio

You can also pass the `Action<StackExchangeRedisSettings>` delegate to set up some or all the options inline, for example to configure `DisableTracing`:

:::zone pivot="redis"

```csharp
builder.AddRedis(
"cache",
settings => settings.DisableTracing = true);
```

:::zone-end
:::zone pivot="garnet"

```csharp
builder.AddGarnet(
"cache",
settings => settings.DisableTracing = true);
```

:::zone-end
:::zone pivot="valkey"

[!INCLUDE [valkey-app-host](includes/valkey-app-host.md)]

```csharp
builder.AddValkey(
"cache",
settings => settings.DisableTracing = true);
```

:::zone-end

[!INCLUDE [component-health-checks](../includes/component-health-checks.md)]

The .NET Aspire Stack Exchange Redis component handles the following:
Expand Down
Loading
Loading