badge for buid status
This commit is contained in:
parent
2c5f58f104
commit
8a31efeab2
@ -1,6 +1,9 @@
|
||||
# eShopOnContainers - Microservices Architecture and Containers based Reference Application (**BETA state** - Visual Studio 2017 and CLI environments compatible)
|
||||
Sample .NET Core reference application, powered by Microsoft, based on a simplified microservices architecture and Docker containers.
|
||||
|
||||
[](https://msftdevtools.visualstudio.com/eShopOnContainers/_build/latest?definitionId=184)
|
||||
|
||||
|
||||
## IMPORTANT NOTES!
|
||||
**You can use either the latest version of Visual Studio or simply Docker CLI and .NET CLI for Windows, Mac and Linux**.
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Polly;
|
||||
@ -10,8 +11,17 @@ namespace Microsoft.AspNetCore.Hosting
|
||||
{
|
||||
public static class IWebHostExtensions
|
||||
{
|
||||
public static bool IsInKubernetes(this IWebHost webHost)
|
||||
{
|
||||
var cfg = webHost.Services.GetService<IConfiguration>();
|
||||
var orchestratorType = cfg.GetValue<string>("OrchestratorType");
|
||||
return orchestratorType?.ToUpper() == "K8S";
|
||||
}
|
||||
|
||||
public static IWebHost MigrateDbContext<TContext>(this IWebHost webHost, Action<TContext,IServiceProvider> seeder) where TContext : DbContext
|
||||
{
|
||||
var underK8s = webHost.IsInKubernetes();
|
||||
|
||||
using (var scope = webHost.Services.CreateScope())
|
||||
{
|
||||
var services = scope.ServiceProvider;
|
||||
@ -24,6 +34,12 @@ namespace Microsoft.AspNetCore.Hosting
|
||||
{
|
||||
logger.LogInformation($"Migrating database associated with context {typeof(TContext).Name}");
|
||||
|
||||
if (underK8s)
|
||||
{
|
||||
InvokeSeeder(seeder, context, services);
|
||||
}
|
||||
else
|
||||
{
|
||||
var retry = Policy.Handle<SqlException>()
|
||||
.WaitAndRetry(new TimeSpan[]
|
||||
{
|
||||
@ -32,28 +48,33 @@ namespace Microsoft.AspNetCore.Hosting
|
||||
TimeSpan.FromSeconds(8),
|
||||
});
|
||||
|
||||
retry.Execute(() =>
|
||||
{
|
||||
//if the sql server container is not created on run docker compose this
|
||||
//migration can't fail for network related exception. The retry options for DbContext only
|
||||
//apply to transient exceptions.
|
||||
|
||||
context.Database
|
||||
.Migrate();
|
||||
|
||||
seeder(context, services);
|
||||
});
|
||||
|
||||
//apply to transient exceptions
|
||||
// Note that this is NOT applied when running some orchestrators (let the orchestrator to recreate the failing service)
|
||||
retry.Execute(() => InvokeSeeder(seeder, context, services));
|
||||
}
|
||||
|
||||
logger.LogInformation($"Migrated database associated with context {typeof(TContext).Name}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"An error occurred while migrating the database used on context {typeof(TContext).Name}");
|
||||
if (underK8s)
|
||||
{
|
||||
throw; // Rethrow under k8s because we rely on k8s to re-run the pod
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return webHost;
|
||||
}
|
||||
|
||||
private static void InvokeSeeder<TContext>(Action<TContext, IServiceProvider> seeder, TContext context, IServiceProvider services)
|
||||
where TContext : DbContext
|
||||
{
|
||||
context.Database.Migrate();
|
||||
seeder(context, services);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
|
||||
<!--
|
||||
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
|
||||
-->
|
||||
|
||||
<system.webServer>
|
||||
<handlers>
|
||||
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
|
||||
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
|
||||
</handlers>
|
||||
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
|
||||
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
|
||||
<environmentVariables />
|
||||
</aspNetCore>
|
||||
</system.webServer>
|
||||
</configuration>
|
Loading…
x
Reference in New Issue
Block a user