Tabnine Logo
MountableFile.forHostPath
Code IndexAdd Tabnine to your IDE (free)

How to use
forHostPath
method
in
org.testcontainers.utility.MountableFile

Best Java code snippets using org.testcontainers.utility.MountableFile.forHostPath (Showing top 14 results out of 315)

origin: testcontainers/testcontainers-java

/**
 * Obtains a {@link MountableFile} corresponding to a file on the docker host filesystem.
 *
 * @param path the path to the resource
 * @return a {@link MountableFile} that may be used to obtain a mountable path
 */
public static MountableFile forHostPath(final Path path) {
  return forHostPath(path, null);
}
origin: testcontainers/testcontainers-java

/**
 * Obtains a {@link MountableFile} corresponding to a file on the docker host filesystem.
 *
 * @param path the path to the resource
 * @return a {@link MountableFile} that may be used to obtain a mountable path
 */
public static MountableFile forHostPath(@NotNull final String path) {
  return forHostPath(path, null);
}
origin: testcontainers/testcontainers-java

  /**
   * Adds file with given mode to tarball copied into container.
   * @param path in tarball
   * @param filePath in host filesystem
   * @param mode octal value of posix file mode (000..777)
   * @return self
   */
  default SELF withFileFromPath(String path, Path filePath, Integer mode) {
    final MountableFile mountableFile = MountableFile.forHostPath(filePath, mode);
    return ((SELF) this).withFileFromTransferable(path, mountableFile);
  }
}
origin: testcontainers/testcontainers-java

/**
 * {@inheritDoc}
 */
@Override
public void addFileSystemBind(final String hostPath, final String containerPath, final BindMode mode, final SelinuxContext selinuxContext) {
  final MountableFile mountableFile = MountableFile.forHostPath(hostPath);
  binds.add(new Bind(mountableFile.getResolvedPath(), new Volume(containerPath), mode.accessMode, selinuxContext.selContext));
}
origin: testcontainers/testcontainers-java

public ContainerisedDockerCompose(List<File> composeFiles, String identifier) {
  super(TestcontainersConfiguration.getInstance().getDockerComposeContainerImage());
  validateFileList(composeFiles);
  addEnv(ENV_PROJECT_NAME, identifier);
  // Map the docker compose file into the container
  final File dockerComposeBaseFile = composeFiles.get(0);
  final String pwd = dockerComposeBaseFile.getAbsoluteFile().getParentFile().getAbsolutePath();
  final String containerPwd = MountableFile.forHostPath(pwd).getFilesystemPath();
  final List<String> absoluteDockerComposeFiles = composeFiles.stream()
      .map(File::getAbsolutePath)
      .map(MountableFile::forHostPath)
      .map(MountableFile::getFilesystemPath)
      .collect(toList());
  final String composeFileEnvVariableValue = Joiner.on(UNIX_PATH_SEPERATOR).join(absoluteDockerComposeFiles); // we always need the UNIX path separator
  logger().debug("Set env COMPOSE_FILE={}", composeFileEnvVariableValue);
  addEnv(ENV_COMPOSE_FILE, composeFileEnvVariableValue);
  addFileSystemBind(pwd, containerPwd, READ_ONLY);
  // 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.
  // As there seems to be a problem with mapping to the /var/run directory in certain environments (e.g. CircleCI)
  //  we map the socket file outside of /var/run, as just /docker.sock
  addFileSystemBind(getDockerSocketHostPath(), "/docker.sock", READ_WRITE);
  addEnv("DOCKER_HOST", "unix:///docker.sock");
  setStartupCheckStrategy(new IndefiniteWaitOneShotStartupCheckStrategy());
  setWorkingDirectory(containerPwd);
  String dockerConfigPath = determineDockerConfigPath();
  if (dockerConfigPath != null && !dockerConfigPath.isEmpty()) {
    addFileSystemBind(dockerConfigPath, DOCKER_CONFIG_FILE, READ_ONLY);
  }
}
origin: testcontainers/testcontainers-java

@Test
public void forHostPath() throws Exception {
  final Path file = createTempFile("somepath");
  final MountableFile mountableFile = MountableFile.forHostPath(file.toString());
  performChecks(mountableFile);
}
origin: testcontainers/testcontainers-java

@Test
public void forHostPathWithPlus() throws Exception {
  final Path file = createTempFile("some+path");
  final MountableFile mountableFile = MountableFile.forHostPath(file.toString());
  performChecks(mountableFile);
  assertTrue("The resolved path contains the original space", mountableFile.getResolvedPath().contains("+"));
  assertFalse("The resolved path does not contain an escaped space", mountableFile.getResolvedPath().contains(" "));
}
origin: testcontainers/testcontainers-java

@Test
public void forHostPathWithSpaces() throws Exception {
  final Path file = createTempFile("some path");
  final MountableFile mountableFile = MountableFile.forHostPath(file.toString());
  performChecks(mountableFile);
  assertTrue("The resolved path contains the original space", mountableFile.getResolvedPath().contains(" "));
  assertFalse("The resolved path does not contain an escaped space", mountableFile.getResolvedPath().contains("\\ "));
}
origin: testcontainers/testcontainers-java

@Test
public void forHostDirPathWithPermission() throws Exception {
  final Path dir = createTempDir();
  final MountableFile mountableFile = MountableFile.forHostPath(dir.toString(), TEST_FILE_MODE);
  performChecks(mountableFile);
  assertEquals("Valid dir mode.", BASE_DIR_MODE | TEST_FILE_MODE, mountableFile.getFileMode());
}
origin: testcontainers/testcontainers-java

@Test
public void forHostFilePathWithPermission() throws Exception {
  final Path file = createTempFile("somepath");
  final MountableFile mountableFile = MountableFile.forHostPath(file.toString(), TEST_FILE_MODE);
  performChecks(mountableFile);
  assertEquals("Valid file mode.", BASE_FILE_MODE | TEST_FILE_MODE, mountableFile.getFileMode());
}
origin: org.testcontainers/testcontainers

/**
 * Obtains a {@link MountableFile} corresponding to a file on the docker host filesystem.
 *
 * @param path the path to the resource
 * @return a {@link MountableFile} that may be used to obtain a mountable path
 */
public static MountableFile forHostPath(final Path path) {
  return forHostPath(path, null);
}
origin: org.testcontainers/testcontainers

  /**
   * Adds file with given mode to tarball copied into container.
   * @param path in tarball
   * @param filePath in host filesystem
   * @param mode octal value of posix file mode (000..777)
   * @return self
   */
  default SELF withFileFromPath(String path, Path filePath, Integer mode) {
    final MountableFile mountableFile = MountableFile.forHostPath(filePath, mode);
    return ((SELF) this).withFileFromTransferable(path, mountableFile);
  }
}
origin: org.testcontainers/testcontainers

/**
 * {@inheritDoc}
 */
@Override
public void addFileSystemBind(final String hostPath, final String containerPath, final BindMode mode, final SelinuxContext selinuxContext) {
  final MountableFile mountableFile = MountableFile.forHostPath(hostPath);
  binds.add(new Bind(mountableFile.getResolvedPath(), new Volume(containerPath), mode.accessMode, selinuxContext.selContext));
}
origin: org.testcontainers/testcontainers

public ContainerisedDockerCompose(List<File> composeFiles, String identifier) {
  super(TestcontainersConfiguration.getInstance().getDockerComposeContainerImage());
  validateFileList(composeFiles);
  addEnv(ENV_PROJECT_NAME, identifier);
  // Map the docker compose file into the container
  final File dockerComposeBaseFile = composeFiles.get(0);
  final String pwd = dockerComposeBaseFile.getAbsoluteFile().getParentFile().getAbsolutePath();
  final String containerPwd = MountableFile.forHostPath(pwd).getFilesystemPath();
  final List<String> absoluteDockerComposeFiles = composeFiles.stream().map(File::getAbsolutePath).map(MountableFile::forHostPath).map(MountableFile::getFilesystemPath).collect(toList());
  final String composeFileEnvVariableValue = Joiner.on(UNIX_PATH_SEPERATOR).join(absoluteDockerComposeFiles); // we always need the UNIX path separator
  logger().debug("Set env COMPOSE_FILE={}", composeFileEnvVariableValue);
  addEnv(ENV_COMPOSE_FILE, composeFileEnvVariableValue);
  addFileSystemBind(pwd, containerPwd, READ_ONLY);
  // 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.
  // As there seems to be a problem with mapping to the /var/run directory in certain environments (e.g. CircleCI)
  //  we map the socket file outside of /var/run, as just /docker.sock
  addFileSystemBind(getDockerSocketHostPath(), "/docker.sock", READ_WRITE);
  addEnv("DOCKER_HOST", "unix:///docker.sock");
  setStartupCheckStrategy(new IndefiniteWaitOneShotStartupCheckStrategy());
  setWorkingDirectory(containerPwd);
  String dockerConfigPath = determineDockerConfigPath();
  if (dockerConfigPath != null && !dockerConfigPath.isEmpty()) {
    addFileSystemBind(dockerConfigPath, DOCKER_CONFIG_FILE, READ_ONLY);
  }
}
org.testcontainers.utilityMountableFileforHostPath

Javadoc

Obtains a MountableFile corresponding to a file on the docker host filesystem.

Popular methods of MountableFile

  • forClasspathResource
  • getResolvedPath
  • <init>
  • copyFromJarToLocation
  • createTempDirectory
  • deleteOnExit
  • extractClassPathResourceToTempLocation
    Extract a file or directory tree from a JAR file to a temporary location. This allows Docker to moun
  • getClasspathResource
  • getFilesystemPath
  • getModeValue
  • getResourcePath
  • getUnixFileMode
  • getResourcePath,
  • getUnixFileMode,
  • unencodeResourceURIToFilePath,
  • getFileMode,
  • recursiveTar,
  • resolveFilesystemPath,
  • resolvePath,
  • transferTo

Popular in Java

  • Running tasks concurrently on multiple threads
  • startActivity (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now