Allow enforcement to reuse a container in the CI build.
This orders reusable containers on wish and is meant for scenarios in which a CI does not allow "native" use of reusable test containers but will make sure to clean them up after CI ran. Export a variable `SDN_FORCE_REUSE_OF_CONTAINERS` as `true` and SDN tests won't close the container, regardless whether the underlying Testcontainers supports reuse or not. Closes #2837
This commit is contained in:
committed by
Mark Paluch
parent
0f54c6f04a
commit
279ba10388
@@ -6,6 +6,7 @@ mkdir -p /tmp/jenkins-home
|
||||
chown -R 1001:1001 .
|
||||
|
||||
export JENKINS_USER=${JENKINS_USER_NAME}
|
||||
export SDN_FORCE_REUSE_OF_CONTAINERS=true
|
||||
|
||||
MAVEN_OPTS="-Duser.name=${JENKINS_USER} -Duser.home=/tmp/jenkins-home -Dscan=false" \
|
||||
./mvnw -s settings.xml -P${PROFILE} clean dependency:list verify -Dsort -U -B -Dmaven.repo.local=/tmp/jenkins-home/.m2/spring-data-neo4j
|
||||
|
||||
@@ -21,12 +21,9 @@ import lombok.extern.apachecommons.CommonsLog;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -84,10 +81,11 @@ public class Neo4jExtension implements BeforeAllCallback, BeforeEachCallback {
|
||||
private static final String SYS_PROPERTY_NEO4J_ACCEPT_COMMERCIAL_EDITION = "SDN_NEO4J_ACCEPT_COMMERCIAL_EDITION";
|
||||
private static final String SYS_PROPERTY_NEO4J_REPOSITORY = "SDN_NEO4J_REPOSITORY";
|
||||
private static final String SYS_PROPERTY_NEO4J_VERSION = "SDN_NEO4J_VERSION";
|
||||
private static final String SYS_PROPERTY_FORCE_CONTAINER_REUSE = "SDN_FORCE_REUSE_OF_CONTAINERS";
|
||||
|
||||
private static Set<String> COMMUNITY_EDITION_INDICATOR = Collections.singleton("community");
|
||||
private static Set<String> COMMUNITY_EDITION_INDICATOR = Set.of("community");
|
||||
|
||||
private static Set<String> COMMERCIAL_EDITION_INDICATOR = new HashSet<>(Arrays.asList("commercial", "enterprise"));
|
||||
private static Set<String> COMMERCIAL_EDITION_INDICATOR = Set.of("commercial", "enterprise");
|
||||
|
||||
@Override
|
||||
public void beforeAll(ExtensionContext context) throws Exception {
|
||||
@@ -296,21 +294,20 @@ public class Neo4jExtension implements BeforeAllCallback, BeforeEachCallback {
|
||||
|
||||
static class ContainerAdapter implements ExtensionContext.Store.CloseableResource {
|
||||
|
||||
private final String repository = Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_REPOSITORY)).orElse("neo4j");
|
||||
private static final String repository = Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_REPOSITORY)).orElse("neo4j");
|
||||
|
||||
private final String imageVersion = Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_VERSION)).orElse("5");
|
||||
private static final String imageVersion = Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_VERSION)).orElse("5");
|
||||
|
||||
private final boolean containerReuseSupported = TestcontainersConfiguration
|
||||
private static final boolean containerReuseSupported = TestcontainersConfiguration
|
||||
.getInstance().environmentSupportsReuse();
|
||||
|
||||
private final Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>(repository + ":" + imageVersion)
|
||||
private static final boolean forceReuse = Boolean.parseBoolean(System.getenv(SYS_PROPERTY_FORCE_CONTAINER_REUSE));
|
||||
|
||||
private static final Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>(repository + ":" + imageVersion)
|
||||
.withoutAuthentication()
|
||||
.withEnv("NEO4J_ACCEPT_LICENSE_AGREEMENT",
|
||||
Optional.ofNullable(System.getenv(SYS_PROPERTY_NEO4J_ACCEPT_COMMERCIAL_EDITION)).orElse("no"))
|
||||
.withTmpFs(new HashMap<String, String>() {{ // K.W. Gedächtnis-Double-Brace-Initialization
|
||||
put("/log", "rw");
|
||||
put("/data", "rw");
|
||||
}})
|
||||
.withTmpFs(Map.of("/log", "rw", "/data", "rw"))
|
||||
.withReuse(containerReuseSupported);
|
||||
|
||||
public String getBoltUrl() {
|
||||
@@ -318,13 +315,15 @@ public class Neo4jExtension implements BeforeAllCallback, BeforeEachCallback {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
neo4jContainer.start();
|
||||
if (!neo4jContainer.isRunning()) {
|
||||
neo4jContainer.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (!containerReuseSupported) {
|
||||
this.neo4jContainer.close();
|
||||
if (!(containerReuseSupported || forceReuse)) {
|
||||
neo4jContainer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user