Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connection port for MongoDB dev services using shared network #42472

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}