public SocatContainer() { super(TestcontainersConfiguration.getInstance().getSocatContainerImage()); withCreateContainerCmdModifier(it -> it.withEntrypoint("/bin/sh")); withCreateContainerCmdModifier(it -> it.withName("testcontainers-socat-" + Base58.randomString(8))); }
client, createContainerCmd -> { createContainerCmd.withName("testcontainers-checks-" + SESSION_ID); createContainerCmd.getHostConfig().withAutoRemove(true); createContainerCmd.withCmd("tail", "-f", "/dev/null");
@Test public void createContainerCmdHookTest() { // Use random name to avoid the conflicts between the tests String randomName = Base58.randomString(5); try( GenericContainer container = new GenericContainer<>("redis:3.0.2") .withCommand("redis-server", "--help") .withCreateContainerCmdModifier(cmd -> cmd.withName("overrideMe")) // Preserves the order .withCreateContainerCmdModifier(cmd -> cmd.withName(randomName)) // Allows to override pre-configured values by GenericContainer .withCreateContainerCmdModifier(cmd -> cmd.withCmd("redis-server", "--port", "6379")) ) { container.start(); assertEquals("Name is configured", "/" + randomName, container.getContainerInfo().getName()); assertEquals("Command is configured", "[redis-server, --port, 6379]", Arrays.toString(container.getContainerInfo().getConfig().getCmd())); } }
@Override protected CreateContainerCmd dockerCommand() { return DockerClientFactory.build() .createContainerCmd(SEED_DATA_IMAGE) .withEnv("ELASTIC_SEARCH_URL=" + elasticSearchUrl) .withName("seed_data_" + new SecureRandom().nextInt()); }
private CreateContainerCmd computeContainerName(ServiceDescriptor dependency, int i, CreateContainerCmd cmd) { if (!dependency.getContainerName() .isEmpty()) { String name = dependency.getReplicas() > 1 ? dependency.getContainerName() + "-" + (i + 1) : dependency.getContainerName(); cmd = cmd.withName(name); } return cmd; }
@Override protected CreateContainerCmd dockerCommand() { return dockerClient .createContainerCmd(TEST_CONFIG.getSchedulerImageName()) .withName(TEST_CONFIG.getSchedulerName() + "_" + new SecureRandom().nextInt()) .withEnv("JAVA_OPTS=-Xms128m -Xmx256m") .withCmd( ZookeeperCLIParameter.ZOOKEEPER_MESOS_URL, getZookeeperMesosUrl(), ElasticsearchCLIParameter.ELASTICSEARCH_NODES, Integer.toString(TEST_CONFIG.getElasticsearchNodesCount()), Configuration.ELASTICSEARCH_RAM, Integer.toString(TEST_CONFIG.getElasticsearchMemorySize()), Configuration.ELASTICSEARCH_CPU, "0.1", Configuration.ELASTICSEARCH_DISK, "150", Configuration.USE_IP_ADDRESS, "false", Configuration.WEB_UI_PORT, Integer.toString(TEST_CONFIG.getSchedulerGuiPort()), Configuration.EXECUTOR_NAME, TEST_CONFIG.getElasticsearchJobName(), Configuration.FRAMEWORK_USE_DOCKER, "true", Configuration.DATA_DIR, dataDirectory, Configuration.FRAMEWORK_ROLE, frameworkRole); }
public void createContainer(String imageId, String containerName, boolean mountFolders, String... env) { pullImageIfNecessary(imageId, false); log.debug("Creating container {}", containerName); CreateContainerCmd createContainerCmd = getClient().createContainerCmd(imageId).withName(containerName).withEnv(env) .withVolumes(new Volume("/var/run/docker.sock")); if (mountFolders) { mountDefaultFolders(createContainerCmd); } createContainerCmd.exec(); log.debug("Container {} started...", containerName); }
public void createContainer(String imageId, String containerName, boolean mountFolders, String... env) { pullImageIfNecessary(imageId, false); log.debug("Creating container {}", containerName); CreateContainerCmd createContainerCmd = getClient().createContainerCmd(imageId).withName(containerName).withEnv(env) .withVolumes(new Volume("/var/run/docker.sock")); if (mountFolders) { mountDefaultFolders(createContainerCmd); } createContainerCmd.exec(); log.debug("Container {} started...", containerName); }
public SocatContainer() { super(TestcontainersConfiguration.getInstance().getSocatContainerImage()); withCreateContainerCmdModifier(it -> it.withEntrypoint("/bin/sh")); withCreateContainerCmdModifier(it -> it.withName("testcontainers-socat-" + Base58.randomString(8))); }
public void startNode(String id, BrowserType browserType, String nodeName, String imageId, boolean record, String containerIp) { // Create node pullImageIfNecessary(imageId, true); log.debug("Creating container for browser '{}'", id); CreateContainerCmd createContainerCmd = getClient().createContainerCmd(imageId).withPrivileged(true).withCapAdd(SYS_ADMIN).withName(nodeName); mountDefaultFolders(createContainerCmd); mountFiles(createContainerCmd); createContainerCmd.withNetworkMode("none"); Map<String, String> labels = new HashMap<>(); labels.put("KurentoDnat", "true"); labels.put("Transport", getProperty(TEST_SELENIUM_TRANSPORT)); labels.put("IpAddress", containerIp); createContainerCmd.withLabels(labels); createContainerCmd.exec(); log.debug("Container {} started...", nodeName); // Start node if stopped startContainer(nodeName); startRecordingIfNeeded(id, nodeName, record); logMounts(nodeName); logNetworks(nodeName); }
@Override protected CreateContainerCmd dockerCommand() { return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag()) .withNetworkMode("host") .withBinds(Bind.parse("/var/run/docker.sock:/tmp/docker.sock")) .withCmd("-internal", String.format("consul://%s:%d", consul.getIpAddress(), ConsulConfig.CONSUL_HTTP_PORT)) .withName(getName()); }
@Override protected CreateContainerCmd dockerCommand() { return DockerClientFactory.build() .createContainerCmd(config.getImageName() + ":" + config.getImageTag()) .withEnv(newEnvironment() .withValues(getMesosDNSEnvVars()) .createEnvironment()) .withCmd("-v=2", "-config=/etc/mesos-dns/config.json") .withExposedPorts(new ExposedPort(Integer.valueOf(DNS_PORT), InternetProtocol.UDP), new ExposedPort(Integer.valueOf(DNS_PORT), InternetProtocol.TCP)) .withName(getName()); }
public void startNode(String id, BrowserType browserType, String nodeName, String imageId, boolean record) { // Create node pullImageIfNecessary(imageId, true); log.debug("Creating container for browser '{}'", id); CreateContainerCmd createContainerCmd = getClient().createContainerCmd(imageId).withPrivileged(true).withCapAdd(SYS_ADMIN).withName(nodeName); mountDefaultFolders(createContainerCmd); mountFiles(createContainerCmd); if (isRunningInContainer()) { createContainerCmd.withNetworkMode("bridge"); } createContainerCmd.exec(); log.debug("Container {} started...", nodeName); // Start node if stopped startContainer(nodeName); startRecordingIfNeeded(id, nodeName, record); logMounts(nodeName); logNetworks(nodeName); listFolderInContainer(nodeName, KurentoTest.getTestFilesDiskPath()); }
@SuppressWarnings("resource") private DockerRabbitMQ(Optional<String> hostNamePrefix, Optional<String> clusterIdentity, Optional<String> erlangCookie, Optional<Network> net) { this.hostNameSuffix = clusterIdentity.orElse(UUID.randomUUID().toString()); this.rabbitHostName = hostName(hostNamePrefix); this.container = new GenericContainer<>(Images.RABBITMQ) .withCreateContainerCmdModifier(cmd -> cmd.withName(this.rabbitHostName)) .withCreateContainerCmdModifier(cmd -> cmd.withHostName(this.rabbitHostName)) .withExposedPorts(DEFAULT_RABBITMQ_PORT, DEFAULT_RABBITMQ_ADMIN_PORT) .waitingFor(waitStrategy()) .withLogConsumer(frame -> LOGGER.debug(frame.getUtf8String())) .withCreateContainerCmdModifier(cmd -> cmd.getHostConfig() .withTmpFs(ImmutableMap.of("/var/lib/rabbitmq/mnesia", "rw,noexec,nosuid,size=100m"))); net.ifPresent(this.container::withNetwork); erlangCookie.ifPresent(cookie -> this.container.withEnv(RABBITMQ_ERLANG_COOKIE, cookie)); this.nodeName = DEFAULT_RABBIT_NODE_NAME_PREFIX + "@" + this.rabbitHostName; this.container.withEnv(RABBITMQ_NODENAME, this.nodeName); }
public void startNode(String id, BrowserType browserType, String nodeName, String imageId, boolean record) { // Create node pullImageIfNecessary(imageId, true); log.debug("Creating container for browser '{}'", id); CreateContainerCmd createContainerCmd = getClient().createContainerCmd(imageId).withPrivileged(true).withCapAdd(SYS_ADMIN).withName(nodeName); mountDefaultFolders(createContainerCmd); mountFiles(createContainerCmd); if (isRunningInContainer()) { createContainerCmd.withNetworkMode("bridge"); } createContainerCmd.exec(); log.debug("Container {} started...", nodeName); // Start node if stopped startContainer(nodeName); startRecordingIfNeeded(id, nodeName, record); logMounts(nodeName); logNetworks(nodeName); listFolderInContainer(nodeName, KurentoTest.getTestFilesDiskPath()); }
@Override protected CreateContainerCmd dockerCommand() { int port = getServicePort(); ExposedPort exposedPort = ExposedPort.tcp(port); Ports portBindings = new Ports(); if (getCluster().isMapPortsToHost()) { portBindings.bind(exposedPort, Ports.Binding.bindPort(port)); } return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag()) .withName(getName()) .withExposedPorts(new ExposedPort(ZooKeeperConfig.DEFAULT_ZOOKEEPER_PORT), new ExposedPort(2888), new ExposedPort(3888)) .withPortBindings(portBindings); }
@Override protected CreateContainerCmd dockerCommand() { ExposedPort exposedPort = ExposedPort.tcp(MARATHON_PORT); Ports portBindings = new Ports(); if (getCluster().isMapPortsToHost()) { portBindings.bind(exposedPort, Ports.Binding.bindPort(MARATHON_PORT)); } return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag()) .withName(getName()) .withExtraHosts("minimesos-zookeeper:" + this.zooKeeper.getIpAddress()) .withCmd(CollectionsUtils.splitCmd(config.getCmd())) .withExposedPorts(exposedPort) .withPortBindings(portBindings); }
@Override protected CreateContainerCmd dockerCommand() { int port = getServicePort(); ExposedPort exposedPort = ExposedPort.tcp(port); Ports portBindings = new Ports(); if (getCluster().isMapPortsToHost()) { portBindings.bind(exposedPort, Ports.Binding.bindPort(port)); } ExposedPort consulHTTPPort = ExposedPort.tcp(ConsulConfig.CONSUL_HTTP_PORT); ExposedPort consulDNSPort = ExposedPort.udp(ConsulConfig.CONSUL_DNS_PORT); return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag()) .withName(getName()) .withCmd("agent", "-server", "-bootstrap", "-client", "0.0.0.0") .withExposedPorts(consulHTTPPort, consulDNSPort) .withPortBindings(portBindings); }
private GenericContainer<?> getContainerHBase(String image, Network network, String logWaitRegex, int logWaitTimes, boolean matchExposedPort) { FixedHostPortGenericContainer<?> container = new FixedHostPortGenericContainer<>(image); container.withNetwork(network); container.withNetworkAliases("hbase_alias"); container.withFixedExposedPort(HBASE_ZK_PORT, HBASE_ZK_PORT); container.withFixedExposedPort(16201, HBASE_REGION_SERVER_PORT); container.withFixedExposedPort(16000, HBASE_MASTER_PORT); container.withCreateContainerCmdModifier(cmd -> cmd.withName(HBASE_CONTAINER_NAME)); container.withCreateContainerCmdModifier(cmd -> cmd.withHostName(HBASE_HOST_NAME)); return container; }
@Override protected CreateContainerCmd dockerCommand() { int port = getServicePort(); ExposedPort exposedPort = ExposedPort.tcp(port); Ports portBindings = new Ports(); if (getCluster().isMapPortsToHost()) { portBindings.bind(exposedPort, Ports.Binding.bindPort(port)); } CreateContainerCmd cmd = DockerClientFactory.build().createContainerCmd(getImageName() + ":" + getImageTag()) .withName(getName()) .withExposedPorts(new ExposedPort(getServicePort())) .withEnv(newEnvironment() .withValues(getMesosMasterEnvVars()) .withValues(getSharedEnvVars()) .createEnvironment()) .withPortBindings(portBindings); MesosDns mesosDns = getCluster().getMesosDns(); if (mesosDns != null) { cmd.withDns(mesosDns.getIpAddress()); } return cmd; }