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

Endpoint changes #3274

Merged
merged 1 commit into from
Mar 29, 2024
Merged

Endpoint changes #3274

merged 1 commit into from
Mar 29, 2024

Conversation

davidfowl
Copy link
Member

@davidfowl davidfowl commented Mar 29, 2024

  • In order for tools to better describe multiple endpoints int the manifest, we must include port information. At runtime most of the port information is dynamically generated and thus not described (for anything but containers), that doesn't work well when trying to deploy to various environments. We allocate ports in situations where there are none to match the runtime behavior.
  • Change also renames ContainerPort to TargetPort everywhere.
  • Added WithExternalHttpEndpoints to mark all http and https endpoints as external.

The exposed port (port in the manifest) is the port used to talk to this binding.
The target port (targetPort in the manifest) is the port the resource binds to.

From Copilot:

These rules determine the values of the targetPort and exposedPort variables based on the properties of an endpoint object:

  1. If the targetPort property is already specified, use its value as the targetPort.
  2. If the endpoint belongs to a ProjectResource and the targetPort is not specified, set the targetPort to null. This is because ProjectResource objects get their default port from the deployment tool.
  3. If none of the above conditions are met, allocate a dynamic port for the targetPort.

Next, the exposedPort is determined based on the following conditions:

  1. If the exposedPort and targetPort are the same, set the exposedPort to null. This means that the exposed port does not need to be explicitly mentioned because it is the same as the target port.
  2. If the port property is specified, use its value as the exposedPort.
  3. If the targetPort is specified and the port is not, set the exposedPort to null. In this case, the exposedPort will default to the targetPort.
  4. If the endpoint has a URI scheme of "http" or "https" and both the port and targetPort are null, set the exposedPort to null. This allows the tool to infer the default HTTP and HTTPS ports.
  5. For other URI schemes, allocate a a dynamic port for the exposedPort.

Fixes #2099

@davidfowl davidfowl requested a review from mitchdenny March 29, 2024 02:15
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Mar 29, 2024
@@ -277,9 +278,49 @@ public void WriteBindings(IResource resource, bool emitContainerPort = false)
Writer.WriteString("protocol", endpoint.Protocol.ToString().ToLowerInvariant());
Writer.WriteString("transport", endpoint.Transport);

if (emitContainerPort && endpoint.ContainerPort is { } containerPort)
int? targetPort = (resource, endpoint.UriScheme, endpoint.TargetPort) switch
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@davidfowl davidfowl added the breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. label Mar 29, 2024
…nifest, we must include port information. At runtime most of the port information is dynamically generated and thus not described (for anything but containers), that doesn't work well when trying to deploy to various environments. We allocate ports in situations where there are none to match the runtime behavior.

- Change also renames ContainerPort to TargetPort everywhere.
- Added `WithExternalHttpEndpoints` to mark all http and https endpoints as external.
@davidfowl davidfowl force-pushed the davidfowl/port-rename branch from 0cb7808 to d675afb Compare March 29, 2024 05:55
@davidfowl davidfowl merged commit 25687b6 into main Mar 29, 2024
8 checks passed
@davidfowl davidfowl deleted the davidfowl/port-rename branch March 29, 2024 08:24
@davidfowl
Copy link
Member Author

/backport to release/8.0-preview5

Copy link
Contributor

Started backporting to release/8.0-preview5: https://github.com/dotnet/aspire/actions/runs/8478915721

Copy link
Contributor

@davidfowl backporting to release/8.0-preview5 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: - In order for tools to better describe multiple endpoints int the manifest, we must include port information. At runtime most of the port information is dynamically generated and thus not described (for anything but containers), that doesn't work well when trying to deploy to various environments. We allocate ports in situations where there are none to match the runtime behavior. - Change also renames ContainerPort to TargetPort everywhere. - Added `WithExternalHttpEndpoints` to mark all http and https endpoints as external.
Using index info to reconstruct a base tree...
M	src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs
M	src/Aspire.Hosting/Dcp/ApplicationExecutor.cs
M	tests/Aspire.Hosting.Tests/RabbitMQ/AddRabbitMQTests.cs
M	tests/Aspire.Hosting.Tests/SqlServer/AddSqlServerTests.cs
Falling back to patching base and 3-way merge...
Auto-merging tests/Aspire.Hosting.Tests/SqlServer/AddSqlServerTests.cs
Auto-merging tests/Aspire.Hosting.Tests/RabbitMQ/AddRabbitMQTests.cs
Auto-merging src/Aspire.Hosting/Dcp/ApplicationExecutor.cs
Removing src/Aspire.Hosting/ApplicationModel/EndpointAnnotationExtensions.cs
Auto-merging src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs
CONFLICT (content): Merge conflict in src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 - In order for tools to better describe multiple endpoints int the manifest, we must include port information. At runtime most of the port information is dynamically generated and thus not described (for anything but containers), that doesn't work well when trying to deploy to various environments. We allocate ports in situations where there are none to match the runtime behavior. - Change also renames ContainerPort to TargetPort everywhere. - Added `WithExternalHttpEndpoints` to mark all http and https endpoints as external.
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Copy link
Contributor

@davidfowl an error occurred while backporting to release/8.0-preview5, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

davidfowl added a commit that referenced this pull request Mar 29, 2024
…nifest, we must include port information. At runtime most of the port information is dynamically generated and thus not described (for anything but containers), that doesn't work well when trying to deploy to various environments. We allocate ports in situations where there are none to match the runtime behavior. (#3274)

- Change also renames ContainerPort to TargetPort everywhere.
- Added `WithExternalHttpEndpoints` to mark all http and https endpoints as external.
davidfowl added a commit that referenced this pull request Mar 29, 2024
* - In order for tools to better describe multiple endpoints int the manifest, we must include port information. At runtime most of the port information is dynamically generated and thus not described (for anything but containers), that doesn't work well when trying to deploy to various environments. We allocate ports in situations where there are none to match the runtime behavior. (#3274)

- Change also renames ContainerPort to TargetPort everywhere.
- Added `WithExternalHttpEndpoints` to mark all http and https endpoints as external.

* Apply suggestions from code review

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>

---------

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
@github-actions github-actions bot locked and limited conversation to collaborators Apr 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication breaking-change Issue or PR that represents a breaking API or functional change over a prerelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to express exposed services in app host
2 participants