From 518c158c8599032df65df62465c5df4b9b3dfdc2 Mon Sep 17 00:00:00 2001 From: Denis Prokhorchik Date: Wed, 16 Mar 2022 00:42:34 +0300 Subject: [PATCH] fix(issue-225): update docker-compose file --- .../auth/O2NextGen.Auth.Web/Dockerfile | 4 +- .../Dockerfile | 4 +- .../appsettings.json | 14 ++-- .../e-sender/O2NextGen.ESender.Api/Dockerfile | 4 +- .../e-sender/O2NextGen.ESender.Api/Startup.cs | 2 - .../Controllers/ChatController.cs | 34 +++++++++ .../Controllers/VersionController.cs | 1 + .../O2NextGen.SmallTalk.Api/Dockerfile | 4 +- .../Helpers/ServiceCollectionExtensions.cs | 53 +++++++++++++ .../Services/ChatSession.cs | 8 ++ .../Services/IChatService.cs | 15 ++++ .../Services/InMemoryChatService.cs | 74 +++++++++++++++++++ .../O2NextGen.SmallTalk.Api/Startup.cs | 16 +--- src/docker-compose.override.yml | 70 +++++++++++++----- src/launchSettings.json | 15 ++++ 15 files changed, 270 insertions(+), 48 deletions(-) create mode 100644 src/Services/smalltalk/O2NextGen.SmallTalk.Api/Controllers/ChatController.cs create mode 100644 src/Services/smalltalk/O2NextGen.SmallTalk.Api/Helpers/ServiceCollectionExtensions.cs create mode 100644 src/Services/smalltalk/O2NextGen.SmallTalk.Api/Services/ChatSession.cs create mode 100644 src/Services/smalltalk/O2NextGen.SmallTalk.Api/Services/IChatService.cs create mode 100644 src/Services/smalltalk/O2NextGen.SmallTalk.Api/Services/InMemoryChatService.cs create mode 100644 src/launchSettings.json diff --git a/src/Services/auth/O2NextGen.Auth.Web/Dockerfile b/src/Services/auth/O2NextGen.Auth.Web/Dockerfile index dc1bb794..414170f2 100644 --- a/src/Services/auth/O2NextGen.Auth.Web/Dockerfile +++ b/src/Services/auth/O2NextGen.Auth.Web/Dockerfile @@ -1,11 +1,11 @@ #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. -FROM mcr.microsoft.com/dotnet/aspnet:2.2 AS base +FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base WORKDIR /app EXPOSE 80 EXPOSE 443 -FROM mcr.microsoft.com/dotnet/sdk:2.2 AS build +FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /src COPY ["Services/auth/O2NextGen.Auth.Web/O2NextGen.Auth.Web.csproj", "Services/auth/O2NextGen.Auth.Web/"] RUN dotnet restore "Services/auth/O2NextGen.Auth.Web/O2NextGen.Auth.Web.csproj" diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/Dockerfile b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/Dockerfile index a797a893..ff952f71 100644 --- a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/Dockerfile +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/Dockerfile @@ -1,11 +1,11 @@ #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. -FROM mcr.microsoft.com/dotnet/aspnet:2.2 AS base +FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base WORKDIR /app EXPOSE 80 EXPOSE 443 -FROM mcr.microsoft.com/dotnet/sdk:2.2 AS build +FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /src COPY ["Services/c-gen/O2NextGen.CertificateManagement.Api/O2NextGen.CertificateManagement.Api.csproj", "Services/c-gen/O2NextGen.CertificateManagement.Api/"] COPY ["Services/c-gen/O2NextGen.CertificateManagement.Data/O2NextGen.CertificateManagement.Data.csproj", "Services/c-gen/O2NextGen.CertificateManagement.Data/"] diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/appsettings.json b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/appsettings.json index f98779d4..3134b830 100644 --- a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/appsettings.json +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/appsettings.json @@ -9,13 +9,13 @@ "FromLogContext" ], "WriteTo": [ - { - "Name": "File", - "Args": { - "path": "Logs/log.txt", - "formatter": "O2NextGen.ESender.Api.Logging.ElasticJsonFormatter, O2NextGen.ESender.Api" - } - }, + //{ + // "Name": "File", + // "Args": { + // "path": "Logs/log.txt", + // "formatter": "O2NextGen.ESender.Api.Logging.ElasticJsonFormatter, O2NextGen.ESender.Api" + // } + //}, { "Name": "Console" } diff --git a/src/Services/e-sender/O2NextGen.ESender.Api/Dockerfile b/src/Services/e-sender/O2NextGen.ESender.Api/Dockerfile index e13b327d..4e582791 100644 --- a/src/Services/e-sender/O2NextGen.ESender.Api/Dockerfile +++ b/src/Services/e-sender/O2NextGen.ESender.Api/Dockerfile @@ -1,11 +1,11 @@ #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. -FROM mcr.microsoft.com/dotnet/aspnet:2.2 AS base +FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base WORKDIR /app EXPOSE 80 EXPOSE 443 -FROM mcr.microsoft.com/dotnet/sdk:2.2 AS build +FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /src COPY ["Services/e-sender/O2NextGen.ESender.Api/O2NextGen.ESender.Api.csproj", "Services/e-sender/O2NextGen.ESender.Api/"] COPY ["Services/e-sender/O2NextGen.ESender.Impl/O2NextGen.ESender.Impl.csproj", "Services/e-sender/O2NextGen.ESender.Impl/"] diff --git a/src/Services/e-sender/O2NextGen.ESender.Api/Startup.cs b/src/Services/e-sender/O2NextGen.ESender.Api/Startup.cs index 54d65a6f..53363198 100644 --- a/src/Services/e-sender/O2NextGen.ESender.Api/Startup.cs +++ b/src/Services/e-sender/O2NextGen.ESender.Api/Startup.cs @@ -1,10 +1,8 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using O2NextGen.ESender.Api.Helpers; using O2NextGen.ESender.Api.IoC; using O2NextGen.ESender.Api.Setup; diff --git a/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Controllers/ChatController.cs b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Controllers/ChatController.cs new file mode 100644 index 00000000..9af8bd78 --- /dev/null +++ b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Controllers/ChatController.cs @@ -0,0 +1,34 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace O2NextGen.SmallTalk.Api.Controllers +{ + public class ChatController : ControllerBase + { + #region Fields + + private readonly IHostingEnvironment _environment; + private readonly ILogger _logger; + + #endregion + + + #region Ctors + + public ChatController(IHostingEnvironment environment, ILogger logger) + { + _environment = environment; + _logger = logger; + } + + #endregion + + + #region Methods + + + + #endregion + } +} diff --git a/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Controllers/VersionController.cs b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Controllers/VersionController.cs index a90d91d3..ad483f54 100644 --- a/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Controllers/VersionController.cs +++ b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Controllers/VersionController.cs @@ -28,6 +28,7 @@ public VersionController(IHostingEnvironment environment, ILogger(this IServiceCollection services, IConfiguration configuration) + where TConfig : class, new() + { + if (services == null) + throw new ArgumentNullException(nameof(services)); + + if (configuration == null) + throw new ArgumentNullException(nameof(configuration)); + + var config = new TConfig(); + configuration.Bind(config); + services.AddSingleton(config); + return config; + } + + + public static IServiceCollection AddBusiness(this IServiceCollection services) + { + // services.AddSingleton(); + // Include DataLayer + //services.AddScoped(); + //more business services... + + services.AddSingleton(); + return services; + } + + public static IServiceCollection AddRequiredMvcComponents(this IServiceCollection services) + { + //services.AddTransient(); + + var mvcBuilder = services.AddMvc(options => + { + // options.Filters.Add(); + }); + mvcBuilder.SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + + return services; + } + } +} + diff --git a/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Services/ChatSession.cs b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Services/ChatSession.cs new file mode 100644 index 00000000..014cec81 --- /dev/null +++ b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Services/ChatSession.cs @@ -0,0 +1,8 @@ +namespace O2NextGen.SmallTalk.Api.Services +{ + public class ChatSession + { + public long Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Services/IChatService.cs b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Services/IChatService.cs new file mode 100644 index 00000000..f23036e4 --- /dev/null +++ b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Services/IChatService.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace O2NextGen.SmallTalk.Api.Services +{ + public interface IChatService + { + Task> GetAllAsync(CancellationToken ct); + Task GetByIdAsync(long id, CancellationToken ct); + Task UpdateAsync(ChatSession certificate, CancellationToken ct); + Task AddAsync(ChatSession certificate, CancellationToken ct); + Task RemoveAsync(long id, CancellationToken ct); + } +} diff --git a/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Services/InMemoryChatService.cs b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Services/InMemoryChatService.cs new file mode 100644 index 00000000..45dede40 --- /dev/null +++ b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Services/InMemoryChatService.cs @@ -0,0 +1,74 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace O2NextGen.SmallTalk.Api.Services +{ + public class InMemoryChatService : IChatService + { + #region Fields + + private static readonly List Sessions = new List() + { + new ChatSession() + { + Id = 1, Name = "First" + } + }; + private long _currentId; + + #endregion + + + #region Ctors + + public InMemoryChatService() + { + _currentId = Sessions.Count(); + } + + #endregion + + + #region Methods + public async Task> GetAllAsync(CancellationToken ct) + { + await Task.Delay(3000, ct); + return await Task.FromResult>(Sessions.AsReadOnly()); + } + + public async Task GetByIdAsync(long id, CancellationToken ct) + { + await Task.Delay(3000, ct); + return await Task.FromResult(Sessions.SingleOrDefault(g => g.Id == id)); + } + + public async Task UpdateAsync(ChatSession certificate, CancellationToken ct) + { + await Task.Delay(5000, ct); + var toUpdate = Sessions.SingleOrDefault(g => g.Id == certificate.Id); + if (toUpdate == null) + return null; + + toUpdate.Name = certificate.Name; + + return await Task.FromResult(toUpdate); + } + + public async Task AddAsync(ChatSession certificate, CancellationToken ct) + { + await Task.Delay(3000, ct); + certificate.Id = ++_currentId; + Sessions.Add(certificate); + return await Task.FromResult(certificate); + } + + public Task RemoveAsync(long id, CancellationToken ct) + { + throw new System.NotImplementedException(); + } + + #endregion + } +} diff --git a/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Startup.cs b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Startup.cs index a142a634..45808f1f 100644 --- a/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Startup.cs +++ b/src/Services/smalltalk/O2NextGen.SmallTalk.Api/Startup.cs @@ -1,15 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; +using O2NextGen.SmallTalk.Api.Helpers; namespace O2NextGen.SmallTalk.Api { @@ -22,13 +15,12 @@ public Startup(IConfiguration configuration) public IConfiguration Configuration { get; } - // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + services.AddRequiredMvcComponents(); + services.AddBusiness(); } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) diff --git a/src/docker-compose.override.yml b/src/docker-compose.override.yml index e64936a5..998fa852 100644 --- a/src/docker-compose.override.yml +++ b/src/docker-compose.override.yml @@ -1,46 +1,78 @@ version: '3.4' +networks: + frontend: + backend: + services: + sql.data: + image: mcr.microsoft.com/mssql/server:2017-latest + container_name: sqldatacontainer + environment: + - SA_PASSWORD=your@Password + - ACCEPT_EULA=Y + # - MSSQL_PID=Developer + ports: + - "5433:1433" + networks: + - backend o2nextgen.auth.web: environment: - ASPNETCORE_ENVIRONMENT=Development + - ConnectionString="Server=sql.data;Initial Catalog=O2NextGen.AuthDb;Persist Security Info=False;User ID=sa;Password=your@Password;Connection Timeout=30;" #- ASPNETCORE_URLS=https://+:443;http://+:80 ports: - - "80:5001" - - "443:10001" - volumes: - - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro + - "5001:80" + # - "10001:443" + #volumes: + # - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro + depends_on: + - sql.data + networks: + - backend o2nextgen.certificatemanagement.api: environment: - ASPNETCORE_ENVIRONMENT=Development + - ConnectionString=Server=sql.data;Initial Catalog=O2NextGen.CGenDb;Persist Security Info=False;User ID=sa;Password=your@Password;Connection Timeout=30; + #- Serilog__Enrich=FromLogContext + #- Serilog__WriteTo__Name=Console #- ASPNETCORE_URLS=https://+:443;http://+:80 ports: - - "80:5002" - - "443:10002" - volumes: - - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro - - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro + - "5002:80" + depends_on: + - sql.data + networks: + - backend + # - "10002:443" + #volumes: + #- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro + #- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro o2nextgen.smalltalk.api: environment: - ASPNETCORE_ENVIRONMENT=Development #- ASPNETCORE_URLS=https://+:443;http://+:80 ports: - - "80:5003" - - "443:10003" - volumes: - - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro - - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro + - "5003:80" + # - "10003:443" + #volumes: + # - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro + # - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro o2nextgen.esender.api: environment: - ASPNETCORE_ENVIRONMENT=Development + - ConnectionString=Server=sql.data;Initial Catalog=O2NextGen.ESenderDb;Persist Security Info=False;User ID=sa;Password=your@Password;Connection Timeout=30; #- ASPNETCORE_URLS=https://+:443;http://+:80 ports: - - "80:5004" - - "443:10004" - volumes: - - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro - - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro + - "5004:80" + depends_on: + - sql.data + networks: + - backend + # - "10004:443" + #volumes: + # - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro + # - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro diff --git a/src/launchSettings.json b/src/launchSettings.json new file mode 100644 index 00000000..c64ede92 --- /dev/null +++ b/src/launchSettings.json @@ -0,0 +1,15 @@ +{ + "profiles": { + "Docker Compose": { + "commandName": "DockerCompose", + "commandVersion": "1.0", + "serviceActions": { + "o2nextgen.auth.web": "StartDebugging", + "o2nextgen.certificatemanagement.api": "StartDebugging", + "o2nextgen.esender.api": "StartDebugging", + "o2nextgen.smalltalk.api": "StartDebugging", + "sql.data": "StartWithoutDebugging" + } + } + } +} \ No newline at end of file