Update for build & deploy process
This commit is contained in:
@@ -9,9 +9,6 @@ RUN dotnet restore
|
||||
COPY . ./
|
||||
RUN dotnet publish -c Release -o out
|
||||
|
||||
ENV ASPNETCORE_ENVIRONMENT=Staging
|
||||
RUN ["dotnet","ef","database","update"]
|
||||
|
||||
# Build runtime image
|
||||
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
|
||||
WORKDIR /app
|
||||
|
||||
@@ -9,9 +9,6 @@ RUN dotnet restore
|
||||
COPY . ./
|
||||
RUN dotnet publish -c Release -o out
|
||||
|
||||
ENV ASPNETCORE_ENVIRONMENT=Production
|
||||
RUN ["dotnet","ef","database","update"]
|
||||
|
||||
# Build runtime image
|
||||
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
|
||||
WORKDIR /app
|
||||
|
||||
@@ -32,7 +32,14 @@ namespace Test01
|
||||
.AddJsonFile("appsettings.json", optional: false)
|
||||
.Build();
|
||||
|
||||
var enableSeedApplicationDb = Convert.ToBoolean(config.GetSection("EnableSeedApplicationDb").Value);
|
||||
var enableMigration = Environment.GetEnvironmentVariable("MIGRATION");
|
||||
|
||||
if (!string.IsNullOrEmpty(enableMigration))
|
||||
{
|
||||
MigrationData.EnsureMigration(host.Services);
|
||||
}
|
||||
|
||||
var enableSeedApplicationDb = Convert.ToBoolean(config.GetSection("EnableSeedApplicationDb").Value);
|
||||
|
||||
//SeedData.EnsureSeedData(host.Services, enableSeedApplicationDb);
|
||||
|
||||
|
||||
@@ -67,4 +67,21 @@ namespace TestAPI01.Seed
|
||||
return Path.Combine(currentDir, filePath);
|
||||
}
|
||||
}
|
||||
|
||||
public class MigrationData
|
||||
{
|
||||
public static void EnsureMigration(IServiceProvider serviceProvider)
|
||||
{
|
||||
Console.WriteLine("Migrate database...");
|
||||
|
||||
using (var scope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope())
|
||||
{
|
||||
var context = scope.ServiceProvider.GetService<DataContext>();
|
||||
context.Database.Migrate();
|
||||
}
|
||||
|
||||
Console.WriteLine("Done.");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
Startup.cs
13
Startup.cs
@@ -52,8 +52,17 @@ namespace Test01
|
||||
// Test jenkins
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
string connectionString = Configuration.GetConnectionString("mainDBConnectionString");
|
||||
string idUrl = Configuration["IdentityServer:url"];
|
||||
var DB_HOST = Environment.GetEnvironmentVariable("DB_HOST");
|
||||
var DB_PORT = Environment.GetEnvironmentVariable("DB_PORT");
|
||||
var DB_NAME = Environment.GetEnvironmentVariable("DB_NAME");
|
||||
var DB_USERNAME = Environment.GetEnvironmentVariable("DB_USERNAME");
|
||||
var DB_PASSWORD = Environment.GetEnvironmentVariable("DB_PASSWORD");
|
||||
|
||||
var envConnectionString = $"Server={DB_HOST};Port={DB_PORT};Database={DB_NAME};User ID={DB_USERNAME};Password={DB_PASSWORD};";
|
||||
|
||||
string connectionString = !string.IsNullOrEmpty(DB_HOST) ? envConnectionString : Configuration.GetConnectionString("mainDBConnectionString");
|
||||
|
||||
string idUrl = Configuration["IdentityServer:url"];
|
||||
string apiName = Configuration["IdentityServer:apiName"];
|
||||
string appsite = Configuration["SiteInformation:appsite"];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user