forked from testcontainers/testcontainers-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Aspire Dashboard module testcontainers#1190
- Loading branch information
1 parent
56d3eab
commit 4cdf554
Showing
6 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 AspireDashboardPort = 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; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the AllowAnonymous mode. | ||
/// </summary> | ||
/// <param name="allowed"></param> | ||
/// <returns>A configured instance of <see cref="KeycloakBuilder" />.</returns> | ||
public AspireDashboardBuilder AllowAnonymous(bool allowed) | ||
{ | ||
return Merge(DockerResourceConfiguration, new AspireDashboardConfiguration(allowAnonymous: allowed)) | ||
.WithEnvironment("DOTNET_DASHBOARD_UNSECURED_ALLOW_ANONYMOUS", allowed.ToString().ToLower()); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the AllowAnonymous mode. | ||
/// </summary> | ||
/// <param name="allowed"></param> | ||
/// <returns>A configured instance of <see cref="KeycloakBuilder" />.</returns> | ||
public AspireDashboardBuilder AllowUnsecuredTransport(bool allowed) | ||
{ | ||
return Merge(DockerResourceConfiguration, new AspireDashboardConfiguration(allowUnsecuredTransport: allowed)) | ||
.WithEnvironment("ASPIRE_ALLOW_UNSECURED_TRANSPORT", allowed.ToString().ToLower()); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override AspireDashboardConfiguration DockerResourceConfiguration { get; } | ||
|
||
/// <inheritdoc /> | ||
public override AspireDashboardContainer Build() | ||
{ | ||
Validate(); | ||
return new AspireDashboardContainer(DockerResourceConfiguration); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override AspireDashboardBuilder Init() | ||
{ | ||
return base.Init() | ||
.WithImage(AspireDashboardImage) | ||
.WithPortBinding(AspireDashboardPort, AspireDashboardPort) | ||
.WithPortBinding(AspireDashboardOtlpPort, true) | ||
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(AspireDashboardPort))); | ||
} | ||
|
||
/// <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 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; } | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Testcontainers.AspireDashboard/AspireDashboardContainer.cs
This file contains 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.AspireDashboardPort)); | ||
|
||
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.CosmosDb.csproj
This file contains 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 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; |