Search in sources :

Example 1 with DockerBuilder

use of io.elastest.epm.client.DockerContainer.DockerBuilder in project elastest-torm by elastest.

the class DockerComposeService method setup.

public void setup() throws IOException, InterruptedException {
    // 1. Start docker-compose-ui container
    dockerComposeUiContainerName = dockerService.generateContainerName(dockerComposeUiPrefix);
    int dockerComposeBindPort = dockerService.findRandomOpenPort();
    Binding bindNoVncPort = bindPort(dockerComposeBindPort);
    ExposedPort exposedNoVncPort = tcp(dockerComposeUiPort);
    String dockerComposeServiceUrl = "http://" + dockerService.getDockerServerIp() + ":" + dockerComposeBindPort;
    log.debug("Starting docker-compose-ui container: {}", dockerComposeUiContainerName);
    List<PortBinding> portBindings = asList(new PortBinding(bindNoVncPort, exposedNoVncPort));
    Volume volume = new Volume(dockerDefaultSocket);
    List<Volume> volumes = asList(volume);
    List<Bind> binds = asList(new Bind(dockerDefaultSocket, volume));
    DockerBuilder dockerBuilder = dockerBuilder(dockerComposeUiImageId, dockerComposeUiContainerName).portBindings(portBindings).volumes(volumes).binds(binds);
    dockerService.startAndWaitContainer(dockerBuilder.build());
    // 2. Create Retrofit object to call docker-compose-ui REST API
    OkHttpClient okHttpClient = new OkHttpClient.Builder().readTimeout(dockerComposeTimeout, SECONDS).connectTimeout(dockerComposeTimeout, SECONDS).build();
    Retrofit retrofit = new Retrofit.Builder().client(okHttpClient).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).addConverterFactory(GsonConverterFactory.create()).baseUrl(dockerComposeServiceUrl).build();
    dockerComposeApi = retrofit.create(DockerComposeApi.class);
    log.debug("docker-compose-ui up and running on URL: {}", dockerComposeServiceUrl);
    // 3.Delete default example projects
    dockerService.waitForHostIsReachable(dockerComposeServiceUrl);
    String[] defaultProjects = { "env-demo", "hello-node", "node-redis", "volumes-demo", "volumes-relative-paths" };
    removeProjects(defaultProjects);
}
Also used : PortBinding(com.github.dockerjava.api.model.PortBinding) Binding(com.github.dockerjava.api.model.Ports.Binding) DockerBuilder(io.elastest.epm.client.DockerContainer.DockerBuilder) Bind(com.github.dockerjava.api.model.Bind) OkHttpClient(okhttp3.OkHttpClient) DockerComposeApi(io.elastest.epm.client.DockerComposeApi) ExposedPort(com.github.dockerjava.api.model.ExposedPort) Retrofit(retrofit2.Retrofit) PortBinding(com.github.dockerjava.api.model.PortBinding) Volume(com.github.dockerjava.api.model.Volume)

Example 2 with DockerBuilder

use of io.elastest.epm.client.DockerContainer.DockerBuilder in project elastest-torm by elastest.

the class PcapService method startPcap.

public Boolean startPcap(String execId) {
    String containerName = containerPrefix + execId;
    if (!containersList.containsKey(containerName)) {
        DockerBuilder dockerBuilder = DockerContainer.dockerBuilder(dockpcapImage, containerName).network(dockpcapNetworkPrefix + execId);
        DockerContainer dockerContainer = dockerBuilder.build();
        containersList.put(containerName, dockerContainer);
        try {
            dockerService.startAndWaitContainer(dockerContainer);
            return true;
        } catch (InterruptedException e) {
            log.error("Pcap not started {}", execId, e);
        }
    }
    return false;
}
Also used : DockerBuilder(io.elastest.epm.client.DockerContainer.DockerBuilder) DockerContainer(io.elastest.epm.client.DockerContainer)

Example 3 with DockerBuilder

use of io.elastest.epm.client.DockerContainer.DockerBuilder in project elastest-torm by elastest.

the class DockerIntegrationTest method testDocker.

@Test
@DisplayName("Ask for Chrome to Docker")
void testDocker() throws Exception {
    // Test data (input)
    String imageId = "selenium/standalone-chrome-debug:3.5.3";
    log.debug("Starting Hub with image {}", imageId);
    String containerName = dockerService.generateContainerName("hub-for-test-");
    Binding bindPort = bindPort(dockerService.findRandomOpenPort());
    ExposedPort exposedPort = tcp(4444);
    Binding bindHubVncPort = bindPort(dockerService.findRandomOpenPort());
    ExposedPort exposedHubVncPort = tcp(5900);
    List<PortBinding> portBindings = asList(new PortBinding(bindPort, exposedPort), new PortBinding(bindHubVncPort, exposedHubVncPort));
    DockerBuilder dockerBuilder = dockerBuilder(imageId, containerName).portBindings(portBindings);
    dockerService.startAndWaitContainer(dockerBuilder.build());
    // Assertions
    assertTrue(dockerService.existsContainer(containerName));
    // Tear down
    log.debug("Stoping Hub");
    dockerService.stopAndRemoveContainer(containerName);
}
Also used : PortBinding(com.github.dockerjava.api.model.PortBinding) Binding(com.github.dockerjava.api.model.Ports.Binding) ExposedPort(com.github.dockerjava.api.model.ExposedPort) DockerBuilder(io.elastest.epm.client.DockerContainer.DockerBuilder) PortBinding(com.github.dockerjava.api.model.PortBinding) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

DockerBuilder (io.elastest.epm.client.DockerContainer.DockerBuilder)3 ExposedPort (com.github.dockerjava.api.model.ExposedPort)2 PortBinding (com.github.dockerjava.api.model.PortBinding)2 Binding (com.github.dockerjava.api.model.Ports.Binding)2 Bind (com.github.dockerjava.api.model.Bind)1 Volume (com.github.dockerjava.api.model.Volume)1 DockerComposeApi (io.elastest.epm.client.DockerComposeApi)1 DockerContainer (io.elastest.epm.client.DockerContainer)1 OkHttpClient (okhttp3.OkHttpClient)1 DisplayName (org.junit.jupiter.api.DisplayName)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Retrofit (retrofit2.Retrofit)1