Skip to content

Commit 7044cde

Browse files
daschleddumelendez
andauthored
[couchbase] only expose ports for enabled services (#4595)
This changeset is a minor cleanup, but it makes sense to only actually expose the ports for the services which are enabled and not all of them all the time. Co-authored-by: Eddú Meléndez <[email protected]>
1 parent d568e9d commit 7044cde

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -241,22 +241,7 @@ public String getConnectionString() {
241241
protected void configure() {
242242
super.configure();
243243

244-
addExposedPorts(
245-
MGMT_PORT,
246-
MGMT_SSL_PORT,
247-
VIEW_PORT,
248-
VIEW_SSL_PORT,
249-
QUERY_PORT,
250-
QUERY_SSL_PORT,
251-
SEARCH_PORT,
252-
SEARCH_SSL_PORT,
253-
ANALYTICS_PORT,
254-
ANALYTICS_SSL_PORT,
255-
KV_PORT,
256-
KV_SSL_PORT,
257-
EVENTING_PORT,
258-
EVENTING_SSL_PORT
259-
);
244+
exposePorts();
260245

261246
WaitAllStrategy waitStrategy = new WaitAllStrategy();
262247

@@ -319,6 +304,34 @@ protected void configure() {
319304
waitingFor(waitStrategy);
320305
}
321306

307+
/**
308+
* Configures the exposed ports based on the enabled services.
309+
* <p>
310+
* Note that the MGMT_PORTs are always enabled since there must always be a cluster
311+
* manager. Also, the View engine ports are implicitly available on the same nodes
312+
* where the KV service is enabled - it is not possible to configure them individually.
313+
*/
314+
private void exposePorts() {
315+
addExposedPorts(MGMT_PORT, MGMT_SSL_PORT);
316+
317+
if (enabledServices.contains(CouchbaseService.KV)) {
318+
addExposedPorts(KV_PORT, KV_SSL_PORT);
319+
addExposedPorts(VIEW_PORT, VIEW_SSL_PORT);
320+
}
321+
if (enabledServices.contains(CouchbaseService.ANALYTICS)) {
322+
addExposedPorts(ANALYTICS_PORT, ANALYTICS_SSL_PORT);
323+
}
324+
if (enabledServices.contains(CouchbaseService.QUERY)) {
325+
addExposedPorts(QUERY_PORT, QUERY_SSL_PORT);
326+
}
327+
if (enabledServices.contains(CouchbaseService.SEARCH)) {
328+
addExposedPorts(SEARCH_PORT, SEARCH_SSL_PORT);
329+
}
330+
if (enabledServices.contains(CouchbaseService.EVENTING)) {
331+
addExposedPorts(EVENTING_PORT, EVENTING_SSL_PORT);
332+
}
333+
}
334+
322335
@Override
323336
protected void containerIsStarting(final InspectContainerResponse containerInfo) {
324337
logger().debug("Couchbase container is starting, performing configuration.");

0 commit comments

Comments
 (0)