Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Added support for additional routes on the Dashboard #1200

Merged
merged 5 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions docs/reference/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ Specifies the protocol used by the binding. The protocol is used in [service dis

Specifies the hostname used by the binding. The protocol is used in [service discovery](/docs/reference/service_discovery.md) to construct a URL. It's safe to omit the `host` when localhost should be used for local development.

#### `routes` (`string[]`)

Specifies the list of additional routes to show in Bindings on the Dashboard for easy access. Example route value: /swagger.

#### `port` (string)

Specifies the port used by the binding. The port is used in [service discovery](/docs/reference/service_discovery.md) to construct a URL.
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Tye.Core/ApplicationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ service is ProjectServiceBuilder project2 &&
ContainerPort = configBinding.ContainerPort,
Port = configBinding.Port,
Protocol = configBinding.Protocol,
Routes = configBinding.Routes
};

// Assume HTTP for projects only (containers may be different)
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.Tye.Core/BindingBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;

namespace Microsoft.Tye
{
public sealed class BindingBuilder
Expand All @@ -12,5 +14,6 @@ public sealed class BindingBuilder
public int? ContainerPort { get; set; }
public string? Host { get; set; }
public string? Protocol { get; set; }
public List<string> Routes { get; set; } = new List<string>();
}
}
3 changes: 3 additions & 0 deletions src/Microsoft.Tye.Core/ConfigModel/ConfigServiceBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;

namespace Microsoft.Tye.ConfigModel
{
public class ConfigServiceBinding
Expand All @@ -12,5 +14,6 @@ public class ConfigServiceBinding
public int? ContainerPort { get; set; }
public string? Host { get; set; }
public string? Protocol { get; set; }
public List<string> Routes { get; set; } = new List<string>();
}
}
18 changes: 18 additions & 0 deletions src/Microsoft.Tye.Core/Serialization/ConfigServiceParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ private static void HandleServiceBindingNameMapping(YamlMappingNode yamlMappingN
case "protocol":
binding.Protocol = YamlParser.GetScalarValue(key, child.Value);
break;
case "routes":
if (child.Value.NodeType != YamlNodeType.Sequence)
{
throw new TyeYamlException(child.Value.Start, CoreStrings.FormatExpectedYamlSequence(key));
}

HandleServiceBindingRoutes((child.Value as YamlSequenceNode)!, binding.Routes);
break;
default:
throw new TyeYamlException(child.Key.Start, CoreStrings.FormatUnrecognizedKey(key));
}
Expand Down Expand Up @@ -571,6 +579,16 @@ private static void HandleServiceTags(YamlSequenceNode yamlSequenceNode, List<st
tags.Add(tag);
}
}

private static void HandleServiceBindingRoutes(YamlSequenceNode yamlSequenceNode, List<string> routes)
{
foreach (var child in yamlSequenceNode!.Children)
{
var route = YamlParser.GetScalarValue(child);
routes.Add(route);
}
}

private static void HandleServiceDockerArgsNameMapping(YamlMappingNode yamlMappingNode, IDictionary<string, string> dockerArguments)
{
foreach (var child in yamlMappingNode!.Children)
Expand Down
17 changes: 14 additions & 3 deletions src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
@inject Application application
@implements IDisposable

<style>
.binding {
display: block;
}
</style>

<h1>Services</h1>
<table class="table service-table">
<thead>
Expand Down Expand Up @@ -54,16 +60,21 @@
if (b.Protocol == "http" || b.Protocol == "https")
{
var url = GetUrl(b);
<span><a href="@url" target="_blank">@url</a></span>
<span class="binding"><a href="@url" target="_blank">@url</a></span>
foreach (var r in b.Routes)
{
var routeUrl = url + r;
<span class="binding"><a href="@routeUrl" target="_blank">@routeUrl</a></span>
}
}
else
{
<span>@GetUrl(b)</span>
<span class="binding">@GetUrl(b)</span>
}
}
else
{
<span>@b.ConnectionString</span>
<span class="binding">@b.ConnectionString</span>
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Tye.Hosting/DockerRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ service.Description.RunInfo is IngressRunInfo ||
Protocol = binding.Protocol
};
b.ReplicaPorts.Add(b.Port.Value);
b.Routes.AddRange(binding.Routes);
proxyDescription.Bindings.Add(b);
}
var proxyContainerService = new Service(proxyDescription, ServiceSource.Host);
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Tye.Hosting/Model/ServiceBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public class ServiceBinding
public string? IPAddress { get; set; }
public string? Protocol { get; set; }
public List<int> ReplicaPorts { get; } = new List<int>();
public List<string> Routes { get; } = new List<string>();
}
}
6 changes: 4 additions & 2 deletions src/tye/ApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,17 @@ public static Application ToHostingApplication(this ApplicationBuilder applicati

foreach (var binding in service.Bindings)
{
description.Bindings.Add(new ServiceBinding()
var sb = new ServiceBinding()
{
ConnectionString = binding.ConnectionString,
Host = binding.Host,
ContainerPort = binding.ContainerPort,
Name = binding.Name,
Port = binding.Port,
Protocol = binding.Protocol,
});
};
sb.Routes.AddRange(binding.Routes);
description.Bindings.Add(sb);
}

services.Add(service.Name, new Service(description, service.Source));
Expand Down
6 changes: 6 additions & 0 deletions test/UnitTests/TyeDeserializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public void ComprehensionalTest()
containerPort: 80
host: localhost
protocol: http
routes:
- /swagger
- /graphql
- name: appB
project: ApplicationB/ApplicationB.csproj
replicas: 2
Expand Down Expand Up @@ -155,6 +158,9 @@ public void ServicesSetCorrectly()
containerPort: 80
host: localhost
protocol: http
routes:
- /swagger
- /graphql
- name: appB
project: ApplicationB/ApplicationB.csproj
replicas: 2
Expand Down