-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAzureSearchEmulatorResourceExtensions.cs
More file actions
63 lines (58 loc) · 3.21 KB
/
Copy pathAzureSearchEmulatorResourceExtensions.cs
File metadata and controls
63 lines (58 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Aspire.Hosting.ApplicationModel;
using F23.Aspire.Hosting.AzureSearchEmulator;
// ReSharper disable once CheckNamespace
namespace Aspire.Hosting;
/// <summary>
/// Extension methods for adding and configuring Azure Search Emulator resources in Aspire.
/// </summary>
public static class AzureSearchEmulatorResourceExtensions
{
extension(IDistributedApplicationBuilder builder)
{
/// <summary>
/// Adds an Azure Search Emulator container resource to the distributed application.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="httpPort">An optional HTTP port. If null, will use a generated port number.</param>
/// <param name="httpsPort">An optional HTTPS port. If null, will use a generated port number.</param>
/// <returns>A resource builder for further configuration.</returns>
/// <remarks>
/// It is recommended to configure a volume for persisting index data using
/// <see cref="WithIndexesVolume"/>.
/// You can also override the default image tag ("latest") by using the returned resource builder's
/// <see cref="ContainerResourceBuilderExtensions.WithImageTag{T}"/> method.
/// </remarks>
public IResourceBuilder<AzureSearchEmulatorResource> AddAzureSearchEmulator(string name,
int? httpPort = null,
int? httpsPort = null)
{
var resource = new AzureSearchEmulatorResource(name);
var resourceBuilder = builder.AddResource(resource)
.WithImage("feature23/azuresearchemulator")
.WithImageTag("latest")
.WithImageRegistry("ghcr.io")
.WithHttpEndpoint(port: httpPort, targetPort: AzureSearchEmulatorResource.DefaultHttpPort, env: "HTTP_PORTS")
.WithHttpsEndpoint(port: httpsPort, targetPort: AzureSearchEmulatorResource.DefaultHttpsPort, env: "HTTPS_PORTS")
.WithEnvironment("ASPNETCORE_URLS", $"https://+:{resource.GetEndpoint("https").Property(EndpointProperty.Port)};http://+:{resource.GetEndpoint("http").Property(EndpointProperty.Port)}")
.WithEnvironment("ASPNETCORE_Kestrel__Certificates__Default__Password", "password")
.WithEnvironment("ASPNETCORE_Kestrel__Certificates__Default__Path", "/app/aspnetapp.pfx");
return resourceBuilder;
}
}
extension(IResourceBuilder<AzureSearchEmulatorResource> builder)
{
/// <summary>
/// Configures a volume for persisting Azure Search index data.
/// </summary>
/// <param name="volumeName">Optional name for the volume. If null, a name will be generated.</param>
/// <param name="isReadOnly">Indicates whether the volume should be mounted as read-only.</param>
/// <returns>The resource builder for further configuration.</returns>
public IResourceBuilder<AzureSearchEmulatorResource> WithIndexesVolume(string? volumeName = null, bool isReadOnly = false)
{
return builder.WithVolume(
name: volumeName ?? VolumeNameGenerator.Generate(builder, "indexes"),
target: "/app/indexes",
isReadOnly: isReadOnly);
}
}
}