org.testcontainers.utility.MountableFile Java Examples

The following examples show how to use org.testcontainers.utility.MountableFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Standard.java    From presto with Apache License 2.0 6 votes vote down vote up
public static void enablePrestoJavaDebugger(DockerContainer container, int debugPort)
{
    try {
        FileAttribute<Set<PosixFilePermission>> rwx = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxrwxrwx"));
        Path script = Files.createTempFile("enable-java-debugger", ".sh", rwx);
        Files.writeString(
                script,
                format(
                        "#!/bin/bash\n" +
                                "printf '%%s\\n' '%s' >> '%s'\n",
                        "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:" + debugPort,
                        CONTAINER_PRESTO_JVM_CONFIG),
                UTF_8);
        container.withCopyFileToContainer(MountableFile.forHostPath(script), "/docker/presto-init.d/enable-java-debugger.sh");

        // expose debug port unconditionally when debug is enabled
        exposePort(container, debugPort);
    }
    catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #2
Source File: ReusabilityUnitTests.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void changesInFolder() throws Exception {
    Path tempDirectory = Files.createTempDirectory("reusable_test");
    MountableFile mountableFile = MountableFile.forHostPath(tempDirectory);
    assertThat(new File(mountableFile.getResolvedPath())).isDirectory();
    container.withCopyFileToContainer(mountableFile, "/foo/bar/");

    long hash1 = container.hashCopiedFiles().getValue();

    Path fileInFolder = Files.createFile(
        // Create file in the sub-folder
        Files.createDirectory(tempDirectory.resolve("sub")).resolve("test.txt")
    );
    assertThat(fileInFolder).exists();
    Files.write(fileInFolder, UUID.randomUUID().toString().getBytes());

    assertThat(container.hashCopiedFiles().getValue()).isNotEqualTo(hash1);
}
 
Example #3
Source File: Neo4jContainerTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void shouldCopyDatabase() {
    try (
        Neo4jContainer neo4jContainer = new Neo4jContainer()
            .withDatabase(MountableFile.forClasspathResource("/test-graph.db"));
    ) {
        neo4jContainer.start();
        try (
            Driver driver = getDriver(neo4jContainer);
            Session session = driver.session()
        ) {
            StatementResult result = session.run("MATCH (t:Thing) RETURN t");
            assertThat(result.list().stream().map(r -> r.get("t").get("name").asString()))
                .containsExactlyInAnyOrder("Thing", "Thing 2", "Thing 3", "A box");
        }
    }
}
 
Example #4
Source File: ReusabilityUnitTests.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void folderAndFile() throws Exception {
    Path tempDirectory = Files.createTempDirectory("reusable_test");
    MountableFile mountableFile = MountableFile.forHostPath(tempDirectory);
    assertThat(new File(mountableFile.getResolvedPath())).isDirectory();
    container.withCopyFileToContainer(mountableFile, "/foo/bar/");

    long hash1 = container.hashCopiedFiles().getValue();

    container.withCopyFileToContainer(
        MountableFile.forClasspathResource("test_copy_to_container.txt"),
        "/foo/baz"
    );

    assertThat(container.hashCopiedFiles().getValue()).isNotEqualTo(hash1);
}
 
Example #5
Source File: CopyFileToContainerTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void shouldUseCopyOnlyWithReadOnlyClasspathResources() {
    String resource = "/test_copy_to_container.txt";
    GenericContainer<?> container = new GenericContainer<>()
        .withClasspathResourceMapping(resource, "/readOnly", BindMode.READ_ONLY)
        .withClasspathResourceMapping(resource, "/readOnlyNoSelinux", BindMode.READ_ONLY)

        .withClasspathResourceMapping(resource, "/readOnlyShared", BindMode.READ_ONLY, SelinuxContext.SHARED)
        .withClasspathResourceMapping(resource, "/readWrite", BindMode.READ_WRITE);

    Map<MountableFile, String> copyMap = container.getCopyToFileContainerPathMap();
    assertTrue("uses copy for read-only", copyMap.containsValue("/readOnly"));
    assertTrue("uses copy for read-only and no Selinux", copyMap.containsValue("/readOnlyNoSelinux"));

    assertFalse("uses mount for read-only with Selinux", copyMap.containsValue("/readOnlyShared"));
    assertFalse("uses mount for read-write", copyMap.containsValue("/readWrite"));
}
 
Example #6
Source File: FileOperationsTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void copyFileToContainerFileTest() throws Exception {
    try (
        GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2")
            .withCommand("top")
    ) {
        alpineCopyToContainer.start();
        final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt");
        alpineCopyToContainer.copyFileToContainer(mountableFile, "/test.txt");

        File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_to_container.txt");
        alpineCopyToContainer.copyFileFromContainer("/test.txt", actualFile.getPath());

        File expectedFile = new File(mountableFile.getResolvedPath());
        assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
    }
}
 
Example #7
Source File: EmbeddedPrometheusBootstrapConfiguration.java    From kayenta with Apache License 2.0 6 votes vote down vote up
@Bean(name = "prometheus", destroyMethod = "stop")
public GenericContainer prometheus(
    ConfigurableEnvironment environment, WaitStrategy prometheusWaitStrategy) {

  GenericContainer container =
      new GenericContainer("prom/prometheus:v2.10.0")
          .withLogConsumer(containerLogsConsumer(log))
          .withExposedPorts(PORT)
          .withCopyFileToContainer(
              MountableFile.forClasspathResource("/external/prometheus/prometheus.yml"),
              "/etc/prometheus/prometheus.yml")
          .waitingFor(prometheusWaitStrategy)
          .withStartupTimeout(Duration.ofSeconds(30));
  container.start();
  Map<String, Object> env = registerEnvironment(environment, container.getMappedPort(PORT));
  log.info("Started Prometheus server. Connection details: {}", env);
  return container;
}
 
Example #8
Source File: ReusabilityUnitTests.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void folderPermissions() throws Exception {
    Path tempDirectory = Files.createTempDirectory("reusable_test");
    MountableFile mountableFile = MountableFile.forHostPath(tempDirectory);
    assertThat(new File(mountableFile.getResolvedPath())).isDirectory();
    Path subDir = Files.createDirectory(tempDirectory.resolve("sub"));
    subDir.toFile().setWritable(false);
    assumeThat(subDir.toFile().canWrite()).isFalse();
    container.withCopyFileToContainer(mountableFile, "/foo/bar/");

    long hash1 = container.hashCopiedFiles().getValue();

    subDir.toFile().setWritable(true);
    assumeThat(subDir.toFile()).canWrite();

    assertThat(container.hashCopiedFiles().getValue()).isNotEqualTo(hash1);
}
 
Example #9
Source File: BesuNode.java    From teku with Apache License 2.0 6 votes vote down vote up
public BesuNode(final Network network) {
  super(network, "hyperledger/besu:1.3.6", LOG);
  container
      .withExposedPorts(JSON_RPC_PORT)
      .withLogConsumer(frame -> LOG.debug(frame.getUtf8String().trim()))
      .waitingFor(new HttpWaitStrategy().forPort(JSON_RPC_PORT).forPath("/liveness"))
      .withCopyFileToContainer(
          MountableFile.forClasspathResource("besu/depositContractGenesis.json"), "/genesis.json")
      .withCommand(
          "--rpc-http-enabled",
          "--rpc-http-port",
          Integer.toString(JSON_RPC_PORT),
          "--rpc-http-cors-origins=*",
          "--host-whitelist=*",
          "--miner-enabled",
          "--miner-coinbase",
          "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73",
          "--genesis-file",
          "/genesis.json");
}
 
Example #10
Source File: FileOperationsTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void copyFileToContainerFolderTest() throws Exception {
    try (
        GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2")
            .withCommand("top")
    ) {
        alpineCopyToContainer.start();
        final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt");
        alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/");

        File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_to_container.txt");
        alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt", actualFile.getPath());

        File expectedFile = new File(mountableFile.getResolvedPath());
        assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
    }
}
 
Example #11
Source File: PulsarTlsContainer.java    From liiklus with MIT License 6 votes vote down vote up
public PulsarTlsContainer(String pulsarVersion) {
    super(pulsarVersion);
    withExposedPorts(BROKER_TLS_PORT, BROKER_HTTP_PORT);
    withEnv("PULSAR_PREFIX_brokerServicePortTls", BROKER_TLS_PORT + "");
    withEnv("PULSAR_PREFIX_tlsEnabled", "true");
    withEnv("PULSAR_PREFIX_tlsCertificateFilePath", "/pulsar/broker.cert.pem");
    withEnv("PULSAR_PREFIX_tlsKeyFilePath", "/pulsar/broker.key-pk8.pem");
    withEnv("PULSAR_PREFIX_tlsTrustCertsFilePath", "/pulsar/ca.cert.pem");

    withCopyFileToContainer(MountableFile.forClasspathResource("certs/"), "/pulsar/");

    setCommand(
            "/bin/bash",
            "-c",
            "bin/apply-config-from-env.py conf/standalone.conf && " +
            "bin/apply-config-from-env.py conf/proxy.conf && " +
                    "bin/pulsar standalone --no-functions-worker -nss"
    );

    waitingFor(Wait.forLogMessage(".*Created namespace public\\/default.*", 1));
}
 
Example #12
Source File: FileOperationsTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void copyFolderToContainerFolderTest() throws Exception {
    try (
        GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2")
            .withCommand("top")
    ) {

        alpineCopyToContainer.start();
        final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/");
        alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/test/");

        File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_to_container.txt");
        alpineCopyToContainer.copyFileFromContainer("/home/test/test-resource.txt", actualFile.getPath());

        File expectedFile = new File(mountableFile.getResolvedPath() + "/test-resource.txt");
        assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
    }
}
 
Example #13
Source File: FileOperationsTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void shouldCopyFileFromContainerTest() throws IOException {
    try (
        GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2")
            .withCommand("top")
    ) {

        alpineCopyToContainer.start();
        final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt");
        alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/");

        File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_from_container.txt");
        alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt", actualFile.getPath());

        File expectedFile = new File(mountableFile.getResolvedPath());
        assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
    }
}
 
Example #14
Source File: RabbitMQContainerTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void shouldMountConfigurationFile()
{
    try (RabbitMQContainer container = new RabbitMQContainer()) {

        container.withRabbitMQConfig(MountableFile.forClasspathResource("/rabbitmq-custom.conf"));
        container.start();

        assertThat(container.getLogs()).contains("config file(s) : /etc/rabbitmq/rabbitmq-custom.conf");
        assertThat(container.getLogs()).doesNotContain(" (not found)");
    }
}
 
Example #15
Source File: RabbitMQContainerTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void shouldMountConfigurationFileErlang()
{
    try (RabbitMQContainer container = new RabbitMQContainer()) {

        container.withRabbitMQConfigErlang(MountableFile.forClasspathResource("/rabbitmq-custom.config"));
        container.start();

        assertThat(container.getLogs()).contains("config file(s) : /etc/rabbitmq/rabbitmq-custom.config");
        assertThat(container.getLogs()).doesNotContain(" (not found)");
    }
}
 
Example #16
Source File: RabbitMQContainerTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void shouldMountConfigurationFileSysctl()
{
    try (RabbitMQContainer container = new RabbitMQContainer()) {

        container.withRabbitMQConfigSysctl(MountableFile.forClasspathResource("/rabbitmq-custom.conf"));
        container.start();

        assertThat(container.getLogs()).contains("config file(s) : /etc/rabbitmq/rabbitmq-custom.conf");
        assertThat(container.getLogs()).doesNotContain(" (not found)");
    }
}
 
Example #17
Source File: ReusabilityUnitTests.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void oneFile() {
    long emptyHash = container.hashCopiedFiles().getValue();

    container.withCopyFileToContainer(
        MountableFile.forClasspathResource("test_copy_to_container.txt"),
        "/foo/bar"
    );

    assertThat(container.hashCopiedFiles().getValue()).isNotEqualTo(emptyHash);
}
 
Example #18
Source File: GenericContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
@VisibleForTesting
@SneakyThrows(IOException.class)
void checksumFile(File file, Checksum checksum) {
    Path path = file.toPath();
    checksum.update(MountableFile.getUnixFileMode(path));
    if (file.isDirectory()) {
        try (Stream<Path> stream = Files.walk(path)) {
            stream.filter(it -> it != path).forEach(it -> {
                checksumFile(it.toFile(), checksum);
            });
        }
    } else {
        FileUtils.checksum(file, checksum);
    }
}
 
Example #19
Source File: GenericContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
/**
 * {@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));
}
 
Example #20
Source File: CopyFileToContainerTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void checkFileCopied() throws IOException, InterruptedException {
    try (
        GenericContainer container = new GenericContainer()
            .withCommand("sleep", "3000")
            .withCopyFileToContainer(MountableFile.forClasspathResource("/mappable-resource/"), containerPath)
    ) {
        container.start();
        String filesList = container.execInContainer("ls", "/tmp/mappable-resource").getStdout();
        assertTrue("file list contains the file", filesList.contains(fileName));
    }
}
 
Example #21
Source File: GenericContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public SELF withClasspathResourceMapping(final String resourcePath, final String containerPath, final BindMode mode, final SelinuxContext selinuxContext) {
    final MountableFile mountableFile = MountableFile.forClasspathResource(resourcePath);

    if (mode == BindMode.READ_ONLY && selinuxContext == SelinuxContext.NONE) {
        withCopyFileToContainer(mountableFile, containerPath);
    } else {
        addFileSystemBind(mountableFile.getResolvedPath(), containerPath, mode, selinuxContext);
    }

    return self();
}
 
Example #22
Source File: ReusabilityUnitTests.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void shouldHashCopiedFiles() {
    Mockito.doReturn(true).when(TestcontainersConfiguration.getInstance()).environmentSupportsReuse();
    AtomicReference<CreateContainerCmd> commandRef = new AtomicReference<>();
    String containerId = randomContainerId();
    when(client.createContainerCmd(any())).then(createContainerAnswer(containerId, commandRef::set));
    when(client.listContainersCmd()).then(listContainersAnswer());
    when(client.startContainerCmd(containerId)).then(startContainerAnswer());
    when(client.inspectContainerCmd(containerId)).then(inspectContainerAnswer());

    container.start();

    assertThat(commandRef).isNotNull();

    Map<String, String> labels = commandRef.get().getLabels();
    assertThat(labels).containsKeys(GenericContainer.COPIED_FILES_HASH_LABEL);

    String oldHash = labels.get(GenericContainer.COPIED_FILES_HASH_LABEL);

    // Simulate stop
    container.containerId = null;

    container.withCopyFileToContainer(
        MountableFile.forClasspathResource("test_copy_to_container.txt"),
        "/foo/bar"
    );
    container.start();

    assertThat(commandRef.get().getLabels()).hasEntrySatisfying(GenericContainer.COPIED_FILES_HASH_LABEL, newHash -> {
        assertThat(newHash).as("new hash").isNotEqualTo(oldHash);
    });
}
 
Example #23
Source File: DockerComposeContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
public ContainerisedDockerCompose(List<File> composeFiles, String identifier) {

        super(TestcontainersConfiguration.getInstance().getDockerComposeContainerImage());
        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);
    }
 
Example #24
Source File: ContainerState.java    From testcontainers-java with MIT License 5 votes vote down vote up
/**
 *
 * Copies a file or directory to the container.
 *
 * @param mountableFile file or directory which is copied into the container
 * @param containerPath destination path inside the container
 */
default void copyFileToContainer(MountableFile mountableFile, String containerPath) {
    File sourceFile = new File(mountableFile.getResolvedPath());

    if (containerPath.endsWith("/") && sourceFile.isFile()) {
        final Logger logger = LoggerFactory.getLogger(GenericContainer.class);
        logger.warn("folder-like containerPath in copyFileToContainer is deprecated, please explicitly specify a file path");
        copyFileToContainer((Transferable) mountableFile, containerPath + sourceFile.getName());
    } else {
        copyFileToContainer((Transferable) mountableFile, containerPath);
    }
}
 
Example #25
Source File: ReusabilityUnitTests.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void multipleFiles() {
    container.withCopyFileToContainer(
        MountableFile.forClasspathResource("test_copy_to_container.txt"),
        "/foo/bar"
    );
    long hash1 = container.hashCopiedFiles().getValue();

    container.withCopyFileToContainer(
        MountableFile.forClasspathResource("mappable-resource/test-resource.txt"),
        "/foo/baz"
    );

    assertThat(container.hashCopiedFiles().getValue()).isNotEqualTo(hash1);
}
 
Example #26
Source File: Prysm.java    From teku with Apache License 2.0 5 votes vote down vote up
public Prysm() {
  super("gcr.io/prysmaticlabs/prysm/beacon-chain:latest");
  try {
    PrivKey privKey = KeyKt.generateKeyPair(KEY_TYPE.SECP256K1).component1();
    PubKey pubKey = privKey.publicKey();
    nodeId = new LibP2PNodeId(PeerId.fromPubKey(pubKey));

    privKeyFile = writePrivKeyToFile(privKey);

    withExposedPorts(13000);
    withCommand(
        "--p2p-tcp-port",
        "13000",
        "--no-discovery",
        "--minimal-config",
        "--p2p-priv-key",
        PRIVKEY_TARGET_PATH,
        "--verbosity",
        "INFO");
    withStartupTimeout(Duration.of(2, MINUTES));
    waitingFor(Wait.forLogMessage(".*Node started p2p server.*", 1));
    withCopyFileToContainer(
        MountableFile.forHostPath(privKeyFile.getAbsolutePath()), PRIVKEY_TARGET_PATH);
    withLogConsumer(outputFrame -> LOG.debug(outputFrame.getUtf8String().trim()));
  } catch (final IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #27
Source File: TekuNode.java    From teku with Apache License 2.0 5 votes vote down vote up
public void start() throws Exception {
  assertThat(started).isFalse();
  LOG.debug("Start node {}", nodeAlias);
  started = true;
  final Map<File, String> configFiles = config.write();
  this.configFiles = configFiles.keySet();
  configFiles.forEach(
      (localFile, targetPath) ->
          container.withCopyFileToContainer(
              MountableFile.forHostPath(localFile.getAbsolutePath()), targetPath));
  container.start();
}
 
Example #28
Source File: ShellUserGroupProviderIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
private GenericContainer createContainer(String image) throws IOException, InterruptedException {
    GenericContainer container = new GenericContainer(image)
        .withEnv("SSH_ENABLE_ROOT", "true").withExposedPorts(CONTAINER_SSH_PORT);
    container.start();

    // This can go into the docker images:
    container.execInContainer("mkdir", "-p", "/root/.ssh");
    container.copyFileToContainer(MountableFile.forHostPath(sshPubKeyFile),  CONTAINER_SSH_AUTH_KEYS);
    return container;
}
 
Example #29
Source File: ContainerPgRule.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
private void initServer(String version) throws Exception {
  File setupFile = getTestResource("resources" + File.separator + "create-postgres.sql");
  
  server = (PostgreSQLContainer) new PostgreSQLContainer("postgres:" + version)
      .withDatabaseName("postgres")
      .withUsername("postgres")
      .withPassword("postgres")
      .withCopyFileToContainer(MountableFile.forHostPath(setupFile.toPath()), "/docker-entrypoint-initdb.d/create-postgres.sql");
  if(ssl) {
    server.withCopyFileToContainer(MountableFile.forHostPath(getTestResource("resources" +File.separator + "server.crt").toPath()), "/server.crt")
          .withCopyFileToContainer(MountableFile.forHostPath(getTestResource("resources" +File.separator + "server.key").toPath()), "/server.key")
          .withCopyFileToContainer(MountableFile.forHostPath(getTestResource("ssl.sh").toPath()), "/docker-entrypoint-initdb.d/ssl.sh");
  }
}
 
Example #30
Source File: PostgresHandleTest.java    From okapi with Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void beforeAll() {
  MountableFile serverKeyFile = MountableFile.forClasspathResource("server.key");
  MountableFile serverCrtFile = MountableFile.forClasspathResource("server.crt");
  POSTGRESQL_CONTAINER.copyFileToContainer(serverKeyFile, KEY_PATH);
  POSTGRESQL_CONTAINER.copyFileToContainer(serverCrtFile, CRT_PATH);
  exec("chown", "postgres.postgres", KEY_PATH, CRT_PATH);
  exec("chmod", "400", KEY_PATH, CRT_PATH);
  exec("cp", "-p", CONF_PATH, CONF_BAK_PATH);

  serverCrt = getResource("server.crt");
  OkapiLogger.get().debug(() -> config().encodePrettily());
}