Skip to content

Commit

Permalink
Fix connection port for MongoDB dev services using shared network
Browse files Browse the repository at this point in the history
The hostname was fixed in quarkusio#42065 but when using a shared network and a
container build, the application will connect directly to the container
port so we shouldn't use the exposed port but the original one.

Fixes quarkusio#42453
  • Loading branch information
gsmet authored and frne-trifork committed Aug 13, 2024
1 parent 32c2f72 commit 4ca8ec6
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private RunningDevService startMongo(DockerStatusBuildItem dockerStatusBuildItem
}

Supplier<RunningDevService> defaultMongoServerSupplier = () -> {
MongoDBContainer mongoDBContainer;
QuarkusMongoDBContainer mongoDBContainer;
if (capturedProperties.imageName != null) {
mongoDBContainer = new QuarkusMongoDBContainer(
DockerImageName.parse(capturedProperties.imageName).asCompatibleSubstituteFor("mongo"),
Expand All @@ -189,8 +189,9 @@ private RunningDevService startMongo(DockerStatusBuildItem dockerStatusBuildItem
timeout.ifPresent(mongoDBContainer::withStartupTimeout);
mongoDBContainer.withEnv(capturedProperties.containerEnv);
mongoDBContainer.start();
final String effectiveUrl = getEffectiveUrl(configPrefix, mongoDBContainer.getHost(),
mongoDBContainer.getMappedPort(MONGO_EXPOSED_PORT), capturedProperties);

final String effectiveUrl = getEffectiveUrl(configPrefix, mongoDBContainer.getEffectiveHost(),
mongoDBContainer.getEffectivePort(), capturedProperties);
return new RunningDevService(Feature.MONGODB_CLIENT.getName(), mongoDBContainer.getContainerId(),
mongoDBContainer::close, getConfigPrefix(connectionName) + "connection-string", effectiveUrl);
};
Expand Down Expand Up @@ -314,9 +315,12 @@ public String getReplicaSetUrl(String databaseName) {
}
}

@Override
public String getHost() {
public String getEffectiveHost() {
return useSharedNetwork ? hostName : super.getHost();
}

public Integer getEffectivePort() {
return useSharedNetwork ? MONGODB_INTERNAL_PORT : getMappedPort(MONGO_EXPOSED_PORT);
}
}
}

0 comments on commit 4ca8ec6

Please sign in to comment.