This commit is contained in:
Chris Cheetham 2020-03-25 15:51:08 -04:00
Родитель 13b22b819f
Коммит 0476ea3c78
9 изменённых файлов: 80 добавлений и 19 удалений

Просмотреть файл

@ -35,7 +35,7 @@ namespace Steeltoe.Cli
{
try
{
Logger.LogDebug($"tooling working directory: {app.WorkingDirectory}");
Logger.LogDebug($"working directory: {app.WorkingDirectory}");
var context = new Context(
app.WorkingDirectory,
_console.Out,

Просмотреть файл

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using McMaster.Extensions.CommandLineUtils;
using Steeltoe.Tooling.Controllers;
@ -27,27 +26,19 @@ Examples:
Run the default configuration:
$ st run
Run a specific configuration:
$ st run -n MyDockerConfig
See Also:
stop
list-cfgs")]
stop")]
public class RunCommand : Command
{
public const string CommandName = "run";
[Option("-n|--name <name>",
Description = "Sets the name of the configuration to be run (must be a Docker configuration)")]
private string Name { get; set; }
public RunCommand(IConsole console) : base(console)
{
}
protected override Controller GetController()
{
throw new NotImplementedException();
return new RunController();
}
}
}

Просмотреть файл

@ -12,6 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using Steeltoe.Tooling.Helpers;
using Steeltoe.Tooling.Models;
namespace Steeltoe.Tooling.Controllers
{
/// <summary>
@ -39,5 +43,16 @@ namespace Steeltoe.Tooling.Controllers
/// Sub-classes implement this to perform their specific workflow.
/// </summary>
protected abstract void Execute();
/// <summary>
/// Returns the project.
/// </summary>
/// <returns>The project.</returns>
protected Project GetProject()
{
var projectDir = Context.WorkingDirectory;
var projectName = Path.GetFileName(projectDir);
return new ProjectBuilder().BuildProject($"{projectDir}/{projectName}.csproj");
}
}
}

Просмотреть файл

@ -0,0 +1,46 @@
// Copyright 2020 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using Microsoft.Extensions.Logging;
using Steeltoe.Tooling.Templaters;
namespace Steeltoe.Tooling.Controllers
{
/// <summary>
/// Controls the "run" operation.
/// </summary>
public class RunController : Controller
{
private static readonly ILogger Logger = Logging.LoggerFactory.CreateLogger<RunController>();
/// <summary>
/// Runs the project in the local Docker environment.
/// </summary>
protected override void Execute()
{
var project = GetProject();
string[] files = new string[] {"Dockerfile", "docker-compose.yml"};
foreach (var file in files)
{
Logger.LogDebug($"writing {file}");
var template = TemplateManager.GetTemplate($"{file}.st");
template.Bind("project", project);
File.WriteAllText(file, template.Render());
}
var cli = new Cli("docker-compose", Context.Shell);
cli.Run("up --build", $"running '{project.Name}' in Docker");
}
}
}

Просмотреть файл

@ -12,6 +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;
@ -38,9 +39,7 @@ namespace Steeltoe.Tooling.Controllers
protected override void Execute()
{
Dictionary<string, Project> projects = new Dictionary<string, Project>();
var projectDir = Context.WorkingDirectory;
var projectName = Path.GetFileName(projectDir);
var project = new ProjectBuilder().BuildProject($"{projectDir}/{projectName}.csproj");
var project = GetProject();
projects.Add(project.Name, project);
var serializer = new SerializerBuilder().Build();
Context.Console.WriteLine(serializer.Serialize(projects));

Просмотреть файл

@ -12,7 +12,9 @@
// 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

Просмотреть файл

@ -0,0 +1,4 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1
WORKDIR /<project.Name>
RUN mkdir -p /usr/local/share/dotnet/sdk/NuGetFallbackFolder
CMD ["dotnet", "watch", "run", "--urls", "<project.Services:{svc|<svc.Protocol>://0.0.0.0:<svc.Port>}; separator=";">"]

Просмотреть файл

@ -0,0 +1,8 @@
version: "3.7"
services:
show:
build: .
ports:
<project.Services: {svc|- "<svc.Port>:<svc.Port>"}; separator="\n">
volumes:
- .:/<project.Name>

Просмотреть файл

@ -30,18 +30,14 @@ namespace Steeltoe.Cli.Test
"Runs project in the local Docker environment",
$"Usage: {Program.Name} run [options]",
"Options:",
"-n|--name <name> Sets the name of the configuration to be run (must be a Docker configuration)",
"-?|-h|--help Show help information",
"Overview:",
"Starts the project application and its dependencies in the local Docker environment.",
"Examples:",
"Run the default configuration:",
"$ st run",
"Run a specific configuration:",
"$ st run -n MyDockerConfig",
"See Also:",
"stop",
"list-cfgs",
})
);
}