Browse Source
Added support for additional routes on the Dashboard (#1200 )
* Add support for additional routes on the Dashboard
* Add deserialization unit tests
* Change routes from semicolon separated list to an array
* Use blocks for bindings.
Co-authored-by: Ante Marić <ante.maric@king-ict.hr>
Co-authored-by: phoff <phoff@microsoft.com>
main-publicPoolNames
ante-maric
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with
55 additions and
5 deletions
docs/reference/schema.md
src/Microsoft.Tye.Core/ApplicationFactory.cs
src/Microsoft.Tye.Core/BindingBuilder.cs
src/Microsoft.Tye.Core/ConfigModel/ConfigServiceBinding.cs
src/Microsoft.Tye.Core/Serialization/ConfigServiceParser.cs
src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor
src/Microsoft.Tye.Hosting/DockerRunner.cs
src/Microsoft.Tye.Hosting/Model/ServiceBinding.cs
src/tye/ApplicationBuilderExtensions.cs
test/UnitTests/TyeDeserializationTests.cs
@ -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.
@ -376,6 +376,7 @@ namespace Microsoft.Tye
ContainerPort = configBinding . ContainerPort ,
Port = configBinding . Port ,
Protocol = configBinding . Protocol ,
Routes = configBinding . Routes
} ;
// Assume HTTP for projects only (containers may be different)
@ -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
@ -12,5 +14,6 @@ namespace Microsoft.Tye
public int? ContainerPort { get ; set ; }
public string? Host { get ; set ; }
public string? Protocol { get ; set ; }
public List < string > Routes { get ; set ; } = new List < string > ( ) ;
}
}
@ -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
@ -12,5 +14,6 @@ namespace Microsoft.Tye.ConfigModel
public int? ContainerPort { get ; set ; }
public string? Host { get ; set ; }
public string? Protocol { get ; set ; }
public List < string > Routes { get ; set ; } = new List < string > ( ) ;
}
}
@ -218,6 +218,14 @@ namespace Tye.Serialization
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 ) ) ;
}
@ -571,6 +579,16 @@ namespace Tye.Serialization
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 )
@ -2,6 +2,12 @@
@inject Application application
@implements IDisposable
<style>
.binding {
display: block;
}
</style>
<h1>Services</h1>
<table class="table service-table">
<thead>
@ -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>
}
}
}
@ -94,6 +94,7 @@ namespace Microsoft.Tye.Hosting
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 ) ;
@ -17,5 +17,6 @@ namespace Microsoft.Tye.Hosting.Model
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 > ( ) ;
}
}
@ -174,7 +174,7 @@ namespace Microsoft.Tye
foreach ( var binding in service . Bindings )
{
description . Bindings . Add ( new ServiceBinding ( )
var sb = new ServiceBinding ( )
{
ConnectionString = binding . ConnectionString ,
Host = binding . Host ,
@ -182,7 +182,9 @@ namespace Microsoft.Tye
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 ) ) ;
@ -82,6 +82,9 @@ services:
containerPort : 8 0
host : localhost
protocol : http
routes :
- / swagger
- / graphql
- name : appB
project : ApplicationB / ApplicationB . csproj
replicas : 2
@ -155,6 +158,9 @@ services:
containerPort : 8 0
host : localhost
protocol : http
routes :
- / swagger
- / graphql
- name : appB
project : ApplicationB / ApplicationB . csproj
replicas : 2