diff --git a/docker-compose.yml b/docker-compose.yml index 094684a..723eb38 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,13 @@ version: '3.4' services: qtc-net-server: - image: ${DOCKER_REGISTRY-}qtcnetserver build: context: . 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" \ No newline at end of file diff --git a/qtc-net-server/Program.cs b/qtc-net-server/Program.cs index 2538ce0..a8f44a9 100644 --- a/qtc-net-server/Program.cs +++ b/qtc-net-server/Program.cs @@ -22,6 +22,21 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddDbContext(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")); else options.UseSqlite(builder.Configuration.GetConnectionString("DevelopmentConnection"));