use of com.spotify.docker.client.messages.HostConfig in project docker-client by spotify.
the class DefaultDockerClientTest method testExtraHosts.
@Test
public void testExtraHosts() throws Exception {
requireDockerApiVersionAtLeast("1.15", "Container Creation with HostConfig.ExtraHosts");
sut.pull(BUSYBOX_LATEST);
final HostConfig expected = HostConfig.builder().extraHosts("extrahost:1.2.3.4").build();
final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).hostConfig(expected).cmd("sh", "-c", "cat /etc/hosts | grep extrahost").build();
final String name = randomName();
final ContainerCreation creation = sut.createContainer(config, name);
final String id = creation.id();
sut.startContainer(id);
final HostConfig actual = sut.inspectContainer(id).hostConfig();
assertThat(actual.extraHosts(), equalTo(expected.extraHosts()));
final String logs;
try (LogStream stream = sut.logs(id, stdout(), stderr())) {
logs = stream.readFully();
}
assertThat(logs, containsString("1.2.3.4"));
}
use of com.spotify.docker.client.messages.HostConfig 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()));
}
use of com.spotify.docker.client.messages.HostConfig in project docker-client by spotify.
the class DefaultDockerClientTest method testContainerWithBlkioOptions.
@Test
public void testContainerWithBlkioOptions() throws Exception {
requireDockerApiVersionAtLeast("1.19", "Container creation with blkio options");
sut.pull(BUSYBOX_LATEST);
final HostConfig.Builder hostConfigBuilder = HostConfig.builder();
if (dockerApiVersionAtLeast("1.19")) {
hostConfigBuilder.blkioWeight(300);
}
if (dockerApiVersionAtLeast("1.22")) {
// TODO (dxia) Some kernels don't support blkio weight. How detect to skip this check?
// hostConfigBuilder.blkioWeightDevice(ImmutableList.of(
// HostConfig.BlkioWeightDevice.builder().path("/dev/random").weight(500).build(),
// HostConfig.BlkioWeightDevice.builder().path("/dev/urandom").weight(200).build()
// ));
final List<HostConfig.BlkioDeviceRate> deviceRates = ImmutableList.of(HostConfig.BlkioDeviceRate.builder().path("/dev/loop0").rate(1024).build());
hostConfigBuilder.blkioDeviceReadBps(deviceRates);
hostConfigBuilder.blkioDeviceWriteBps(deviceRates);
hostConfigBuilder.blkioDeviceReadIOps(deviceRates);
hostConfigBuilder.blkioDeviceWriteIOps(deviceRates);
}
final HostConfig expected = hostConfigBuilder.build();
final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).hostConfig(expected).build();
final String name = randomName();
final ContainerCreation creation = sut.createContainer(config, name);
final String id = creation.id();
sut.startContainer(id);
final HostConfig actual = sut.inspectContainer(id).hostConfig();
if (dockerApiVersionAtLeast("1.19")) {
// TODO (dxia) Some kernels don't support blkio weight. How detect to skip this check?
// assertThat(actual.blkioWeight(), equalTo(expected.blkioWeight()));
}
if (dockerApiVersionAtLeast("1.22")) {
// TODO (dxia) Some kernels don't support blkio weight device. How detect to skip this check?
// assertThat(actual.blkioWeightDevice(), equalTo(expected.blkioWeightDevice()));
assertThat(actual.blkioDeviceReadBps(), equalTo(expected.blkioDeviceReadBps()));
assertThat(actual.blkioDeviceWriteBps(), equalTo(expected.blkioDeviceWriteBps()));
assertThat(actual.blkioDeviceReadIOps(), equalTo(expected.blkioDeviceReadIOps()));
assertThat(actual.blkioDeviceWriteBps(), equalTo(expected.blkioDeviceWriteBps()));
}
}
use of com.spotify.docker.client.messages.HostConfig in project repairnator by Spirals-Team.
the class RunnablePipelineContainer method run.
@Override
public void run() {
String containerId = null;
DockerClient docker = Launcher.docker;
try {
LOGGER.info("Start to run check container for branch " + branchName);
String containerName = "checkbranch_" + branchName;
String humanPatchStr = "";
if (this.repairnatorConfig.isHumanPatch()) {
humanPatchStr = "--human-patch";
}
String[] envValues = new String[] { "BRANCH_NAME=" + this.branchName, "REPOSITORY=" + this.repairnatorConfig.getRepository(), "HUMAN_PATCH=" + humanPatchStr };
Map<String, String> labels = new HashMap<>();
labels.put("name", containerName);
HostConfig hostConfig = HostConfig.builder().appendBinds(this.repairnatorConfig.getOutputPath() + ":/tmp/result.txt").build();
ContainerConfig containerConfig = ContainerConfig.builder().image(imageId).env(envValues).hostname(Utils.getHostname()).hostConfig(hostConfig).labels(labels).build();
LOGGER.info("Create the container: " + containerName);
ContainerCreation container = docker.createContainer(containerConfig);
containerId = container.id();
LOGGER.info("Start the container: " + containerName + " (id: " + containerId + ")");
docker.startContainer(container.id());
ContainerExit exitStatus = docker.waitContainer(containerId);
LOGGER.info("The container has finished with status code: " + exitStatus.statusCode());
if (!this.repairnatorConfig.isSkipDelete() && exitStatus.statusCode() == 0) {
LOGGER.info("Container will be removed.");
docker.removeContainer(containerId);
}
LOGGER.info("TREATED Docker container : " + containerId);
} catch (InterruptedException e) {
LOGGER.error("Error while running the container for branch name " + branchName, e);
killDockerContainer(docker, containerId);
} catch (DockerException e) {
LOGGER.error("Error while creating or running the container for branch name " + branchName, e);
}
Launcher.submittedRunnablePipelineContainers.remove(this);
}
use of com.spotify.docker.client.messages.HostConfig in project helios by spotify.
the class BindVolumeContainerDecorator method decorateHostConfig.
@Override
public void decorateHostConfig(Job job, Optional<String> dockerVersion, HostConfig.Builder hostConfigBuilder) {
final List<String> b = Lists.newArrayList();
final HostConfig hostConfig = hostConfigBuilder.build();
if (hostConfig.binds() != null) {
b.addAll(hostConfig.binds());
}
b.addAll(this.binds);
hostConfigBuilder.binds(b);
}
Aggregations