Rework Docker support
- Use multi-stage build for the application image - Utilize connection pool init timeout for waiting on database container startup, "docker-compose-wait" dependency is no longer required - Override database host through environment variable - used in docker-compose - Rename database scripts for explicit ordering (db container loads them alphabetically)
This commit is contained in:
@@ -5,7 +5,8 @@ public class ServerConfig {
|
||||
public boolean USE_THREAD_TRACKER;
|
||||
|
||||
//Database Configuration
|
||||
public String DB_URL;
|
||||
public String DB_URL_FORMAT;
|
||||
public String DB_HOST;
|
||||
public String DB_USER;
|
||||
public String DB_PASS;
|
||||
public int INIT_CONNECTION_POOL_TIMEOUT;
|
||||
|
||||
@@ -27,10 +27,19 @@ public class DatabaseConnection {
|
||||
return dataSource.getConnection();
|
||||
}
|
||||
|
||||
private static String getDbUrl() {
|
||||
// Environment variables override what's defined in the config file
|
||||
// This feature is used for the Docker support
|
||||
String hostOverride = System.getenv("DB_HOST");
|
||||
String host = hostOverride != null ? hostOverride : YamlConfig.config.server.DB_HOST;
|
||||
String dbUrl = String.format(YamlConfig.config.server.DB_URL_FORMAT, host);
|
||||
return dbUrl;
|
||||
}
|
||||
|
||||
private static HikariConfig getConfig() {
|
||||
HikariConfig config = new HikariConfig();
|
||||
|
||||
config.setJdbcUrl(YamlConfig.config.server.DB_URL);
|
||||
config.setJdbcUrl(getDbUrl());
|
||||
config.setUsername(YamlConfig.config.server.DB_USER);
|
||||
config.setPassword(YamlConfig.config.server.DB_PASS);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user