-
-
Notifications
You must be signed in to change notification settings - Fork 336
feat: Add Aspire Dashboard module #1190 #1194
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
Open
NikiforovAll
wants to merge
6
commits into
testcontainers:develop
Choose a base branch
from
NikiforovAll:feature/aspire-dashboard
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4cdf554
feat: Add Aspire Dashboard module #1190
NikiforovAll b818522
Add tests
NikiforovAll 272bbf7
Merge branch 'develop' into feature/aspire-dashboard
HofmeisterAn 2db71e1
chore: Remove BOM, sort projects
HofmeisterAn 6f10ad4
chore: Align XML doc
HofmeisterAn 4bd053b
fix: fixes after code review
NikiforovAll 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
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 @@ | ||
root = true |
91 changes: 91 additions & 0 deletions
91
src/Testcontainers.AspireDashboard/AspireDashboardBuilder.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,91 @@ | ||
namespace Testcontainers.AspireDashboard; | ||
|
||
/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" /> | ||
[PublicAPI] | ||
public sealed class AspireDashboardBuilder : ContainerBuilder<AspireDashboardBuilder, AspireDashboardContainer, AspireDashboardConfiguration> | ||
{ | ||
public const string AspireDashboardImage = "mcr.microsoft.com/dotnet/aspire-dashboard:latest"; | ||
|
||
public const ushort AspireDashboardFrontendPort = 18888; | ||
|
||
public const ushort AspireDashboardOtlpPort = 18889; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AspireDashboardBuilder" /> class. | ||
/// </summary> | ||
public AspireDashboardBuilder() | ||
: this(new AspireDashboardConfiguration(false, false)) | ||
{ | ||
DockerResourceConfiguration = Init().DockerResourceConfiguration; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AspireDashboardBuilder" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
private AspireDashboardBuilder(AspireDashboardConfiguration resourceConfiguration) | ||
: base(resourceConfiguration) | ||
{ | ||
DockerResourceConfiguration = resourceConfiguration; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override AspireDashboardConfiguration DockerResourceConfiguration { get; } | ||
|
||
/// <summary> | ||
/// Configures the dashboard to accept anonymous access. | ||
/// </summary> | ||
/// <param name="allowed">A value indicating whether anonymous access is allowed.</param> | ||
/// <returns>A configured instance of <see cref="AspireDashboardBuilder" />.</returns> | ||
public AspireDashboardBuilder AllowAnonymous(bool allowed) | ||
{ | ||
return Merge(DockerResourceConfiguration, new AspireDashboardConfiguration(allowAnonymous: allowed)) | ||
.WithEnvironment("DOTNET_DASHBOARD_UNSECURED_ALLOW_ANONYMOUS", allowed.ToString().ToLowerInvariant()); | ||
} | ||
|
||
/// <summary> | ||
/// Configures the dashboard to allow unsecured transport. | ||
/// </summary> | ||
/// <param name="allowed">A value indicating whether unsecured transport is allowed.</param> | ||
/// <returns>A configured instance of <see cref="AspireDashboardBuilder" />.</returns> | ||
public AspireDashboardBuilder AllowUnsecuredTransport(bool allowed) | ||
{ | ||
return Merge(DockerResourceConfiguration, new AspireDashboardConfiguration(allowUnsecuredTransport: allowed)) | ||
.WithEnvironment("ASPIRE_ALLOW_UNSECURED_TRANSPORT", allowed.ToString().ToLowerInvariant()); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override AspireDashboardContainer Build() | ||
{ | ||
Validate(); | ||
return new AspireDashboardContainer(DockerResourceConfiguration); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override AspireDashboardBuilder Init() | ||
{ | ||
return base.Init() | ||
.WithImage(AspireDashboardImage) | ||
.WithPortBinding(AspireDashboardFrontendPort, AspireDashboardFrontendPort) | ||
NikiforovAll marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
.WithPortBinding(AspireDashboardOtlpPort, true) | ||
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(AspireDashboardFrontendPort))); | ||
NikiforovAll marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
/// <inheritdoc /> | ||
protected override AspireDashboardBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
{ | ||
return Merge(DockerResourceConfiguration, new AspireDashboardConfiguration(resourceConfiguration)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override AspireDashboardBuilder Clone(IContainerConfiguration resourceConfiguration) | ||
{ | ||
return Merge(DockerResourceConfiguration, new AspireDashboardConfiguration(resourceConfiguration)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override AspireDashboardBuilder Merge(AspireDashboardConfiguration oldValue, AspireDashboardConfiguration newValue) | ||
{ | ||
return new AspireDashboardBuilder(new AspireDashboardConfiguration(oldValue, newValue)); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/Testcontainers.AspireDashboard/AspireDashboardConfiguration.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,65 @@ | ||
namespace Testcontainers.AspireDashboard; | ||
|
||
/// <inheritdoc cref="ContainerConfiguration" /> | ||
[PublicAPI] | ||
public sealed class AspireDashboardConfiguration : ContainerConfiguration | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AspireDashboardConfiguration" /> class. | ||
/// </summary> | ||
public AspireDashboardConfiguration(bool allowAnonymous = false, bool allowUnsecuredTransport = false) | ||
{ | ||
AllowAnonymous = allowAnonymous; | ||
AllowUnsecuredTransport = allowUnsecuredTransport; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AspireDashboardConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
public AspireDashboardConfiguration(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
: base(resourceConfiguration) | ||
{ | ||
// Passes the configuration upwards to the base implementations to create an updated immutable copy. | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AspireDashboardConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
public AspireDashboardConfiguration(IContainerConfiguration resourceConfiguration) | ||
: base(resourceConfiguration) | ||
{ | ||
// Passes the configuration upwards to the base implementations to create an updated immutable copy. | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AspireDashboardConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
public AspireDashboardConfiguration(AspireDashboardConfiguration resourceConfiguration) | ||
: this(new AspireDashboardConfiguration(), resourceConfiguration) | ||
{ | ||
// Passes the configuration upwards to the base implementations to create an updated immutable copy. | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AspireDashboardConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="oldValue">The old Docker resource configuration.</param> | ||
/// <param name="newValue">The new Docker resource configuration.</param> | ||
public AspireDashboardConfiguration(AspireDashboardConfiguration oldValue, AspireDashboardConfiguration newValue) | ||
: base(oldValue, newValue) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets AllowAnonymous mode. | ||
/// </summary> | ||
public bool AllowAnonymous { get; } | ||
|
||
/// <summary> | ||
/// Gets AllowUnsecuredTransport mode. | ||
/// </summary> | ||
public bool AllowUnsecuredTransport { get; } | ||
NikiforovAll marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/Testcontainers.AspireDashboard/AspireDashboardContainer.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,43 @@ | ||
namespace Testcontainers.AspireDashboard; | ||
|
||
/// <inheritdoc cref="DockerContainer" /> | ||
[PublicAPI] | ||
public sealed class AspireDashboardContainer : DockerContainer | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AspireDashboardContainer" /> class. | ||
/// </summary> | ||
/// <param name="configuration">The container configuration.</param> | ||
public AspireDashboardContainer(AspireDashboardConfiguration configuration) | ||
: base(configuration) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets the AspireDashboard URL. | ||
/// </summary> | ||
/// <returns>The AspireDashboard URL.</returns> | ||
public string GetDashboardUrl() | ||
{ | ||
var endpoint = new UriBuilder( | ||
Uri.UriSchemeHttp, | ||
Hostname, | ||
GetMappedPublicPort(AspireDashboardBuilder.AspireDashboardFrontendPort)); | ||
|
||
return endpoint.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the AspireDashboard OTLP endpoint URL. | ||
/// </summary> | ||
/// <returns>The AspireDashboard OTLP endpoint URL.</returns> | ||
public string GetOtlpEndpointUrl() | ||
{ | ||
var endpoint = new UriBuilder( | ||
Uri.UriSchemeHttp, | ||
Hostname, | ||
GetMappedPublicPort(AspireDashboardBuilder.AspireDashboardOtlpPort)); | ||
|
||
return endpoint.ToString(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Testcontainers.AspireDashboard/Testcontainers.AspireDashboard.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,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net6.0;net8.0;netstandard2.0;netstandard2.1</TargetFrameworks> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="JetBrains.Annotations" VersionOverride="2023.3.0" PrivateAssets="All"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="../Testcontainers/Testcontainers.csproj"/> | ||
</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,11 @@ | ||
global using System; | ||
global using System.Collections.Generic; | ||
global using System.Linq; | ||
global using System.Net.Http; | ||
global using System.Threading; | ||
global using System.Threading.Tasks; | ||
global using Docker.DotNet.Models; | ||
global using DotNet.Testcontainers.Builders; | ||
global using DotNet.Testcontainers.Configurations; | ||
global using DotNet.Testcontainers.Containers; | ||
global using JetBrains.Annotations; |
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 @@ | ||
root = true |
35 changes: 35 additions & 0 deletions
35
tests/Testcontainers.AspireDashboard.Tests/AspireDashboardContainerTest.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,35 @@ | ||
namespace Testcontainers.AspireDashboard; | ||
|
||
public sealed class AspireDashboardContainerTest : IAsyncLifetime | ||
{ | ||
private readonly AspireDashboardContainer _container = new AspireDashboardBuilder() | ||
.AllowAnonymous(true) | ||
.AllowUnsecuredTransport(false) | ||
.Build(); | ||
|
||
public Task InitializeAsync() | ||
{ | ||
return _container.StartAsync(); | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
return _container.DisposeAsync().AsTask(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetDashboardReturnsHttpStatusCodeOk() | ||
{ | ||
// Given | ||
using var httpClient = new HttpClient(); | ||
|
||
var address = new Uri(_container.GetDashboardUrl()); | ||
httpClient.BaseAddress = address; | ||
|
||
// When | ||
using var response = await httpClient.GetAsync("/"); | ||
|
||
// Then | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/Testcontainers.AspireDashboard.Tests/Testcontainers.AspireDashboard.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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net8.0</TargetFrameworks> | ||
<IsPackable>false</IsPackable> | ||
<IsPublishable>false</IsPublishable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk"/> | ||
<PackageReference Include="coverlet.collector"/> | ||
<PackageReference Include="xunit.runner.visualstudio"/> | ||
<PackageReference Include="xunit"/> | ||
<PackageReference Include="ArangoDBNetStandard"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="../../src/Testcontainers.AspireDashboard/Testcontainers.AspireDashboard.csproj"/> | ||
<ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/> | ||
</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,6 @@ | ||
global using System; | ||
global using System.Net; | ||
global using System.Net.Http; | ||
global using System.Threading.Tasks; | ||
global using DotNet.Testcontainers.Commons; | ||
global using Xunit; |
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.