Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import java.util.Map;

import com.github.dockerjava.api.exception.NotFoundException;
import com.github.dockerjava.api.model.ExposedPorts;
import com.github.dockerjava.api.model.Volumes;
Expand All @@ -29,6 +31,9 @@ public interface CommitCmd extends SyncDockerCmd<String> {
@CheckForNull
String getHostname();

@CheckForNull
Map<String, String> getLabels();

@CheckForNull
Integer getMemory();

Expand Down Expand Up @@ -88,6 +93,8 @@ public interface CommitCmd extends SyncDockerCmd<String> {

CommitCmd withHostname(String hostname);

CommitCmd withLabels(Map<String, String> labels);

CommitCmd withMemory(Integer memory);

CommitCmd withMemorySwap(Integer memorySwap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.dockerjava.api.command.CommitCmd;
import com.github.dockerjava.api.exception.NotFoundException;
Expand Down Expand Up @@ -43,6 +45,9 @@ public class CommitCmdImpl extends AbstrDockerCmd<CommitCmd, String> implements
@JsonProperty("Hostname")
private String hostname;

@JsonProperty("Labels")
private Map<String, String> labels;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since what API version it apperead? Does tests pass for all travis versions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like.


@JsonProperty("Memory")
private Integer memory;

Expand Down Expand Up @@ -189,6 +194,17 @@ public CommitCmdImpl withEnv(String... env) {
return this;
}

@Override
public Map<String, String> getLabels() {
return labels;
}

@Override
public CommitCmdImpl withLabels(Map<String, String> labels) {
this.labels = labels;
return this;
}

@Override
public ExposedPorts getExposedPorts() {
return exposedPorts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import static org.testinfected.hamcrest.jpa.HasFieldWithValue.hasField;

import java.lang.reflect.Method;
import java.util.Map;

import com.google.common.collect.ImmutableMap;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
Expand Down Expand Up @@ -54,7 +56,7 @@ public void commit() throws DockerException {
assertThat(container.getId(), not(isEmptyString()));
dockerClient.startContainerCmd(container.getId()).exec();

LOG.info("Commiting container: {}", container.toString());
LOG.info("Committing container: {}", container.toString());
String imageId = dockerClient.commitCmd(container.getId()).exec();

InspectImageResponse inspectImageResponse = dockerClient.inspectImageCmd(imageId).exec();
Expand All @@ -68,6 +70,26 @@ public void commit() throws DockerException {
assertThat(inspectImageResponse.getParent(), equalTo(busyboxImg.getId()));
}

@Test
public void commitWithLabels() throws DockerException {

CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("touch", "/test").exec();

LOG.info("Created container: {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));
dockerClient.startContainerCmd(container.getId()).exec();

LOG.info("Committing container: {}", container.toString());
Map<String, String> labels = ImmutableMap.of("label1", "abc", "label2", "123");
String imageId = dockerClient.commitCmd(container.getId()).withLabels(labels).exec();

InspectImageResponse inspectImageResponse = dockerClient.inspectImageCmd(imageId).exec();
LOG.info("Image Inspect: {}", inspectImageResponse.toString());
Map<String, String> responseLabels = inspectImageResponse.getContainerConfig().getLabels();
assertThat(responseLabels.get("label1"), equalTo("abc"));
assertThat(responseLabels.get("label2"), equalTo("123"));
}

@Test(expectedExceptions = NotFoundException.class)
public void commitNonExistingContainer() throws DockerException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import static org.testinfected.hamcrest.jpa.HasFieldWithValue.hasField;

import java.lang.reflect.Method;
import java.util.Map;

import com.google.common.collect.ImmutableMap;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
Expand Down Expand Up @@ -54,7 +56,7 @@ public void commit() throws DockerException {
assertThat(container.getId(), not(isEmptyString()));
dockerClient.startContainerCmd(container.getId()).exec();

LOG.info("Commiting container: {}", container.toString());
LOG.info("Committing container: {}", container.toString());
String imageId = dockerClient.commitCmd(container.getId()).exec();

InspectImageResponse inspectImageResponse = dockerClient.inspectImageCmd(imageId).exec();
Expand All @@ -68,6 +70,26 @@ public void commit() throws DockerException {
assertThat(inspectImageResponse.getParent(), equalTo(busyboxImg.getId()));
}

@Test
public void commitWithLabels() throws DockerException {

CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("touch", "/test").exec();

LOG.info("Created container: {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));
dockerClient.startContainerCmd(container.getId()).exec();

LOG.info("Committing container: {}", container.toString());
Map<String, String> labels = ImmutableMap.of("label1", "abc", "label2", "123");
String imageId = dockerClient.commitCmd(container.getId()).withLabels(labels).exec();

InspectImageResponse inspectImageResponse = dockerClient.inspectImageCmd(imageId).exec();
LOG.info("Image Inspect: {}", inspectImageResponse.toString());
Map<String, String> responseLabels = inspectImageResponse.getContainerConfig().getLabels();
assertThat(responseLabels.get("label1"), equalTo("abc"));
assertThat(responseLabels.get("label2"), equalTo("123"));
}

@Test(expectedExceptions = NotFoundException.class)
public void commitNonExistingContainer() throws DockerException {

Expand Down