Search in sources :

Example 1 with LogConfig

use of com.spotify.docker.client.messages.LogConfig in project docker-client by spotify.

the class DefaultDockerClientTest method testLogDriver.

@Test
public void testLogDriver() throws Exception {
    requireDockerApiVersionAtLeast("1.21", "Container Creation with HostConfig.LogConfig");
    sut.pull(BUSYBOX_LATEST);
    final String name = randomName();
    final Map<String, String> logOptions = new HashMap<>();
    logOptions.put("max-size", "10k");
    logOptions.put("max-file", "2");
    logOptions.put("labels", name);
    final LogConfig logConfig = LogConfig.create("json-file", logOptions);
    assertThat(logConfig.logType(), equalTo("json-file"));
    assertThat(logConfig.logOptions(), equalTo(logOptions));
    final HostConfig expected = HostConfig.builder().logConfig(logConfig).build();
    final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).hostConfig(expected).build();
    final ContainerCreation creation = sut.createContainer(config, name);
    final String id = creation.id();
    sut.startContainer(id);
    final HostConfig actual = sut.inspectContainer(id).hostConfig();
    assertThat(actual.logConfig(), equalTo(expected.logConfig()));
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) ContainerCreation(com.spotify.docker.client.messages.ContainerCreation) HashMap(java.util.HashMap) HostConfig(com.spotify.docker.client.messages.HostConfig) Long.toHexString(java.lang.Long.toHexString) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) LogConfig(com.spotify.docker.client.messages.LogConfig) Test(org.junit.Test)

Example 2 with LogConfig

use of com.spotify.docker.client.messages.LogConfig in project helios by spotify.

the class SyslogRedirectingContainerDecoratorTest method testWithDockerVersionPost1_9.

@Test
public void testWithDockerVersionPost1_9() {
    final Optional<String> dockerVersion = Optional.of("1.12.1");
    final SyslogRedirectingContainerDecorator decorator = new SyslogRedirectingContainerDecorator(SYSLOG_HOST_PORT);
    final HostConfig.Builder hostBuilder = HostConfig.builder();
    decorator.decorateHostConfig(JOB, dockerVersion, hostBuilder);
    final ContainerConfig.Builder containerBuilder = ContainerConfig.builder();
    decorator.decorateContainerConfig(JOB, imageInfo, dockerVersion, containerBuilder);
    final ContainerConfig containerConfig = containerBuilder.build();
    assertThat(containerConfig.entrypoint(), not(hasItem("/helios/syslog-redirector")));
    final HostConfig hostConfig = hostBuilder.build();
    final LogConfig logConfig = hostConfig.logConfig();
    assertEquals("syslog", logConfig.logType());
    assertEquals(JOB.getId().toString(), logConfig.logOptions().get("tag"));
    assertEquals("udp://" + SYSLOG_HOST_PORT, logConfig.logOptions().get("syslog-address"));
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) HostConfig(com.spotify.docker.client.messages.HostConfig) LogConfig(com.spotify.docker.client.messages.LogConfig) Test(org.junit.Test)

Aggregations

ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)2 HostConfig (com.spotify.docker.client.messages.HostConfig)2 LogConfig (com.spotify.docker.client.messages.LogConfig)2 Test (org.junit.Test)2 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)1 Long.toHexString (java.lang.Long.toHexString)1 HashMap (java.util.HashMap)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)1