Search in sources :

Example 1 with Binding

use of com.github.dockerjava.api.model.Ports.Binding 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 Binding

use of com.github.dockerjava.api.model.Ports.Binding in project elastest-torm by elastest.

the class DockerUnitTest method testEmptyContainer.

@Test
@DisplayName("Try to start a container with invalid input")
void testEmptyContainer() {
    assertThrows(Exception.class, () -> {
        Binding bindPort = bindPort(0);
        ExposedPort exposedPort = tcp(0);
        List<PortBinding> portBindings = asList(new PortBinding(bindPort, exposedPort));
        dockerService.startAndWaitContainer(dockerBuilder("", "").portBindings(portBindings).build());
    });
}
Also used : PortBinding(com.github.dockerjava.api.model.PortBinding) Binding(com.github.dockerjava.api.model.Ports.Binding) ExposedPort(com.github.dockerjava.api.model.ExposedPort) PortBinding(com.github.dockerjava.api.model.PortBinding) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with Binding

use of com.github.dockerjava.api.model.Ports.Binding 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

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