Skip to content

Commit ce0dd30

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 ce0dd30

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

Lines changed: 23 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,23 @@ 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
58+
* that all monitored files got into a container while working in DinD. Mounting in such an
59+
* environment follows the following rules:
60+
* <p>
61+
* <ul>
62+
* <li>When we run tests on a system where dockerd is located locally. Mounting occurs
63+
* relatively the current host (where dockerd is located).
64+
* <li>When we run tests using DinD as a separate service: the tests are executed in the
65+
* so-called build-container, which contains all test files and data. Test containers
66+
* (tarantool container), which are created testcontainers are launched inside the
67+
* so-called DinD container. Mounting is performed relative to the directories of the
68+
* DinD container, and not relative to the build container. For this reason we use
69+
* additional copying of the mounted directory so that the files in the mounted
70+
* directory were also on the DinD container.
71+
* </ul>
72+
*/
5573
@Override
5674
protected void configure() {
5775
if (configured) {
@@ -74,6 +92,11 @@ protected void configure() {
7492
DEFAULT_DATA_DIR.toAbsolutePath().toString(),
7593
BindMode.READ_WRITE,
7694
SelinuxContext.SHARED);
95+
96+
withCopyFileToContainer(
97+
MountableFile.forHostPath(this.mountPath),
98+
TarantoolContainer.DEFAULT_DATA_DIR.toAbsolutePath().toString());
99+
77100
addExposedPort(DEFAULT_TARANTOOL_PORT);
78101

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

0 commit comments

Comments
 (0)