prep for service dependency support
This commit is contained in:
Родитель
1170f4837d
Коммит
84bd775056
|
@ -32,7 +32,7 @@ See Also:
|
|||
{
|
||||
public const string CommandName = "run";
|
||||
|
||||
[Option("-g|--generate-only", Description = "Only generate configuration files (don't run in Docker).")]
|
||||
[Option("-g|--generate-only", Description = "Only generate configuration files (don't run in Docker)")]
|
||||
private bool GenerateOnly { get; }
|
||||
|
||||
public RunCommand(IConsole console) : base(console)
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
// limitations under the License.
|
||||
|
||||
using System.IO;
|
||||
using Steeltoe.Tooling.Helpers;
|
||||
using Steeltoe.Tooling.Models;
|
||||
|
||||
namespace Steeltoe.Tooling.Controllers
|
||||
|
|
|
@ -12,10 +12,8 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Steeltoe.Tooling.Models;
|
||||
using Steeltoe.Tooling.Templaters;
|
||||
|
||||
namespace Steeltoe.Tooling.Controllers
|
||||
|
|
|
@ -12,10 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Steeltoe.Tooling.Helpers;
|
||||
using Steeltoe.Tooling.Models;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
|
|
|
@ -12,9 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Steeltoe.Tooling.Models
|
||||
|
@ -28,7 +26,13 @@ namespace Steeltoe.Tooling.Models
|
|||
/// Project name.
|
||||
/// </summary>
|
||||
[YamlIgnore]
|
||||
public string Name { get; set; }
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value.ToLower();
|
||||
}
|
||||
|
||||
private string _name;
|
||||
|
||||
/// <summary>
|
||||
/// Project file path.
|
||||
|
@ -45,7 +49,7 @@ namespace Steeltoe.Tooling.Models
|
|||
/// <summary>
|
||||
/// Network ports.
|
||||
/// </summary>
|
||||
[YamlMember(Alias = "services")]
|
||||
public List<Service> Services { get; set; }
|
||||
[YamlMember(Alias = "protocols")]
|
||||
public List<Protocol> Protocols { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,10 +18,9 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Steeltoe.Tooling.Models;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Steeltoe.Tooling.Helpers
|
||||
namespace Steeltoe.Tooling.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper for building a Project.
|
||||
|
@ -30,11 +29,11 @@ namespace Steeltoe.Tooling.Helpers
|
|||
{
|
||||
private static readonly ILogger Logger = Logging.LoggerFactory.CreateLogger<ProjectBuilder>();
|
||||
|
||||
private static readonly List<Service> DefaultServices = new List<Service>();
|
||||
private static readonly List<Protocol> DefaultServices = new List<Protocol>();
|
||||
|
||||
static ProjectBuilder()
|
||||
{
|
||||
DefaultServices.Add(new Service("http", 8080));
|
||||
DefaultServices.Add(new Protocol("http", 8080));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -59,7 +58,7 @@ namespace Steeltoe.Tooling.Helpers
|
|||
Name = Path.GetFileNameWithoutExtension(projectFile),
|
||||
File = Path.GetFileName(projectFile),
|
||||
Framework = GetFramework(projectFile),
|
||||
Services = GetServices(projectFile)
|
||||
Protocols = GetServices(projectFile)
|
||||
};
|
||||
return project;
|
||||
}
|
||||
|
@ -83,7 +82,7 @@ namespace Steeltoe.Tooling.Helpers
|
|||
throw new ToolingException("could not determine framework");
|
||||
}
|
||||
|
||||
private List<Service> GetServices(string projectFile)
|
||||
private List<Protocol> GetServices(string projectFile)
|
||||
{
|
||||
var launchSettingsPath =
|
||||
Path.Join(Path.GetDirectoryName(projectFile), "Properties", "launchSettings.json");
|
||||
|
@ -115,7 +114,7 @@ namespace Steeltoe.Tooling.Helpers
|
|||
return DefaultServices;
|
||||
}
|
||||
|
||||
var services = urls.Select(url => new Uri(url)).Select(uri => new Service(uri.Scheme, uri.Port)).ToList();
|
||||
var services = urls.Select(url => new Uri(url)).Select(uri => new Protocol(uri.Scheme, uri.Port)).ToList();
|
||||
services.Sort();
|
||||
return services;
|
||||
}
|
|
@ -20,13 +20,13 @@ namespace Steeltoe.Tooling.Models
|
|||
/// <summary>
|
||||
/// A network port.
|
||||
/// </summary>
|
||||
public class Service : IComparable
|
||||
public class Protocol : IComparable
|
||||
{
|
||||
/// <summary>
|
||||
/// Service protocol.
|
||||
/// </summary>
|
||||
[YamlMember(Alias = "protocol")]
|
||||
public string Protocol { get; }
|
||||
[YamlMember(Alias = "name")]
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Service port.
|
||||
|
@ -35,26 +35,26 @@ namespace Steeltoe.Tooling.Models
|
|||
public int Port { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new service.
|
||||
/// Create a new Protocol.
|
||||
/// </summary>
|
||||
/// <param name="protocol">Service protocol.</param>
|
||||
/// <param name="port">Service port.</param>
|
||||
public Service(string protocol, int port)
|
||||
/// <param name="name">Protocol name.</param>
|
||||
/// <param name="port">Protocol port.</param>
|
||||
public Protocol(string name, int port)
|
||||
{
|
||||
Protocol = protocol;
|
||||
Name = name;
|
||||
Port = port;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns a comparison of the Services' protocols, and if equal, a comparison of the ports.
|
||||
/// Returns a comparison of the Protocols' names, and if equal, a comparison of the ports.
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="obj">Protocol against which to compare.</param>
|
||||
/// <returns><0, 0, >0.</returns>
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
var svc = (Service) obj;
|
||||
var compare = Protocol.CompareTo(svc.Protocol);
|
||||
var svc = (Protocol) obj;
|
||||
var compare = Name.CompareTo(svc.Name);
|
||||
if (compare != 0)
|
||||
{
|
||||
return compare;
|
|
@ -24,7 +24,7 @@ namespace Steeltoe.Tooling.Templaters
|
|||
/// </summary>
|
||||
public class TemplateManager
|
||||
{
|
||||
private static readonly object Locker = new object();
|
||||
private static readonly object TemplaterLock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the named template.
|
||||
|
@ -38,14 +38,14 @@ namespace Steeltoe.Tooling.Templaters
|
|||
var template = File.ReadAllText(path);
|
||||
try
|
||||
{
|
||||
lock (Locker) // StringTemplate doesn't seem to be tread safe
|
||||
lock (TemplaterLock) // AntlrStringTemplate doesn't seem to be thread safe
|
||||
{
|
||||
return new AntlrStringTemplate(template);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ToolingException($"failed to load template '{name}': {e.Message}");
|
||||
throw new ToolingException($"failed to load template: {name} [{e.Message}]");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
version: "3.7"
|
||||
services:
|
||||
show:
|
||||
<project.Name>:
|
||||
build: .
|
||||
ports:
|
||||
<project.Services: {svc|- "<svc.Port>:<svc.Port>"}; separator="\n">
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace Steeltoe.Cli.Test
|
|||
"Runs project in the local Docker environment",
|
||||
$"Usage: {Program.Name} run [options]",
|
||||
"Options:",
|
||||
"-g|--generate-only Only generate configuration files (don't run in Docker)",
|
||||
"-?|-h|--help Show help information",
|
||||
"Overview:",
|
||||
"Starts the project application and its dependencies in the local Docker environment.",
|
||||
|
|
Загрузка…
Ссылка в новой задаче