Skip to content

Commit

Permalink
testcontainers#7239 - reduce the pain by making it configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderankin committed Jan 26, 2024
1 parent 78d1768 commit 21cbc05
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;
import org.testcontainers.utility.PathUtils;
import org.testcontainers.utility.TestcontainersConfiguration;

import java.io.File;
import java.util.List;
Expand Down Expand Up @@ -43,7 +44,10 @@ public ContainerisedDockerCompose(DockerImageName dockerImageName, List<File> co
final String composeFileEnvVariableValue = Joiner.on(UNIX_PATH_SEPARATOR).join(absoluteDockerComposeFiles); // we always need the UNIX path separator
logger().debug("Set env COMPOSE_FILE={}", composeFileEnvVariableValue);
addEnv(ENV_COMPOSE_FILE, composeFileEnvVariableValue);
withCopyFileToContainer(MountableFile.forHostPath(pwd), containerPwd);
if (TestcontainersConfiguration.getInstance().isComposeFsModeMount())
addFileSystemBind(pwd, containerPwd, BindMode.READ_WRITE);
else
withCopyFileToContainer(MountableFile.forHostPath(pwd), containerPwd);

// Ensure that compose can access docker. Since the container is assumed to be running on the same machine
// as the docker daemon, just mapping the docker control socket is OK.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -221,6 +222,10 @@ public Integer getClientPingTimeout() {
return Integer.parseInt(getEnvVarOrProperty("client.ping.timeout", "10"));
}

public boolean isComposeFsModeMount() {
return "mount".equalsIgnoreCase(getEnvVarOrProperty("compose.container.fs.mode", "copy"));
}

@Nullable
@Contract("_, !null, _ -> !null")
private String getConfigurable(
Expand Down
18 changes: 18 additions & 0 deletions docs/features/advanced_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,21 @@ The previous implementation should be registered in `META-INF/services/org.testc
Usually, containers are started sequentially when more than one container is used.
Using `Startables.deepStart(container1, container2, ...).join()` will start all containers in parallel.
This can be advantageous to reduce the impact of the container startup overhead.

## Containerized Docker Compose

If you are using `ComposeContainer` (for `compose`, v2) or `DockerComposeContainer`
(`docker-compose`, v1), then you may be running the `compose` plugin/program
inside a docker container itself.
This works by running the `compose` commands inside a container,
to communicate with a docker engine running somewhere else.

If you need to access files on your local filesystem,
such as with a `compose` file with a build context instead of an image,
then you may find that it is beneficial to opt out of the default
Testcontainers behavior of copying files to containers, and use a fs mount:

```properties
compose.container.fs.mode=bind
#compose.container.fs.mode=copy
```

0 comments on commit 21cbc05

Please sign in to comment.