Skip to content

Commit

Permalink
enable custom command in database devservices
Browse files Browse the repository at this point in the history
(cherry picked from commit b7108b5)
  • Loading branch information
newur authored and gsmet committed Jun 13, 2022
1 parent 3f597e6 commit 969a089
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ public class DevServicesDatasourceContainerConfig {
private final Map<String, String> containerProperties;
private final Map<String, String> additionalJdbcUrlProperties;
private final OptionalInt fixedExposedPort;
private final Optional<String> command;

public DevServicesDatasourceContainerConfig(Optional<String> imageName,
Map<String, String> containerProperties,
Map<String, String> additionalJdbcUrlProperties,
OptionalInt port) {
OptionalInt port,
Optional<String> command) {
this.imageName = imageName;
this.containerProperties = containerProperties;
this.additionalJdbcUrlProperties = additionalJdbcUrlProperties;
this.fixedExposedPort = port;
this.command = command;
}

public Optional<String> getImageName() {
Expand All @@ -36,4 +39,8 @@ public Map<String, String> getAdditionalJdbcUrlProperties() {
public OptionalInt getFixedExposedPort() {
return fixedExposedPort;
}

public Optional<String> getCommand() {
return command;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ private RunningDevService startDevDb(String dbName,
dataSourceBuildTimeConfig.devservices.imageName,
dataSourceBuildTimeConfig.devservices.containerProperties,
dataSourceBuildTimeConfig.devservices.properties,
dataSourceBuildTimeConfig.devservices.port);
dataSourceBuildTimeConfig.devservices.port,
dataSourceBuildTimeConfig.devservices.command);

DevServicesDatasourceProvider.RunningDevServicesDatasource datasource = devDbProvider
.startDatabase(ConfigProvider.getConfig().getOptionalValue(prefix + "username", String.class),
Expand All @@ -276,6 +277,9 @@ private RunningDevService startDevDb(String dbName,

propertiesMap.put(prefix + "db-kind", dataSourceBuildTimeConfig.dbKind.orElse(null));
String devServicesPrefix = prefix + "devservices.";
if (dataSourceBuildTimeConfig.devservices.command.isPresent()) {
propertiesMap.put(devServicesPrefix + "command", dataSourceBuildTimeConfig.devservices.command.get());
}
if (dataSourceBuildTimeConfig.devservices.imageName.isPresent()) {
propertiesMap.put(devServicesPrefix + "image-name", dataSourceBuildTimeConfig.devservices.imageName.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ public class DevServicesBuildTimeConfig {
@ConfigItem
public OptionalInt port;

/**
* The container start command to use, for container based DevServices providers.
*
* If the provider is not container based (e.g. a H2 Database) then this has no effect.
*/
@ConfigItem
public Optional<String> command;

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
.withDatabaseName(datasourceName.orElse("default"))
.withReuse(true);
containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam);
containerConfig.getCommand().ifPresent(container::setCommand);
container.start();

LOG.info("Dev Services for IBM Db2 started.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
}

containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam);
containerConfig.getCommand().ifPresent(container::setCommand);

container.start();

LOG.info("Dev Services for MariaDB started.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
container.withPassword(password.orElse("Quarkuspassword1"))
.withReuse(true);
containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam);
containerConfig.getCommand().ifPresent(container::setCommand);

container.start();

LOG.info("Dev Services for Microsoft SQL Server started.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
}

containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam);
containerConfig.getCommand().ifPresent(container::setCommand);

container.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
container.withCreateContainerCmdModifier(cmd -> cmd.getHostConfig().withNanoCPUs(2_000_000_000l));

containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam);
containerConfig.getCommand().ifPresent(container::setCommand);

container.start();

LOG.info("Dev Services for Oracle started.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
.withDatabaseName(datasourceName.orElse("default"))
.withReuse(true);
containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam);
containerConfig.getCommand().ifPresent(container::setCommand);

container.start();

Expand Down

0 comments on commit 969a089

Please sign in to comment.