public GenericContainer() { this(TestcontainersConfiguration.getInstance().getTinyImage()); }
private static String resolveImageName() { String image = TestcontainersConfiguration.getInstance() .getProperties().getProperty("oracle.container.image"); if (image == null) { throw new IllegalStateException("An image to use for Oracle containers must be configured. " + "To do this, please place a file on the classpath named `testcontainers.properties`, " + "containing `oracle.container.image=IMAGE`, where IMAGE is a suitable image name and tag."); } return image; }
@SneakyThrows(MalformedURLException.class) private static TestcontainersConfiguration loadConfiguration() { final TestcontainersConfiguration config = new TestcontainersConfiguration( Stream .of( ); if (!config.getProperties().isEmpty()) { log.debug("Testcontainers configuration overrides loaded from {}", config);
.concat( Stream .of(TestcontainersConfiguration.getInstance().getDockerClientStrategyClassName()) .filter(Objects::nonNull) .flatMap(it -> { TestcontainersConfiguration.getInstance().updateGlobalConfig("docker.client.strategy", strategy.getClass().getName());
public SocatContainer() { super(TestcontainersConfiguration.getInstance().getSocatContainerImage()); withCreateContainerCmdModifier(it -> it.withEntrypoint("/bin/sh")); withCreateContainerCmdModifier(it -> it.withName("testcontainers-socat-" + Base58.randomString(8))); }
protected DockerClient getClientForConfig(DockerClientConfig config) { DockerClientBuilder clientBuilder = DockerClientBuilder .getInstance(new AuthDelegatingDockerClientConfig(config)); String transportType = TestcontainersConfiguration.getInstance().getTransportType(); if ("okhttp".equals(transportType)) { clientBuilder .withDockerCmdExecFactory(new OkHttpDockerCmdExecFactory()); } else if ("netty".equals(transportType)) { clientBuilder .withDockerCmdExecFactory(new TestcontainersDockerCmdExecFactory()); } else { throw new IllegalArgumentException("Unknown transport type: " + transportType); } LOGGER.info("Will use '{}' transport", transportType); return clientBuilder.build(); }
public AmbassadorContainer(LinkableContainer otherContainer, String serviceName, int servicePort) { super(TestcontainersConfiguration.getInstance().getAmbassadorContainerImage()); /* Use the unique 'identifierPrefix' (random compose project name) so that the ambassador can see the container it's supposed to be proxying. */ this.otherContainerName = otherContainer.getContainerName(); this.serviceName = serviceName; this.servicePort = servicePort; // Link addLink(otherContainer, serviceName); // Expose ambassador's port addExposedPort(servicePort); // Tell the proxy what to connect to within the docker network addEnv("SERVICE_NAME", serviceName); addEnv("SERVICE_PORT", String.format("%d", servicePort)); }
@SneakyThrows private Connection createSSHSession() { String password = UUID.randomUUID().toString(); container = new GenericContainer<>(TestcontainersConfiguration.getInstance().getSSHdImage()) .withExposedPorts(22) .withEnv("PASSWORD", password) .withCommand( "sh", "-c", // Disable ipv6 & Make it listen on all interfaces, not just localhost "echo \"root:$PASSWORD\" | chpasswd && /usr/sbin/sshd -D -o PermitRootLogin=yes -o AddressFamily=inet -o GatewayPorts=yes" ); container.start(); Connection connection = new Connection(container.getContainerIpAddress(), container.getMappedPort(22)); connection.setTCPNoDelay(true); connection.connect( (hostname, port, serverHostKeyAlgorithm, serverHostKey) -> true, (int) Duration.ofSeconds(30).toMillis(), (int) Duration.ofSeconds(30).toMillis() ); if (!connection.authenticateWithPassword("root", password)) { throw new IllegalStateException("Authentication failed."); } return connection; }
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); } }
super(TestcontainersConfiguration.getInstance().getVncRecordedContainerImage());
createCommand.withEnv(envArray); boolean shouldCheckFileMountingSupport = binds.size() > 0 && !TestcontainersConfiguration.getInstance().isDisableChecks(); if (shouldCheckFileMountingSupport) { if (!DockerClientFactory.instance().isFileMountingSupported()) {
public static String start(String hostIpAddress, DockerClient client) { try { String ryukImage = TestcontainersConfiguration.getInstance().getRyukImage(); DockerClientFactory.instance().checkAndPullImage(client, ryukImage); List<Bind> binds = new ArrayList<>(); binds.add(new Bind("//var/run/docker.sock", new Volume("/var/run/docker.sock"))); String ryukContainerId = client.createContainerCmd(ryukImage).withHostConfig(new HostConfig().withAutoRemove(true)).withExposedPorts(new ExposedPort(8080)).withPublishAllPorts(true).withName("testcontainers-ryuk-" + DockerClientFactory.SESSION_ID).withLabels(Collections.singletonMap(DockerClientFactory.TESTCONTAINERS_LABEL, "true")).withBinds(binds).withPrivileged(TestcontainersConfiguration.getInstance().isRyukPrivileged()).exec().getId(); client.startContainerCmd(ryukContainerId).exec(); InspectContainerResponse inspectedContainer = client.inspectContainerCmd(ryukContainerId).exec(); kiraThread.start(); if (!ryukScheduledLatch.await(TestcontainersConfiguration.getInstance().getRyukTimeout(), TimeUnit.SECONDS)) { throw new IllegalStateException("Can not connect to Ryuk");
public PulsarContainer(String pulsarVersion) { super(TestcontainersConfiguration.getInstance().getPulsarImage() + ":" + pulsarVersion); withExposedPorts(BROKER_PORT, BROKER_HTTP_PORT); withCommand("/pulsar/bin/pulsar", "standalone", "--no-functions-worker", "-nss"); waitingFor(Wait.forHttp(METRICS_ENDPOINT).forStatusCode(200).forPort(BROKER_HTTP_PORT)); }
private void putImageInRegistry() throws InterruptedException { // It doesn't matter which image we use for this test, but use one that's likely to have been pulled already final String dummySourceImage = TestcontainersConfiguration.getInstance().getRyukImage(); client.pullImageCmd(dummySourceImage) .exec(new PullImageResultCallback()) .awaitCompletion(1, TimeUnit.MINUTES); final String id = client.inspectImageCmd(dummySourceImage) .exec() .getId(); // push the image to the registry client.tagImageCmd(id, testImageName, "latest").exec(); client.pushImageCmd(testImageNameWithTag) .exec(new PushImageResultCallback()) .awaitCompletion(1, TimeUnit.MINUTES); // remove the image tag from local docker so that it must be pulled before use client.removeImageCmd(testImageNameWithTag).withForce(true).exec(); } }
public KafkaContainer(String confluentPlatformVersion) { super(TestcontainersConfiguration.getInstance().getKafkaImage() + ":" + confluentPlatformVersion); withNetwork(Network.newNetwork()); withNetworkAliases("kafka-" + Base58.randomString(6)); withExposedPorts(KAFKA_PORT); // Use two listeners with different names, it will force Kafka to communicate with itself via internal // listener when KAFKA_INTER_BROKER_LISTENER_NAME is set, otherwise Kafka will try to use the advertised listener withEnv("KAFKA_LISTENERS", "PLAINTEXT://0.0.0.0:" + KAFKA_PORT + ",BROKER://0.0.0.0:9092"); withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "BROKER:PLAINTEXT,PLAINTEXT:PLAINTEXT"); withEnv("KAFKA_INTER_BROKER_LISTENER_NAME", "BROKER"); withEnv("KAFKA_BROKER_ID", "1"); withEnv("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "1"); withEnv("KAFKA_OFFSETS_TOPIC_NUM_PARTITIONS", "1"); withEnv("KAFKA_LOG_FLUSH_INTERVAL_MESSAGES", Long.MAX_VALUE + ""); withEnv("KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS", "0"); }
@java.lang.Override @java.lang.SuppressWarnings("all") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof TestcontainersConfiguration)) return false; final TestcontainersConfiguration other = (TestcontainersConfiguration) o; if (!other.canEqual((java.lang.Object) this)) return false; final java.lang.Object this$properties = this.getProperties(); final java.lang.Object other$properties = other.getProperties(); if (this$properties == null ? other$properties != null : !this$properties.equals(other$properties)) return false; return true; }
this(TestcontainersConfiguration.getInstance().getTinyImage());
private static TestcontainersConfiguration loadConfiguration() { try { final TestcontainersConfiguration config = new TestcontainersConfiguration(Stream.of(TestcontainersConfiguration.class.getClassLoader().getResource(PROPERTIES_FILE_NAME), Thread.currentThread().getContextClassLoader().getResource(PROPERTIES_FILE_NAME), GLOBAL_CONFIG_FILE.toURI().toURL()).filter(Objects::nonNull).map(it -> { log.debug("Testcontainers configuration overrides will be loaded from {}", it); final Properties subProperties = new Properties(); try (InputStream inputStream = it.openStream()) { subProperties.load(inputStream); } catch (FileNotFoundException e) { log.trace("Testcontainers config override was found on " + it + " but the file was not found", e); } catch (IOException e) { log.warn("Testcontainers config override was found on " + it + " but could not be loaded", e); } return subProperties; }).reduce(new Properties(), (a, b) -> { a.putAll(b); return a; })); if (!config.getProperties().isEmpty()) { log.debug("Testcontainers configuration overrides loaded from {}", config); } return config; } catch (final MalformedURLException $ex) { throw lombok.Lombok.sneakyThrow($ex); } }
.concat( Stream .of(TestcontainersConfiguration.getInstance().getDockerClientStrategyClassName()) .filter(Objects::nonNull) .flatMap(it -> { TestcontainersConfiguration.getInstance().updateGlobalConfig("docker.client.strategy", strategy.getClass().getName());
public SocatContainer() { super(TestcontainersConfiguration.getInstance().getSocatContainerImage()); withCreateContainerCmdModifier(it -> it.withEntrypoint("/bin/sh")); withCreateContainerCmdModifier(it -> it.withName("testcontainers-socat-" + Base58.randomString(8))); }