net5
This commit is contained in:
parent
a88f6c5149
commit
19a5dde1ac
@ -1,8 +1,8 @@
|
|||||||
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
|
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
# It's important to keep lines from here down to "COPY . ." identical in all Dockerfiles
|
# It's important to keep lines from here down to "COPY . ." identical in all Dockerfiles
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<UserSecretsId>aspnet-eShopOnContainers.Identity-90487118-103c-4ff0-b9da-e5e26f7ab0c5</UserSecretsId>
|
<UserSecretsId>aspnet-eShopOnContainers.Identity-90487118-103c-4ff0-b9da-e5e26f7ab0c5</UserSecretsId>
|
||||||
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
|
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||||
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
|
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using IdentityServer4.EntityFramework.DbContexts;
|
using IdentityServer4.EntityFramework.DbContexts;
|
||||||
using Microsoft.AspNetCore;
|
using Microsoft.AspNetCore;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Identity.API;
|
||||||
using Microsoft.eShopOnContainers.Services.Identity.API.Data;
|
using Microsoft.eShopOnContainers.Services.Identity.API.Data;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@ -11,103 +12,92 @@ using Serilog;
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Identity.API
|
string Namespace = typeof(Startup).Namespace;
|
||||||
|
string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1);
|
||||||
|
|
||||||
|
var configuration = GetConfiguration();
|
||||||
|
|
||||||
|
Log.Logger = CreateSerilogLogger(configuration);
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
public class Program
|
Log.Information("Configuring web host ({ApplicationContext})...", AppName);
|
||||||
{
|
var host = BuildWebHost(configuration, args);
|
||||||
public static readonly string Namespace = typeof(Program).Namespace;
|
|
||||||
public static readonly string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1);
|
|
||||||
|
|
||||||
public static int Main(string[] args)
|
Log.Information("Applying migrations ({ApplicationContext})...", AppName);
|
||||||
|
host.MigrateDbContext<PersistedGrantDbContext>((_, __) => { })
|
||||||
|
.MigrateDbContext<ApplicationDbContext>((context, services) =>
|
||||||
{
|
{
|
||||||
var configuration = GetConfiguration();
|
var env = services.GetService<IWebHostEnvironment>();
|
||||||
|
var logger = services.GetService<ILogger<ApplicationDbContextSeed>>();
|
||||||
|
var settings = services.GetService<IOptions<AppSettings>>();
|
||||||
|
|
||||||
Log.Logger = CreateSerilogLogger(configuration);
|
new ApplicationDbContextSeed()
|
||||||
|
.SeedAsync(context, env, logger, settings)
|
||||||
try
|
.Wait();
|
||||||
{
|
})
|
||||||
Log.Information("Configuring web host ({ApplicationContext})...", AppName);
|
.MigrateDbContext<ConfigurationDbContext>((context, services) =>
|
||||||
var host = BuildWebHost(configuration, args);
|
|
||||||
|
|
||||||
Log.Information("Applying migrations ({ApplicationContext})...", AppName);
|
|
||||||
host.MigrateDbContext<PersistedGrantDbContext>((_, __) => { })
|
|
||||||
.MigrateDbContext<ApplicationDbContext>((context, services) =>
|
|
||||||
{
|
|
||||||
var env = services.GetService<IWebHostEnvironment>();
|
|
||||||
var logger = services.GetService<ILogger<ApplicationDbContextSeed>>();
|
|
||||||
var settings = services.GetService<IOptions<AppSettings>>();
|
|
||||||
|
|
||||||
new ApplicationDbContextSeed()
|
|
||||||
.SeedAsync(context, env, logger, settings)
|
|
||||||
.Wait();
|
|
||||||
})
|
|
||||||
.MigrateDbContext<ConfigurationDbContext>((context, services) =>
|
|
||||||
{
|
|
||||||
new ConfigurationDbContextSeed()
|
|
||||||
.SeedAsync(context, configuration)
|
|
||||||
.Wait();
|
|
||||||
});
|
|
||||||
|
|
||||||
Log.Information("Starting web host ({ApplicationContext})...", AppName);
|
|
||||||
host.Run();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", AppName);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IWebHost BuildWebHost(IConfiguration configuration, string[] args) =>
|
|
||||||
WebHost.CreateDefaultBuilder(args)
|
|
||||||
.CaptureStartupErrors(false)
|
|
||||||
.ConfigureAppConfiguration(x => x.AddConfiguration(configuration))
|
|
||||||
.UseStartup<Startup>()
|
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseSerilog()
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
private static Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
|
|
||||||
{
|
{
|
||||||
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
new ConfigurationDbContextSeed()
|
||||||
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
.SeedAsync(context, configuration)
|
||||||
return new LoggerConfiguration()
|
.Wait();
|
||||||
.MinimumLevel.Verbose()
|
});
|
||||||
.Enrich.WithProperty("ApplicationContext", AppName)
|
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.WriteTo.Console()
|
|
||||||
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)
|
|
||||||
.WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://localhost:8080" : logstashUrl)
|
|
||||||
.ReadFrom.Configuration(configuration)
|
|
||||||
.CreateLogger();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IConfiguration GetConfiguration()
|
Log.Information("Starting web host ({ApplicationContext})...", AppName);
|
||||||
{
|
host.Run();
|
||||||
var builder = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
|
||||||
.AddEnvironmentVariables();
|
|
||||||
|
|
||||||
var config = builder.Build();
|
return 0;
|
||||||
|
}
|
||||||
if (config.GetValue<bool>("UseVault", false))
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
builder.AddAzureKeyVault(
|
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", AppName);
|
||||||
$"https://{config["Vault:Name"]}.vault.azure.net/",
|
return 1;
|
||||||
config["Vault:ClientId"],
|
}
|
||||||
config["Vault:ClientSecret"]);
|
finally
|
||||||
}
|
{
|
||||||
|
Log.CloseAndFlush();
|
||||||
return builder.Build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IWebHost BuildWebHost(IConfiguration configuration, string[] args) =>
|
||||||
|
WebHost.CreateDefaultBuilder(args)
|
||||||
|
.CaptureStartupErrors(false)
|
||||||
|
.ConfigureAppConfiguration(x => x.AddConfiguration(configuration))
|
||||||
|
.UseStartup<Startup>()
|
||||||
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
|
.UseSerilog()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
||||||
|
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
||||||
|
return new LoggerConfiguration()
|
||||||
|
.MinimumLevel.Verbose()
|
||||||
|
.Enrich.WithProperty("ApplicationContext", AppName)
|
||||||
|
.Enrich.FromLogContext()
|
||||||
|
.WriteTo.Console()
|
||||||
|
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)
|
||||||
|
.WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://localhost:8080" : logstashUrl)
|
||||||
|
.ReadFrom.Configuration(configuration)
|
||||||
|
.CreateLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
IConfiguration GetConfiguration()
|
||||||
|
{
|
||||||
|
var builder = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||||
|
.AddEnvironmentVariables();
|
||||||
|
|
||||||
|
var config = builder.Build();
|
||||||
|
|
||||||
|
if (config.GetValue<bool>("UseVault", false))
|
||||||
|
{
|
||||||
|
builder.AddAzureKeyVault(
|
||||||
|
$"https://{config["Vault:Name"]}.vault.azure.net/",
|
||||||
|
config["Vault:ClientId"],
|
||||||
|
config["Vault:ClientSecret"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.Build();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user