Add `DB_PROVIDER
and
DB_CONNECTION_STRING
` environment variables
This commit is contained in:
parent
073c5ee29e
commit
198a8635ab
@ -2,7 +2,13 @@ version: '3.4'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
qtc-net-server:
|
qtc-net-server:
|
||||||
image: ${DOCKER_REGISTRY-}qtcnetserver
|
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: qtc-net-server/Dockerfile
|
dockerfile: qtc-net-server/Dockerfile
|
||||||
|
environment:
|
||||||
|
- ASPNETCORE_ENVIRONMENT=Production
|
||||||
|
- ASPNETCORE_HTTP_PORTS=8080
|
||||||
|
- DB_CONNECTION_STRING=Data Source=qtcdev.db
|
||||||
|
- DB_PROVIDER=SQLite
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
@ -22,6 +22,21 @@ builder.Services.AddControllers();
|
|||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddDbContext<DataContext>(options =>
|
builder.Services.AddDbContext<DataContext>(options =>
|
||||||
{
|
{
|
||||||
|
if(!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING")) && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DB_PROVIDER")))
|
||||||
|
{
|
||||||
|
switch(Environment.GetEnvironmentVariable("DB_PROVIDER"))
|
||||||
|
{
|
||||||
|
case "MySQL":
|
||||||
|
options.UseMySQL(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING")!);
|
||||||
|
break;
|
||||||
|
case "SQLite":
|
||||||
|
options.UseSqlite(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING")!);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (builder.Environment.IsProduction()) options.UseMySQL(builder.Configuration.GetConnectionString("DefaultConnection"));
|
if (builder.Environment.IsProduction()) options.UseMySQL(builder.Configuration.GetConnectionString("DefaultConnection"));
|
||||||
else options.UseSqlite(builder.Configuration.GetConnectionString("DevelopmentConnection"));
|
else options.UseSqlite(builder.Configuration.GetConnectionString("DevelopmentConnection"));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user