Search in sources :

Example 1 with Mount

use of com.github.dockerjava.api.model.Mount in project infinispan by infinispan.

the class ContainerInfinispanServerDriver method createContainer.

private GenericContainer<?> createContainer(int i, Consumer<OutputFrame>... logConsumers) {
    if (this.volumes[i] == null) {
        String volumeName = Util.threadLocalRandomUUID().toString();
        DockerClientFactory.instance().client().createVolumeCmd().withName(volumeName).exec();
        this.volumes[i] = volumeName;
    }
    GenericContainer<?> container = new GenericContainer<>(image).withCreateContainerCmdModifier(cmd -> {
        cmd.getHostConfig().withMounts(Arrays.asList(new Mount().withSource(this.volumes[i]).withTarget(serverPath()).withType(MountType.VOLUME)));
        if (IMAGE_MEMORY != null) {
            cmd.getHostConfig().withMemory(IMAGE_MEMORY);
        }
        if (IMAGE_MEMORY_SWAP != null) {
            cmd.getHostConfig().withMemorySwap(IMAGE_MEMORY_SWAP);
        }
    });
    String debug = configuration.properties().getProperty(TestSystemPropertyNames.INFINISPAN_TEST_SERVER_CONTAINER_DEBUG);
    if (debug != null && Integer.parseInt(debug) == i) {
        String option = debugJvmOption();
        container.withEnv("JAVA_OPTS", option);
        log.infof("Container debug enabled with options '%s'%n", option);
    }
    // Process any enhancers
    container.withLogConsumer(new JBossLoggingConsumer(LogFactory.getLogger(name)).withPrefix(Integer.toString(i)));
    for (Consumer<OutputFrame> consumer : logConsumers) container.withLogConsumer(consumer);
    log.infof("Starting container %d", i);
    container.start();
    containers[i] = new InfinispanGenericContainer(container);
    log.infof("Started container %d", i);
    return container;
}
Also used : Mount(com.github.dockerjava.api.model.Mount) OutputFrame(org.testcontainers.containers.output.OutputFrame)

Example 2 with Mount

use of com.github.dockerjava.api.model.Mount in project webdrivermanager by bonigarcia.

the class DockerService method startBrowserContainer.

public DockerContainer startBrowserContainer(String dockerImage, String cacheKey, String browserVersion, boolean androidEnabled) {
    dockerImage = getPrefixedDockerImage(dockerImage);
    // pull image
    pullImageIfNecessary(cacheKey, dockerImage, browserVersion);
    // exposed ports
    List<String> exposedPorts = new ArrayList<>();
    String dockerBrowserPort = String.valueOf(config.getDockerBrowserPort());
    exposedPorts.add(dockerBrowserPort);
    // shmSize
    long shmSize = config.getDockerMemSizeBytes(config.getDockerShmSize());
    // mounts
    List<Mount> mounts = new ArrayList<>();
    Mount tmpfsMount = new Mount().withTmpfsOptions(new TmpfsOptions().withSizeBytes(config.getDockerMemSizeBytes(config.getDockerTmpfsSize()))).withTarget(config.getDockerTmpfsMount());
    mounts.add(tmpfsMount);
    // binds
    List<String> binds = new ArrayList<>();
    String dockerVolumes = config.getDockerVolumes();
    if (!isNullOrEmpty(dockerVolumes)) {
        List<String> volumeList = Arrays.asList(dockerVolumes.split(","));
        log.trace("Using custom volumes: {}", volumeList);
        binds.addAll(volumeList);
    }
    // envs
    List<String> envs = new ArrayList<>();
    envs.add("TZ=" + config.getDockerTimezone());
    envs.add("LANG=" + config.getDockerLang());
    envs.add("SCREEN_RESOLUTION=" + config.getDockerScreenResolution());
    envs.addAll(config.getDockerEnvVariables());
    String dockerVncPort = String.valueOf(config.getDockerVncPort());
    if (config.isDockerEnabledVnc()) {
        envs.add("ENABLE_VNC=true");
        exposedPorts.add(dockerVncPort);
    }
    if (androidEnabled) {
        envs.add("QTWEBENGINE_DISABLE_SANDBOX=1");
    }
    if (isChromeAllowedOrigins(dockerImage, browserVersion)) {
        envs.add("DRIVER_ARGS=--whitelisted-ips= --allowed-origins=*");
    }
    // network
    String network = config.getDockerNetwork();
    // extra hosts
    List<String> extraHosts = config.getDockerExtraHosts();
    // builder
    DockerBuilder dockerBuilder = DockerContainer.dockerBuilder(dockerImage).exposedPorts(exposedPorts).network(network).mounts(mounts).binds(binds).shmSize(shmSize).envs(envs).extraHosts(extraHosts).sysadmin();
    if (androidEnabled) {
        dockerBuilder = dockerBuilder.privileged();
    }
    DockerContainer browserContainer = dockerBuilder.build();
    String containerId = startContainer(browserContainer);
    browserContainer.setContainerId(containerId);
    String browserHost = getHost(containerId, network);
    String browserPort = getBindPort(containerId, dockerBrowserPort + "/tcp");
    String browserUrlFormat = "http://%s:%s/";
    if (dockerImage.contains("firefox") || androidEnabled) {
        browserUrlFormat += "wd/hub";
    }
    String browserUrl = format(browserUrlFormat, browserHost, browserPort);
    browserContainer.setContainerUrl(browserUrl);
    String gateway = getGateway(containerId, network);
    browserContainer.setGateway(gateway);
    String address = getAddress(containerId, network);
    browserContainer.setAddress(address);
    log.trace("Browser remote URL {}", browserUrl);
    if (config.isDockerEnabledVnc()) {
        String vncPort = getBindPort(containerId, dockerVncPort + "/tcp");
        browserContainer.setVncPort(vncPort);
        String vncAddress = format("vnc://%s:%s/", getDefaultHost(), vncPort);
        log.debug("VNC server URL: {}", vncAddress);
        browserContainer.setVncAddress(vncAddress);
    }
    return browserContainer;
}
Also used : DockerBuilder(io.github.bonigarcia.wdm.docker.DockerContainer.DockerBuilder) ArrayList(java.util.ArrayList) Mount(com.github.dockerjava.api.model.Mount) TmpfsOptions(com.github.dockerjava.api.model.TmpfsOptions)

Aggregations

Mount (com.github.dockerjava.api.model.Mount)2 TmpfsOptions (com.github.dockerjava.api.model.TmpfsOptions)1 DockerBuilder (io.github.bonigarcia.wdm.docker.DockerContainer.DockerBuilder)1 ArrayList (java.util.ArrayList)1 OutputFrame (org.testcontainers.containers.output.OutputFrame)1