Skip to content

Commit

Permalink
copy extension resources instead of just binding
Browse files Browse the repository at this point in the history
this allows also to run the testcontainer on a remote machine
resolves #44
  • Loading branch information
dasniko committed Dec 1, 2021
1 parent ebff8ff commit 01c1782
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package dasniko.testcontainers.keycloak;

import com.github.dockerjava.api.command.InspectContainerResponse;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.SelinuxContext;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
Expand All @@ -12,14 +10,20 @@
import org.testcontainers.utility.MountableFile;

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Stream;

/**
* @author Niko Köbler, https://www.n-k.de, @dasniko
Expand Down Expand Up @@ -183,7 +187,17 @@ protected void createKeycloakExtensionDeployment(String deploymentLocation, Stri

String explodedFolderName = extensionClassFolder.hashCode() + "-" + extensionName;
String explodedFolderExtensionsJar = deploymentLocation + "/" + explodedFolderName;
addFileSystemBind(classesLocation, explodedFolderExtensionsJar, BindMode.READ_WRITE, SelinuxContext.SINGLE);

try (Stream<Path> extensionPathStream = Files.walk(Paths.get(extensionClassFolder))) {
extensionPathStream.forEach(extPath -> {
if (!Files.isDirectory(extPath)) {
withCopyFileToContainer(MountableFile.forClasspathResource(extPath.toString().replace(extensionClassFolder, "")),
explodedFolderExtensionsJar + extPath.toString().replace(extensionClassFolder, ""));
}
});
} catch (IOException e) {
throw new UncheckedIOException(e);
}

boolean wildflyDeployment = deploymentLocation.contains("/standalone/deployments");
if (wildflyDeployment) {
Expand Down

0 comments on commit 01c1782

Please sign in to comment.