diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3729ff0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/Chess.sln b/Chess.sln new file mode 100644 index 0000000..6f4f4ff --- /dev/null +++ b/Chess.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33815.320 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TURN.Services.Chess", "TURN.Services.Chess\TURN.Services.Chess.csproj", "{8D4377EA-91FB-464B-8B16-3BEE15F56616}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TURN.Libraries.Core", "TURN.Libraries.Core\TURN.Libraries.Core.csproj", "{54ACF6B1-2512-47C4-877A-5B78E9001B8C}" +EndProject +Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{9E564C7C-C521-47AC-9CD1-F475B2E4174C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8D4377EA-91FB-464B-8B16-3BEE15F56616}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D4377EA-91FB-464B-8B16-3BEE15F56616}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D4377EA-91FB-464B-8B16-3BEE15F56616}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D4377EA-91FB-464B-8B16-3BEE15F56616}.Release|Any CPU.Build.0 = Release|Any CPU + {54ACF6B1-2512-47C4-877A-5B78E9001B8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {54ACF6B1-2512-47C4-877A-5B78E9001B8C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {54ACF6B1-2512-47C4-877A-5B78E9001B8C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {54ACF6B1-2512-47C4-877A-5B78E9001B8C}.Release|Any CPU.Build.0 = Release|Any CPU + {9E564C7C-C521-47AC-9CD1-F475B2E4174C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9E564C7C-C521-47AC-9CD1-F475B2E4174C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9E564C7C-C521-47AC-9CD1-F475B2E4174C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9E564C7C-C521-47AC-9CD1-F475B2E4174C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {14F45E3F-FCDD-4DA0-99D5-E88D10CF7C4F} + EndGlobalSection +EndGlobal diff --git a/TURN.Libraries.Core/LoggerFactory.cs b/TURN.Libraries.Core/LoggerFactory.cs new file mode 100644 index 0000000..c6c1042 --- /dev/null +++ b/TURN.Libraries.Core/LoggerFactory.cs @@ -0,0 +1,38 @@ +using System; +using System.Text; +using NLog; +using NLog.Targets; + +namespace TURN.Libraries.Core +{ + public static class LoggerFactory + { + public static Logger GetLogger() + { + return LogManager.Setup().LoadConfiguration(c => + { + ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget() + { + Layout = "${date}|${level:uppercase=true}|${message:withexception=true}" + }; + FileTarget fileTarget = new FileTarget() + { + FileName = Environment.GetEnvironmentVariable("LOG_FILE_PATH"), + Layout = "${date}|${level:uppercase=true}|${message:withexception=true}", + Encoding = Encoding.UTF8, + LineEnding = LineEndingMode.CRLF, + KeepFileOpen = true, + ConcurrentWrites = true, + ArchiveAboveSize = long.Parse(Environment.GetEnvironmentVariable("LOG_FILE_SIZE")), + MaxArchiveFiles = 10, + MaxArchiveDays = 365 + }; + + _ = c.ForLogger("consoleAndFile") + .FilterMinLevel(LogLevel.Debug) + .WriteTo(consoleTarget) + .WriteTo(fileTarget); + }).GetLogger("consoleAndFile"); + } + } +} diff --git a/TURN.Libraries.Core/Properties/AssemblyInfo.cs b/TURN.Libraries.Core/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..740a6f9 --- /dev/null +++ b/TURN.Libraries.Core/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TURN.Libraries.Core")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("*")] +[assembly: AssemblyProduct("TURN.Libraries.Core")] +[assembly: AssemblyCopyright("Copyright © * 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("54acf6b1-2512-47c4-877a-5b78e9001b8c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TURN.Libraries.Core/TURN.Libraries.Core.csproj b/TURN.Libraries.Core/TURN.Libraries.Core.csproj new file mode 100644 index 0000000..c667a4b --- /dev/null +++ b/TURN.Libraries.Core/TURN.Libraries.Core.csproj @@ -0,0 +1,56 @@ + + + + + Debug + AnyCPU + {54ACF6B1-2512-47C4-877A-5B78E9001B8C} + Library + Properties + TURN.Libraries.Core + TURN.Libraries.Core + v4.8 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\NLog.5.2.0\lib\net46\NLog.dll + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TURN.Libraries.Core/packages.config b/TURN.Libraries.Core/packages.config new file mode 100644 index 0000000..367cb28 --- /dev/null +++ b/TURN.Libraries.Core/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/TURN.Services.Chess/Controllers/TurnController.cs b/TURN.Services.Chess/Controllers/TurnController.cs new file mode 100644 index 0000000..e0dc3ad --- /dev/null +++ b/TURN.Services.Chess/Controllers/TurnController.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Mvc; + +namespace TURN.Services.Chess.Controllers +{ + [Route("/[controller]")] + [ApiController] + public class TurnController : ControllerBase + { + /// + /// Тестовый гет. + /// + [HttpGet("test/{param}")] + public ActionResult Get(string param) + { + try + { + return Ok(param); + } + catch (Exception ex) + { + return StatusCode(500, $"Internal server error: {ex.Message}"); + } + } + } +} diff --git a/TURN.Services.Chess/Dockerfile b/TURN.Services.Chess/Dockerfile new file mode 100644 index 0000000..6a6fa2e --- /dev/null +++ b/TURN.Services.Chess/Dockerfile @@ -0,0 +1,21 @@ +#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base +WORKDIR /app + +FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +WORKDIR /src +COPY ["TURN.Services.Chess/TURN.Services.Chess.csproj", "TURN.Services.Chess/"] +COPY ["TURN.Libraries.Core/TURN.Libraries.Core.csproj", "TURN.Libraries.Core/"] +RUN dotnet restore "TURN.Services.Chess/TURN.Services.Chess.csproj" +COPY . . +WORKDIR "/src/TURN.Services.Chess" +RUN dotnet build "TURN.Services.Chess.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "TURN.Services.Chess.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "TURN.Services.Chess.dll"] \ No newline at end of file diff --git a/TURN.Services.Chess/Program.cs b/TURN.Services.Chess/Program.cs new file mode 100644 index 0000000..414ea38 --- /dev/null +++ b/TURN.Services.Chess/Program.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore; +using TURN.Services.Chess; +using LoggerFactory = TURN.Libraries.Core.LoggerFactory; + +NLog.Logger logger = LoggerFactory.GetLogger(); +logger.Info("Chess app starting."); + +try +{ + IWebHost host = BuildWebHost(args); + host.Run(); +} +catch (Exception ex) +{ + logger.Error(ex); +} + +IWebHost BuildWebHost(string[] args) => WebHost + .CreateDefaultBuilder(args) + .CaptureStartupErrors(false) + .ConfigureServices(services => + { + _ = services.AddSingleton(logger); + }) + .UseStartup() + .Build(); diff --git a/TURN.Services.Chess/Properties/launchSettings.json b/TURN.Services.Chess/Properties/launchSettings.json new file mode 100644 index 0000000..322941c --- /dev/null +++ b/TURN.Services.Chess/Properties/launchSettings.json @@ -0,0 +1,32 @@ +{ + "profiles": { + "http": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5110" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Docker": { + "commandName": "Docker", + "publishAllPorts": true + } + }, + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:12777", + "sslPort": 0 + } + } +} \ No newline at end of file diff --git a/TURN.Services.Chess/Startup.cs b/TURN.Services.Chess/Startup.cs new file mode 100644 index 0000000..e559876 --- /dev/null +++ b/TURN.Services.Chess/Startup.cs @@ -0,0 +1,51 @@ +using System.Reflection; +using Microsoft.OpenApi.Models; +using Newtonsoft.Json.Converters; + +namespace TURN.Services.Chess +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + ConfigureSwagger(services); + _ = services.AddControllers(); + _ = services.AddControllers().AddNewtonsoftJson(jsonOptions => + { + jsonOptions.SerializerSettings.Converters.Add(new StringEnumConverter()); + }); + //_ = services.AddDbContext( + // options => options.UseSqlServer(Environment.GetEnvironmentVariable("DB"))); + } + + public void Configure(IApplicationBuilder app) + { + _ = app.UseRouting(); + _ = app.UseSwagger(); + _ = app.UseSwaggerUI(); + _ = app.UseEndpoints(endpoints => + { + _ = endpoints.MapControllers(); + _ = endpoints.MapControllerRoute( + name: "default", + pattern: "{controller}/{action}"); + _ = endpoints.MapSwagger(); + }); + } + + private void ConfigureSwagger(IServiceCollection services) + { + _ = services.AddSwaggerGen(options => + { + options.SwaggerDoc("v1", new OpenApiInfo + { + Title = "TURN.Api.Swagger", + Version = "v1" + }); + string xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); + }); + _ = services.AddSwaggerGenNewtonsoftSupport(); + } + } +} diff --git a/TURN.Services.Chess/TURN.Services.Chess.csproj b/TURN.Services.Chess/TURN.Services.Chess.csproj new file mode 100644 index 0000000..df07ebe --- /dev/null +++ b/TURN.Services.Chess/TURN.Services.Chess.csproj @@ -0,0 +1,28 @@ + + + + net7.0 + enable + enable + Linux + ..\docker-compose.dcproj + true + $(NoWarn);1591 + + + + + + + + + + + + + + + + + + diff --git a/TURN.Services.Chess/appsettings.Development.json b/TURN.Services.Chess/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/TURN.Services.Chess/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/TURN.Services.Chess/appsettings.json b/TURN.Services.Chess/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/TURN.Services.Chess/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/docker-compose.dcproj b/docker-compose.dcproj new file mode 100644 index 0000000..fca38b7 --- /dev/null +++ b/docker-compose.dcproj @@ -0,0 +1,12 @@ + + + + 2.1 + Linux + 9e564c7c-c521-47ac-9cd1-f475b2e4174c + + + + + + \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..994463c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,42 @@ +version: '3.4' + +services: + chess: + build: + context: . + dockerfile: TURN.Services.Chess\Dockerfile + environment: + - LOG_FILE_PATH=/logs/log.log + - LOG_FILE_SIZE=50000000 + ports: + - 80:80 + volumes: + - /d/programming/ChessData:/logs + networks: + - app-network + + postgresdb: + image: postgres + restart: always + ports: + - 5432:5432 + environment: + - POSTGRES_DB=TURNChese + - POSTGRES_PASSWORD=example + - PGDATA=/var/lib/postgresql/data/pgdata + volumes: + - /d/programming/ChessData/pgdata:/var/lib/postgresql/data + networks: + - app-network + + adminer: + image: adminer + restart: always + ports: + - 8080:8080 + networks: + - app-network + +networks: + app-network: + driver: bridge diff --git a/launchSettings.json b/launchSettings.json new file mode 100644 index 0000000..871bf1a --- /dev/null +++ b/launchSettings.json @@ -0,0 +1,11 @@ +{ + "profiles": { + "Docker Compose": { + "commandName": "DockerCompose", + "commandVersion": "1.0", + "serviceActions": { + "turn.services.chess": "StartDebugging" + } + } + } +} \ No newline at end of file