From 00bde7a283b14c1b585afa976da61c8fc925862f Mon Sep 17 00:00:00 2001 From: schmelczerandras Date: Fri, 17 Jul 2020 14:49:31 +0200 Subject: [PATCH] Add configuration server template --- config/ConfigurationServer/.dockerignore | 25 ++++++++++ config/ConfigurationServer/.gitignore | 4 ++ .../ConfigurationServer.csproj | 14 ++++++ .../ConfigurationServer.sln | 25 ++++++++++ .../Controllers/WeatherForecastController.cs | 39 +++++++++++++++ config/ConfigurationServer/Dockerfile | 21 ++++++++ config/ConfigurationServer/Program.cs | 26 ++++++++++ .../Properties/launchSettings.json | 36 ++++++++++++++ config/ConfigurationServer/Startup.cs | 48 +++++++++++++++++++ config/ConfigurationServer/WeatherForecast.cs | 15 ++++++ .../appsettings.Development.json | 9 ++++ config/ConfigurationServer/appsettings.json | 10 ++++ 12 files changed, 272 insertions(+) create mode 100644 config/ConfigurationServer/.dockerignore create mode 100644 config/ConfigurationServer/.gitignore create mode 100644 config/ConfigurationServer/ConfigurationServer.csproj create mode 100644 config/ConfigurationServer/ConfigurationServer.sln create mode 100644 config/ConfigurationServer/Controllers/WeatherForecastController.cs create mode 100644 config/ConfigurationServer/Dockerfile create mode 100644 config/ConfigurationServer/Program.cs create mode 100644 config/ConfigurationServer/Properties/launchSettings.json create mode 100644 config/ConfigurationServer/Startup.cs create mode 100644 config/ConfigurationServer/WeatherForecast.cs create mode 100644 config/ConfigurationServer/appsettings.Development.json create mode 100644 config/ConfigurationServer/appsettings.json diff --git a/config/ConfigurationServer/.dockerignore b/config/ConfigurationServer/.dockerignore new file mode 100644 index 0000000..3729ff0 --- /dev/null +++ b/config/ConfigurationServer/.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/config/ConfigurationServer/.gitignore b/config/ConfigurationServer/.gitignore new file mode 100644 index 0000000..bd7da14 --- /dev/null +++ b/config/ConfigurationServer/.gitignore @@ -0,0 +1,4 @@ +bin +obj +.vs +*.user diff --git a/config/ConfigurationServer/ConfigurationServer.csproj b/config/ConfigurationServer/ConfigurationServer.csproj new file mode 100644 index 0000000..f5db55a --- /dev/null +++ b/config/ConfigurationServer/ConfigurationServer.csproj @@ -0,0 +1,14 @@ + + + + netcoreapp3.1 + Linux + . + + + + + + + + diff --git a/config/ConfigurationServer/ConfigurationServer.sln b/config/ConfigurationServer/ConfigurationServer.sln new file mode 100644 index 0000000..3715c7a --- /dev/null +++ b/config/ConfigurationServer/ConfigurationServer.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30309.148 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfigurationServer", "ConfigurationServer.csproj", "{CD78C1FA-1A88-4299-961B-2B5424DBEEDF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CD78C1FA-1A88-4299-961B-2B5424DBEEDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD78C1FA-1A88-4299-961B-2B5424DBEEDF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD78C1FA-1A88-4299-961B-2B5424DBEEDF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD78C1FA-1A88-4299-961B-2B5424DBEEDF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5CE906F0-BAD5-4BD3-B3D7-1D26E4D6385C} + EndGlobalSection +EndGlobal diff --git a/config/ConfigurationServer/Controllers/WeatherForecastController.cs b/config/ConfigurationServer/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..3ea0014 --- /dev/null +++ b/config/ConfigurationServer/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace ConfigurationServer.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/config/ConfigurationServer/Dockerfile b/config/ConfigurationServer/Dockerfile new file mode 100644 index 0000000..26db67a --- /dev/null +++ b/config/ConfigurationServer/Dockerfile @@ -0,0 +1,21 @@ +#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/core/aspnet:3.1-buster-slim AS base +WORKDIR /app +EXPOSE 80 + +FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build +WORKDIR /src +COPY ["ConfigurationServer.csproj", ""] +RUN dotnet restore "./ConfigurationServer.csproj" +COPY . . +WORKDIR "/src/." +RUN dotnet build "ConfigurationServer.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "ConfigurationServer.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "ConfigurationServer.dll"] \ No newline at end of file diff --git a/config/ConfigurationServer/Program.cs b/config/ConfigurationServer/Program.cs new file mode 100644 index 0000000..7459de3 --- /dev/null +++ b/config/ConfigurationServer/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace ConfigurationServer +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/config/ConfigurationServer/Properties/launchSettings.json b/config/ConfigurationServer/Properties/launchSettings.json new file mode 100644 index 0000000..e54db27 --- /dev/null +++ b/config/ConfigurationServer/Properties/launchSettings.json @@ -0,0 +1,36 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:63198", + "sslPort": 0 + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "ConfigurationServer": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:5000" + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/weatherforecast", + "publishAllPorts": true + } + } +} \ No newline at end of file diff --git a/config/ConfigurationServer/Startup.cs b/config/ConfigurationServer/Startup.cs new file mode 100644 index 0000000..5268c56 --- /dev/null +++ b/config/ConfigurationServer/Startup.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +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 Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace ConfigurationServer +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = 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.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/config/ConfigurationServer/WeatherForecast.cs b/config/ConfigurationServer/WeatherForecast.cs new file mode 100644 index 0000000..e4664f1 --- /dev/null +++ b/config/ConfigurationServer/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace ConfigurationServer +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git a/config/ConfigurationServer/appsettings.Development.json b/config/ConfigurationServer/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/config/ConfigurationServer/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/config/ConfigurationServer/appsettings.json b/config/ConfigurationServer/appsettings.json new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ b/config/ConfigurationServer/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +}