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

Provide optional arguments for password/port when running as a container #6886

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dansiegel
Copy link

@dansiegel dansiegel commented Dec 6, 2024

Description

Adds optional parameters from the underlying call to AddSqlServer for the password and the port. This allows users to specify these properties when using Azure Sql to run locally as a container for development and still optionally configure the password/port like you can when using the SqlServer AddSqlServer method directly.

This can be helpful for local development as the port will shift each time the AppHost is run.

Fixes # (issue)

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
    • Updated existing with new optional parameters
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?
Microsoft Reviewers: Open in CodeFlow

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Dec 6, 2024
@davidfowl
Copy link
Member

@eerhardt we should do this in 9.1

@@ -146,7 +148,7 @@ public static IResourceBuilder<AzureSqlDatabaseResource> AddDatabase(this IResou
/// builder.Build().Run();
/// </code>
/// </example>
public static IResourceBuilder<AzureSqlServerResource> RunAsContainer(this IResourceBuilder<AzureSqlServerResource> builder, Action<IResourceBuilder<SqlServerServerResource>>? configureContainer = null)
public static IResourceBuilder<AzureSqlServerResource> RunAsContainer(this IResourceBuilder<AzureSqlServerResource> builder, Action<IResourceBuilder<SqlServerServerResource>>? configureContainer = null, IResourceBuilder<ParameterResource>? password = null, int? port = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidfowl @sebastienros @ReubenBond @JamesNK @DamianEdwards - are we concerned with binary breaking changes like this in the Hosting integrations? Part of me thinks this is OK, but wanted to check what everyone else thinks.

If we didn't go with this approach, we could take one of 2 approaches:

  1. Just add 1 new overload that took all parameters, and callers would pass in null explicitly for the parameters they aren't supplying.
  2. Explode the API out with 8 overloads - every combination of parameters - which feels excessive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative is to expose some methods that allow for configuring the port and the password during the configureContainer callback.

See 15e8a26 for an example:

var sql1 = builder.AddAzureSqlServer("sql1")
                  .RunAsContainer(c =>
                  {
                      c.WithHostPort(5555);
                  });

The downside with just exposing it on these 3 containers is that it isn't consistent with the rest of the "top level" containers - like MongoDB, RabbitMQ, etc. If we go with this route, would we add it to all of them as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we've generally been fine with adding new optional parameters to existing methods right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't been fine in the client integration libraries, since it is a binary breaking change. But I'm not sure we care as much in the hosting integrations libraries.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I guess I'm basing this on what we've done in ASP.NET Core itself and Aspire.Hosting, or I'm totally misremembering 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't make binary breaking changes in minors. Just add overloads 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm in favor of taking the alternative approach above:

var sql1 = builder.AddAzureSqlServer("sql1")
                  .RunAsContainer(c =>
                  {
                      c.WithHostPort(5555);
                  });

This fits with our other "emulator" containers, and allows us to not have an explosion of overloads.

We would also then have a .WithPassword(IResourceBuilder<ParameterResource>) extension as well that allows you to set the password after the constructor.

Opinions on taking this approach?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that as well but it would require more changes to the way that the underlying SqlServerResource is created/updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it would require some more changes throughout, but I think it provides a better API experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants