Skip to content

Commit 649852c

Browse files
author
Vladimir Rogach
committed
Closes #24, closes #25. Add option to bind container to fixed host ports
1 parent d878f27 commit 649852c

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

src/main/java/org/testcontainers/containers/TarantoolCartridgeContainer.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
9898
private static final String ENV_TARANTOOL_WORKDIR = "TARANTOOL_WORKDIR";
9999
private static final String ENV_TARANTOOL_RUNDIR = "TARANTOOL_RUNDIR";
100100
private static final String ENV_TARANTOOL_DATADIR = "TARANTOOL_DATADIR";
101+
private boolean useFixedPorts = false;
101102

102103
private String routerHost = ROUTER_HOST;
103104
private int routerPort = ROUTER_PORT;
@@ -315,6 +316,17 @@ public int getAPIPort() {
315316
return getMappedPort(apiPort);
316317
}
317318

319+
/**
320+
* Use fixed ports binding.
321+
* Defaults to false.
322+
*
323+
* @return HTTP API port
324+
*/
325+
public TarantoolCartridgeContainer withUseFixedPorts(boolean useFixedPorts) {
326+
this.useFixedPorts = useFixedPorts;
327+
return this;
328+
}
329+
318330
/**
319331
* Set Cartridge router hostname
320332
*
@@ -377,8 +389,17 @@ public TarantoolCartridgeContainer withRouterPassword(String routerPassword) {
377389

378390
@Override
379391
protected void configure() {
380-
withFileSystemBind(getDirectoryBinding(), getInstanceDir(), BindMode.READ_WRITE);
381-
withExposedPorts(instanceFileParser.getExposablePorts());
392+
if (!getDirectoryBinding().isEmpty()) {
393+
withFileSystemBind(getDirectoryBinding(), getInstanceDir(), BindMode.READ_WRITE);
394+
}
395+
396+
if (useFixedPorts) {
397+
for (Integer port : instanceFileParser.getExposablePorts()) {
398+
addFixedExposedPort(port, port);
399+
}
400+
} else {
401+
withExposedPorts(instanceFileParser.getExposablePorts());
402+
}
382403
}
383404

384405
@Override

src/main/java/org/testcontainers/containers/TarantoolContainer.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class TarantoolContainer extends GenericContainer<TarantoolContainer>
4343
private String directoryResourcePath = SCRIPT_RESOURCE_DIRECTORY;
4444
private String scriptFileName = SCRIPT_FILENAME;
4545
private String instanceDir = INSTANCE_DIR;
46+
private boolean useFixedPorts = false;
4647

4748
private final TarantoolContainerClientHelper clientHelper;
4849

@@ -60,6 +61,17 @@ public TarantoolContainer(Future<String> image) {
6061
clientHelper = new TarantoolContainerClientHelper(this);
6162
}
6263

64+
/**
65+
* Use fixed ports binding.
66+
* Defaults to false.
67+
*
68+
* @return HTTP API port
69+
*/
70+
public TarantoolContainer withUseFixedPorts(boolean useFixedPorts) {
71+
this.useFixedPorts = useFixedPorts;
72+
return this;
73+
}
74+
6375
/**
6476
* Specify the host for connecting to Tarantool with.
6577
*
@@ -259,8 +271,16 @@ protected void configure() {
259271
}
260272
String sourceDirectoryPath = normalizePath(sourceDirectory.getPath());
261273

262-
withFileSystemBind(sourceDirectoryPath, getInstanceDir(), BindMode.READ_WRITE);
263-
withExposedPorts(port);
274+
//disable bind if directory is empty
275+
if (!sourceDirectoryPath.isEmpty()) {
276+
withFileSystemBind(sourceDirectoryPath, getInstanceDir(), BindMode.READ_WRITE);
277+
}
278+
279+
if (useFixedPorts) {
280+
addFixedExposedPort(port, port);
281+
} else {
282+
withExposedPorts(port);
283+
}
264284

265285
withCommand("tarantool", normalizePath(
266286
Paths.get(getInstanceDir(), getScriptFileName())));

0 commit comments

Comments
 (0)