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

Add missing port configuration to AddAzurePostgresFlexibleServer RunAsContainer #6276

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ public static IResourceBuilder<AzurePostgresFlexibleServerDatabaseResource> AddD
/// </summary>
/// <param name="builder">The Azure PostgreSQL server resource builder.</param>
/// <param name="configureContainer">Callback that exposes underlying container to allow for customization.</param>
/// <param name="port">The host port used when launching the container. If null a random port will be assigned.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{AzurePostgresFlexibleServerResource}"/> builder.</returns>
/// <example>
/// The following example creates an Azure PostgreSQL Flexible Server resource that runs locally in a
Expand All @@ -241,7 +240,7 @@ public static IResourceBuilder<AzurePostgresFlexibleServerDatabaseResource> AddD
/// builder.Build().Run();
/// </code>
/// </example>
public static IResourceBuilder<AzurePostgresFlexibleServerResource> RunAsContainer(this IResourceBuilder<AzurePostgresFlexibleServerResource> builder, Action<IResourceBuilder<PostgresServerResource>>? configureContainer = null, int? port = null)
public static IResourceBuilder<AzurePostgresFlexibleServerResource> RunAsContainer(this IResourceBuilder<AzurePostgresFlexibleServerResource> builder, Action<IResourceBuilder<PostgresServerResource>>? configureContainer = null)
{
if (builder.ApplicationBuilder.ExecutionContext.IsPublishMode)
{
Expand All @@ -266,8 +265,7 @@ public static IResourceBuilder<AzurePostgresFlexibleServerResource> RunAsContain
var postgresContainer = builder.ApplicationBuilder.AddPostgres(
azureResource.Name,
userNameParameterBuilder,
passwordParameterBuilder,
port);
passwordParameterBuilder);

azureResource.SetInnerResource(postgresContainer.Resource);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ override Aspire.Hosting.Azure.AzurePostgresFlexibleServerDatabaseResource.Annota
override Aspire.Hosting.Azure.AzurePostgresFlexibleServerResource.Annotations.get -> Aspire.Hosting.ApplicationModel.ResourceAnnotationCollection!
static Aspire.Hosting.AzurePostgresExtensions.AddAzurePostgresFlexibleServer(this Aspire.Hosting.IDistributedApplicationBuilder! builder, string! name) -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzurePostgresFlexibleServerResource!>!
static Aspire.Hosting.AzurePostgresExtensions.AddDatabase(this Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzurePostgresFlexibleServerResource!>! builder, string! name, string? databaseName = null) -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzurePostgresFlexibleServerDatabaseResource!>!
static Aspire.Hosting.AzurePostgresExtensions.RunAsContainer(this Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzurePostgresFlexibleServerResource!>! builder, System.Action<Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.PostgresServerResource!>!>? configureContainer = null, int? port = null) -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzurePostgresFlexibleServerResource!>!
static Aspire.Hosting.AzurePostgresExtensions.RunAsContainer(this Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzurePostgresFlexibleServerResource!>! builder, System.Action<Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.PostgresServerResource!>!>? configureContainer = null) -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzurePostgresFlexibleServerResource!>!
static Aspire.Hosting.AzurePostgresExtensions.WithPasswordAuthentication(this Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzurePostgresFlexibleServerResource!>! builder, Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ParameterResource!>? userName = null, Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ParameterResource!>? password = null) -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzurePostgresFlexibleServerResource!>!
16 changes: 16 additions & 0 deletions src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ public static IResourceBuilder<T> WithPgAdmin<T>(this IResourceBuilder<T> builde
}
}

/// <summary>
/// Configures the host port that the PostgresServer resource is exposed on instead of using randomly assigned port.
/// </summary>
/// <param name="builder">The resource builder for PostgresServer.</param>
/// <param name="port">The port to bind on the host. If <see langword="null"/> is used random port will be assigned.</param>
/// <returns>The resource builder for PostgresServer.</returns>
public static IResourceBuilder<PostgresServerResource> WithHostPort(this IResourceBuilder<PostgresServerResource> builder, int? port)
{
ArgumentNullException.ThrowIfNull(builder);

return builder.WithEndpoint("http", endpoint =>
{
endpoint.Port = port;
});
}

/// <summary>
/// Configures the host port that the PGAdmin resource is exposed on instead of using randomly assigned port.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Aspire.Hosting.PostgreSQL/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Aspire.Hosting.ApplicationModel.PostgresServerResource.UserNameParameter.set ->
Aspire.Hosting.Postgres.PgWebContainerResource
Aspire.Hosting.Postgres.PgWebContainerResource.PgWebContainerResource(string! name) -> void
Aspire.Hosting.Postgres.PgWebContainerResource.PrimaryEndpoint.get -> Aspire.Hosting.ApplicationModel.EndpointReference!
static Aspire.Hosting.PostgresBuilderExtensions.WithHostPort(this Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.PostgresServerResource!>! builder, int? port) -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.PostgresServerResource!>!
static Aspire.Hosting.PostgresBuilderExtensions.WithHostPort(this Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Postgres.PgWebContainerResource!>! builder, int? port) -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Postgres.PgWebContainerResource!>!
static Aspire.Hosting.PostgresBuilderExtensions.WithPgWeb(this Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.PostgresServerResource!>! builder, System.Action<Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Postgres.PgWebContainerResource!>!>? configureContainer = null, string? containerName = null) -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.PostgresServerResource!>!