-
Notifications
You must be signed in to change notification settings - Fork 3
Add Aspire hosting support, #16 #22
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
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| // For local development and testing, we add an Azure Search Emulator instance based on the project directly | ||
| builder.AddProject<Projects.AzureSearchEmulator>("emulator-project") | ||
| .WithExternalHttpEndpoints(); | ||
|
|
||
| // Example container usage via F23.Aspire.Hosting.AzureSearchEmulator | ||
| builder.AddAzureSearchEmulator("emulator-container") | ||
| .WithIndexesVolume(); | ||
|
|
||
| builder.Build().Run(); |
16 changes: 16 additions & 0 deletions
16
AzureSearchEmulator.Aspire.DemoAppHost/AzureSearchEmulator.Aspire.DemoAppHost.csproj
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,16 @@ | ||
| <Project Sdk="Aspire.AppHost.Sdk/13.0.0"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <UserSecretsId>e92d4b6e-a95b-491f-9fe2-8c8ecb4be28f</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\AzureSearchEmulator.Aspire\AzureSearchEmulator.Aspire.csproj" IsAspireProjectResource="false" /> | ||
| <ProjectReference Include="..\AzureSearchEmulator\AzureSearchEmulator.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
31 changes: 31 additions & 0 deletions
31
AzureSearchEmulator.Aspire.DemoAppHost/Properties/launchSettings.json
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,31 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17078;http://localhost:15216", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21046", | ||
| "ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "https://localhost:23199", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22069" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15216", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19291", | ||
| "ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "http://localhost:18104", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20178" | ||
| } | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
AzureSearchEmulator.Aspire.DemoAppHost/appsettings.Development.json
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,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
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,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
AzureSearchEmulator.Aspire.Tests/AzureSearchEmulator.Aspire.Tests.csproj
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,25 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="coverlet.collector" Version="6.0.4"/> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/> | ||
| <PackageReference Include="xunit" Version="2.9.3"/> | ||
| <PackageReference Include="xunit.runner.visualstudio" Version="3.1.4"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="Xunit"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\AzureSearchEmulator.Aspire\AzureSearchEmulator.Aspire.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
62 changes: 62 additions & 0 deletions
62
AzureSearchEmulator.Aspire.Tests/AzureSearchEmulatorResourceExtensionsTests.cs
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,62 @@ | ||
| using Aspire.Hosting; | ||
| using Aspire.Hosting.ApplicationModel; | ||
| using F23.Aspire.Hosting.AzureSearchEmulator; | ||
|
|
||
| namespace AzureSearchEmulator.Aspire.Tests; | ||
|
|
||
| public class AzureSearchEmulatorResourceExtensionsTests | ||
| { | ||
| [Fact] | ||
| public async Task AddAzureSearchEmulator_ShouldAddResourceToBuilder() | ||
| { | ||
| // Arrange | ||
| var builder = DistributedApplication.CreateBuilder(); | ||
| const string resourceName = "my-emulator"; | ||
|
|
||
| // Act | ||
| var resource = builder.AddAzureSearchEmulator(resourceName); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(resource); | ||
| Assert.Equal(resourceName, resource.Resource.Name); | ||
| Assert.Contains(resource.Resource, builder.Resources.ToList()); | ||
|
|
||
| var http = resource.Resource.GetEndpoint("http"); | ||
| Assert.NotNull(http); | ||
| Assert.Equal(AzureSearchEmulatorResource.DefaultHttpPort, http.TargetPort); | ||
| Assert.Equal("http", http.Scheme); | ||
|
|
||
| var https = resource.Resource.GetEndpoint("https"); | ||
| Assert.NotNull(https); | ||
| Assert.Equal(AzureSearchEmulatorResource.DefaultHttpsPort, https.TargetPort); | ||
| Assert.Equal("https", https.Scheme); | ||
|
|
||
| var envVars = await resource.Resource.GetEnvironmentVariableValuesAsync(); | ||
| Assert.True(envVars.ContainsKey("ASPNETCORE_URLS")); | ||
| } | ||
|
|
||
| [InlineData(false)] | ||
| [InlineData(true)] | ||
| [Theory] | ||
| public void WithIndexesVolume_ShouldAddVolumeToResource(bool isReadOnly) | ||
| { | ||
| // Arrange | ||
| var builder = DistributedApplication.CreateBuilder(); | ||
| var resourceBuilder = builder.AddAzureSearchEmulator("my-emulator"); | ||
|
|
||
| // Act | ||
| var updatedBuilder = resourceBuilder.WithIndexesVolume(isReadOnly: isReadOnly); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(updatedBuilder); | ||
|
|
||
| if (!updatedBuilder.Resource.TryGetAnnotationsOfType<ContainerMountAnnotation>(out var mountAnnotations)) | ||
| { | ||
| Assert.Fail("No mount annotations found on the resource."); | ||
| } | ||
|
|
||
| var mount = mountAnnotations.FirstOrDefault(ma => ma.Target == "/app/indexes"); | ||
| Assert.NotNull(mount); | ||
| Assert.Equal(isReadOnly, mount.IsReadOnly); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
AzureSearchEmulator.Aspire.Tests/AzureSearchEmulatorResourceTests.cs
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,19 @@ | ||
| using F23.Aspire.Hosting.AzureSearchEmulator; | ||
|
|
||
| namespace AzureSearchEmulator.Aspire.Tests; | ||
|
|
||
| public class AzureSearchEmulatorResourceTests | ||
| { | ||
| [Fact] | ||
| public void Constructor_InitializesResourceProperly() | ||
| { | ||
| // Arrange | ||
| const string name = "my-emulator"; | ||
|
|
||
| // Act | ||
| var resource = new AzureSearchEmulatorResource(name); | ||
|
|
||
| // Assert | ||
| Assert.Equal(name, resource.Name); | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
AzureSearchEmulator.Aspire/AzureSearchEmulator.Aspire.csproj
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,39 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <RootNamespace>F23.Aspire.Hosting.AzureSearchEmulator</RootNamespace> | ||
| <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
| <LangVersion>14</LangVersion> | ||
| <PackageId>F23.Aspire.Hosting.AzureSearchEmulator</PackageId> | ||
| <PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression> | ||
| <RepositoryUrl>https://github.com/feature23/azuresearchemulator</RepositoryUrl> | ||
| <PackageTags>azure search emulator ai hosting docker</PackageTags> | ||
| <Description>Azure Search Emulator hosting support for Aspire.</Description> | ||
| <IsPackable>true</IsPackable> | ||
| <Version>1.0.0-beta</Version> | ||
| <Company>feature[23]</Company> | ||
| <Copyright>Copyright (c) feature[23] 2025</Copyright> | ||
| <Authors>Paul Irwin</Authors> | ||
| <PackageIcon>logo.png</PackageIcon> | ||
| <PackageReadmeFile>README.md</PackageReadmeFile> | ||
| <IncludeSymbols>true</IncludeSymbols> | ||
| <SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <InternalsVisibleTo Include="AzureSearchEmulator.Aspire.Tests" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting" Version="13.0.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="../logo.png" Pack="true" PackagePath="\" /> | ||
| <None Include="../README.md" Pack="true" PackagePath="\" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
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,9 @@ | ||
| using Aspire.Hosting.ApplicationModel; | ||
|
|
||
| namespace F23.Aspire.Hosting.AzureSearchEmulator; | ||
|
|
||
| public class AzureSearchEmulatorResource(string name) : ContainerResource(name) | ||
| { | ||
| public const int DefaultHttpPort = 5100; | ||
| public const int DefaultHttpsPort = 5143; | ||
| } | ||
63 changes: 63 additions & 0 deletions
63
AzureSearchEmulator.Aspire/AzureSearchEmulatorResourceExtensions.cs
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,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> | ||
paulirwin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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)}") | ||
paulirwin marked this conversation as resolved.
Show resolved
Hide resolved
paulirwin marked this conversation as resolved.
Show resolved
Hide resolved
paulirwin marked this conversation as resolved.
Show resolved
Hide resolved
paulirwin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .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> | ||
paulirwin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// <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); | ||
| } | ||
paulirwin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
paulirwin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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
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 |
|---|---|---|
| @@ -1,35 +1,12 @@ | ||
| { | ||
| "iisSettings": { | ||
| "windowsAuthentication": false, | ||
| "anonymousAuthentication": true, | ||
| "iisExpress": { | ||
| "applicationUrl": "http://localhost:54359", | ||
| "sslPort": 44381 | ||
| } | ||
| }, | ||
| "profiles": { | ||
| "IIS Express": { | ||
| "commandName": "IISExpress", | ||
| "launchBrowser": true, | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "AzureSearchEmulator": { | ||
| "commandName": "Project", | ||
| "launchBrowser": true, | ||
| "launchBrowser": false, | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| }, | ||
| "dotnetRunMessages": "true", | ||
| "applicationUrl": "https://localhost:5123" | ||
| }, | ||
| "Docker": { | ||
| "commandName": "Docker", | ||
| "launchBrowser": true, | ||
| "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", | ||
| "publishAllPorts": true, | ||
| "useSSL": true | ||
| } | ||
| } | ||
| } | ||
| } |
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.