From 685a6538194c3cfb53440abf2ff096b983aeb19c Mon Sep 17 00:00:00 2001 From: Daniel Gerlag Date: Fri, 7 Jun 2019 15:12:34 -0700 Subject: [PATCH] wip --- .dockerignore | 9 +++++ Conductor.Domain/Conductor.Domain.csproj | 5 +-- Conductor.Steps/Conductor.Steps.csproj | 2 +- Conductor.sln | 14 ++----- Conductor/Conductor.csproj | 9 ++++- Conductor/Conductor.csproj.user | 2 +- Conductor/Controllers/EventController.cs | 2 +- .../RawRequestBodyInputFormatter.cs | 37 ------------------- .../YamlRequestBodyInputFormatter.cs | 5 ++- .../YamlRequestBodyOutputFormatter.cs | 30 +++++++++++++++ Conductor/Properties/launchSettings.json | 17 ++++++--- Conductor/Startup.cs | 3 +- Dockerfile | 23 ++++++++++++ 13 files changed, 94 insertions(+), 64 deletions(-) create mode 100644 .dockerignore delete mode 100644 Conductor/Formatters/RawRequestBodyInputFormatter.cs create mode 100644 Conductor/Formatters/YamlRequestBodyOutputFormatter.cs create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..df2e0fe --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.dockerignore +.env +.git +.gitignore +.vs +.vscode +*/bin +*/obj +**/.toolstarget \ No newline at end of file diff --git a/Conductor.Domain/Conductor.Domain.csproj b/Conductor.Domain/Conductor.Domain.csproj index 74e11e9..2c6c9fa 100644 --- a/Conductor.Domain/Conductor.Domain.csproj +++ b/Conductor.Domain/Conductor.Domain.csproj @@ -7,10 +7,7 @@ - - - - + diff --git a/Conductor.Steps/Conductor.Steps.csproj b/Conductor.Steps/Conductor.Steps.csproj index 9fc5207..9235843 100644 --- a/Conductor.Steps/Conductor.Steps.csproj +++ b/Conductor.Steps/Conductor.Steps.csproj @@ -5,7 +5,7 @@ - + diff --git a/Conductor.sln b/Conductor.sln index 0f06cb2..7e3e974 100644 --- a/Conductor.sln +++ b/Conductor.sln @@ -16,9 +16,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scratch", "Scratch", "{29F7 1.yaml = 1.yaml EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WorkflowCore", "WorkflowCore", "{50A4A1A7-403C-4B9E-BF53-FA6C1840086B}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkflowCore", "..\workflow-core\src\WorkflowCore\WorkflowCore.csproj", "{692E5594-87E7-4BD8-8746-A6C33562A056}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B3E1C72D-C63A-4A85-AAC1-AF7C1F072907}" + ProjectSection(SolutionItems) = preProject + Dockerfile = Dockerfile + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -42,17 +43,10 @@ Global {C9DA979C-9D97-4D8B-B297-C0DEC68C9490}.Debug|Any CPU.Build.0 = Debug|Any CPU {C9DA979C-9D97-4D8B-B297-C0DEC68C9490}.Release|Any CPU.ActiveCfg = Release|Any CPU {C9DA979C-9D97-4D8B-B297-C0DEC68C9490}.Release|Any CPU.Build.0 = Release|Any CPU - {692E5594-87E7-4BD8-8746-A6C33562A056}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {692E5594-87E7-4BD8-8746-A6C33562A056}.Debug|Any CPU.Build.0 = Debug|Any CPU - {692E5594-87E7-4BD8-8746-A6C33562A056}.Release|Any CPU.ActiveCfg = Release|Any CPU - {692E5594-87E7-4BD8-8746-A6C33562A056}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {692E5594-87E7-4BD8-8746-A6C33562A056} = {50A4A1A7-403C-4B9E-BF53-FA6C1840086B} - EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B88BB9DA-8644-464E-820C-100F799AD7E2} EndGlobalSection diff --git a/Conductor/Conductor.csproj b/Conductor/Conductor.csproj index 1760454..cf39cfb 100644 --- a/Conductor/Conductor.csproj +++ b/Conductor/Conductor.csproj @@ -3,16 +3,23 @@ netcoreapp2.2 InProcess + Linux + 0b178d89-9937-49c8-b1f1-efb5f96e516d + + + + + + - diff --git a/Conductor/Conductor.csproj.user b/Conductor/Conductor.csproj.user index 7f376b2..79243e9 100644 --- a/Conductor/Conductor.csproj.user +++ b/Conductor/Conductor.csproj.user @@ -9,7 +9,7 @@ True False - Conductor + Docker ProjectDebugger diff --git a/Conductor/Controllers/EventController.cs b/Conductor/Controllers/EventController.cs index e89c170..e5cf5b5 100644 --- a/Conductor/Controllers/EventController.cs +++ b/Conductor/Controllers/EventController.cs @@ -24,7 +24,7 @@ public EventController(IWorkflowController workflowController) } [HttpPost("{name}/{key}")] - public async Task Post(string name, string key, [FromBody] JObject data) + public async Task Post(string name, string key, [FromBody] object data) { await _workflowController.PublishEvent(name, key, data); Response.StatusCode = 204; diff --git a/Conductor/Formatters/RawRequestBodyInputFormatter.cs b/Conductor/Formatters/RawRequestBodyInputFormatter.cs deleted file mode 100644 index 32796c8..0000000 --- a/Conductor/Formatters/RawRequestBodyInputFormatter.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Formatters; - -namespace Conductor.Formatters -{ - public class RawRequestBodyInputFormatter : InputFormatter - { - public override bool CanRead(InputFormatterContext context) - { - return (context.HttpContext.Request.ContentType == "application/json") ? false : true; - } - - public override async Task ReadRequestBodyAsync(InputFormatterContext context) - { - if (context == null) - throw new ArgumentNullException(nameof(context)); - - var request = context.HttpContext.Request; - using (var reader = new StreamReader(request.Body)) - { - try - { - var content = await reader.ReadToEndAsync(); - return await InputFormatterResult.SuccessAsync(content); - } - catch - { - return await InputFormatterResult.FailureAsync(); - } - } - } - } -} diff --git a/Conductor/Formatters/YamlRequestBodyInputFormatter.cs b/Conductor/Formatters/YamlRequestBodyInputFormatter.cs index 50c28af..c8d6eaf 100644 --- a/Conductor/Formatters/YamlRequestBodyInputFormatter.cs +++ b/Conductor/Formatters/YamlRequestBodyInputFormatter.cs @@ -11,9 +11,10 @@ namespace Conductor.Formatters { public class YamlRequestBodyInputFormatter : InputFormatter { - public override bool CanRead(InputFormatterContext context) + public YamlRequestBodyInputFormatter() { - return (context.HttpContext.Request.ContentType == "application/x-yaml"); + SupportedMediaTypes.Add("application/x-yaml"); + SupportedMediaTypes.Add("application/yaml"); } public override async Task ReadRequestBodyAsync(InputFormatterContext context) diff --git a/Conductor/Formatters/YamlRequestBodyOutputFormatter.cs b/Conductor/Formatters/YamlRequestBodyOutputFormatter.cs new file mode 100644 index 0000000..3e26373 --- /dev/null +++ b/Conductor/Formatters/YamlRequestBodyOutputFormatter.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Conductor.Domain.Models; +using Microsoft.AspNetCore.Mvc.Formatters; +using SharpYaml.Serialization; + +namespace Conductor.Formatters +{ + public class YamlRequestBodyOutputFormatter : OutputFormatter + { + + public YamlRequestBodyOutputFormatter() + { + SupportedMediaTypes.Add("application/x-yaml"); + SupportedMediaTypes.Add("application/yaml"); + } + + public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context) + { + var response = context.HttpContext.Response; + var serializer = new Serializer(); + var body = Encoding.UTF8.GetBytes(serializer.Serialize(context.Object)); + await response.Body.WriteAsync(body, 0, body.Length); + } + } +} diff --git a/Conductor/Properties/launchSettings.json b/Conductor/Properties/launchSettings.json index d8cb2cb..a0c808e 100644 --- a/Conductor/Properties/launchSettings.json +++ b/Conductor/Properties/launchSettings.json @@ -1,13 +1,13 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", +{ "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, + "windowsAuthentication": false, + "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:61924", "sslPort": 44340 } }, + "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { "IIS Express": { "commandName": "IISExpress", @@ -21,10 +21,15 @@ "commandName": "Project", "launchBrowser": true, "launchUrl": "api/values", - "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000" + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/api/values" } } } \ No newline at end of file diff --git a/Conductor/Startup.cs b/Conductor/Startup.cs index 11b8dc4..56698ba 100644 --- a/Conductor/Startup.cs +++ b/Conductor/Startup.cs @@ -33,7 +33,8 @@ public void ConfigureServices(IServiceCollection services) { services.AddMvc(options => { - options.InputFormatters.Insert(0, new YamlRequestBodyInputFormatter()); + options.InputFormatters.Add(new YamlRequestBodyInputFormatter()); + options.OutputFormatters.Add(new YamlRequestBodyOutputFormatter()); }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..57d5e45 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM microsoft/dotnet:2.2-sdk AS build +WORKDIR /src +COPY ["Conductor/Conductor.csproj", "Conductor/"] +COPY ["Conductor.Steps/Conductor.Steps.csproj", "Conductor.Steps/"] +COPY ["Conductor.Domain/Conductor.Domain.csproj", "Conductor.Domain/"] +COPY ["Conductor.Storage/Conductor.Storage.csproj", "Conductor.Storage/"] +RUN dotnet restore "Conductor/Conductor.csproj" +COPY . . +WORKDIR "/src/Conductor" +RUN dotnet build "Conductor.csproj" -c Release -o /app + +FROM build AS publish +RUN dotnet publish "Conductor.csproj" -c Release -o /app + +FROM base AS final +WORKDIR /app +COPY --from=publish /app . +ENTRYPOINT ["dotnet", "Conductor.dll"] \ No newline at end of file