Skip to content

Commit

Permalink
Add network alias support
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebell90 committed Jan 27, 2022
1 parent 9d1c541 commit 0d83886
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

1.0.0
-----
* Add network alias option

1.0.0RC3
-----
* Stop excluding junit4 from testcontainers - check the README for the sordid details.
* Pass host and port to the ConnectionInfo bean. We strongly recommend you prefer getDatasource or getUrl, these will be more portable in usage. We ran into
a few use cases where this was handy, however.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,18 @@ public class EmbeddedPostgres implements Closeable {
Map<String, String> localeConfig,
Map<String, BindMount> bindMounts,
Optional<Network> network,
Optional<String> networkAlias,
DockerImageName image,
String databaseName
) throws IOException {
this(postgresConfig, localeConfig, bindMounts, network, image, DEFAULT_PG_STARTUP_WAIT, databaseName);
this(postgresConfig, localeConfig, bindMounts, network, networkAlias, image, DEFAULT_PG_STARTUP_WAIT, databaseName);
}

EmbeddedPostgres(Map<String, String> postgresConfig,
Map<String, String> localeConfig,
Map<String, BindMount> bindMounts,
Optional<Network> network,
Optional<String> networkAlias,
DockerImageName image,
Duration pgStartupWait,
String databaseName
Expand All @@ -103,6 +105,7 @@ public class EmbeddedPostgres implements Closeable {
postgreDBContainer.setCommand(cmd.toArray(new String[0]));
processBindMounts(postgreDBContainer, bindMounts);
network.ifPresent(postgreDBContainer::withNetwork);
networkAlias.ifPresent(postgreDBContainer::withNetworkAliases);
postgreDBContainer.start();
}

Expand Down Expand Up @@ -220,6 +223,7 @@ public static class Builder {

private DockerImageName image = getDefaultImage();
private String databaseName = POSTGRES;
private Optional<String> networkAlias = Optional.empty();

// See comments at top for the logic.
DockerImageName getDefaultImage() {
Expand Down Expand Up @@ -270,8 +274,9 @@ public Builder setBindMount(String localFile, String remoteFile) {
return this;
}

public Builder setNetwork(Network network) {
public Builder setNetwork(Network network, String networkAlias) {
this.network = Optional.ofNullable(network);
this.networkAlias = Optional.ofNullable(networkAlias);
return this;
}

Expand Down Expand Up @@ -299,7 +304,7 @@ DockerImageName getImage() {
}

public EmbeddedPostgres start() throws IOException {
return new EmbeddedPostgres(config, localeConfig, bindMounts, network, image, pgStartupWait, databaseName);
return new EmbeddedPostgres(config, localeConfig, bindMounts, network, networkAlias, image, pgStartupWait, databaseName);
}

@Override
Expand Down

2 comments on commit 0d83886

@opentable-devops
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Architecture Team / Java TC Platform / otj-pg-embedded / PR Build Build ???.164/merge.140 is now running

@opentable-devops
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Architecture Team / Java TC Platform / otj-pg-embedded / PR Build Build 1.0.0.RC4-SNAPSHOT.164/merge.140 outcome was SUCCESS
Summary: Tests passed: 13, ignored: 2 Build time: 00:01:10

Please sign in to comment.