Skip to content

Commit 7b7c79e

Browse files
committed
refactor(testcontainers): add copy of mounting directory
Since it is possible to use test containers in conjunction with DinD services, in which paths are mounted relative to the DinD container, and not relative to the paths of the container in which the tests are directly launched, it is necessary to add a copy of the mounted directory.
1 parent 0fbd58a commit 7b7c79e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

testcontainers/src/main/java/org/testcontainers/containers/tarantool/Tarantool2Container.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.testcontainers.containers.SelinuxContext;
2020
import org.testcontainers.containers.utils.Utils;
2121
import org.testcontainers.utility.DockerImageName;
22+
import org.testcontainers.utility.MountableFile;
2223

2324
/**
2425
* Testcontainers for Tarantool version 2.11.x.
@@ -52,6 +53,24 @@ private Tarantool2Container(DockerImageName dockerImageName, String initScript,
5253
this.mountPath = Utils.createTempDirectory(this.node);
5354
}
5455

56+
/**
57+
* @implNote We copy all files from the mounted directory to the container. This is necessary so that all monitored
58+
* files got into a container while working in DinD. Mounting in such an environment follows the following rules:
59+
* <p/>
60+
* <ul>
61+
* <li>
62+
* When we run tests on a system where dockerd is located locally. Mounting occurs relatively
63+
* the current host (where dockerd is located).
64+
* </li>
65+
* <li>
66+
* When we run tests using DinD as a separate service: the tests are executed in the so-called build-container,
67+
* which contains all test files and data. Test containers (tarantool container), which are created testcontainers
68+
* are launched inside the so-called DinD container. Mounting is performed relative to the directories of the DinD
69+
* container, and not relative to the build container. For this reason we use additional copying of the mounted
70+
* directory so that the files in the mounted directory were also on the DinD container.
71+
* </li>
72+
* </ul>
73+
*/
5574
@Override
5675
protected void configure() {
5776
if (configured) {
@@ -74,6 +93,12 @@ protected void configure() {
7493
DEFAULT_DATA_DIR.toAbsolutePath().toString(),
7594
BindMode.READ_WRITE,
7695
SelinuxContext.SHARED);
96+
97+
withCopyFileToContainer(
98+
MountableFile.forHostPath(this.mountPath),
99+
TarantoolContainer.DEFAULT_DATA_DIR.toAbsolutePath().toString()
100+
);
101+
77102
addExposedPort(DEFAULT_TARANTOOL_PORT);
78103

79104
addEnv("TT_MEMTX_DIR", DEFAULT_DATA_DIR.toAbsolutePath().toString());

0 commit comments

Comments
 (0)