Skip to content

Commit

Permalink
Add default labels to images created with ImageFromDockerfile (#2809)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsideup authored May 29, 2020
1 parent 892d84d commit 6ac18b2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public void onNext(BuildResponseItem item) {

BuildImageCmd buildImageCmd = dockerClient.buildImageCmd(in);
configure(buildImageCmd);
Map<String, String> labels = new HashMap<>();
if (buildImageCmd.getLabels() != null) {
labels.putAll(buildImageCmd.getLabels());
}
labels.putAll(DockerClientFactory.DEFAULT_LABELS);
buildImageCmd.withLabels(labels);

prePullDependencyImages(dependencyImageNames);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.testcontainers.images.builder;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.InspectImageResponse;
import org.junit.Test;
import org.testcontainers.DockerClientFactory;

import static org.assertj.core.api.Assertions.assertThat;

public class ImageFromDockerfileTest {

@Test
public void shouldAddDefaultLabels() {
ImageFromDockerfile image = new ImageFromDockerfile()
.withDockerfileFromBuilder(it -> it.from("scratch"));

String imageId = image.resolve();

DockerClient dockerClient = DockerClientFactory.instance().client();

InspectImageResponse inspectImageResponse = dockerClient.inspectImageCmd(imageId).exec();

assertThat(inspectImageResponse.getConfig().getLabels())
.containsAllEntriesOf(DockerClientFactory.DEFAULT_LABELS);
}

}

0 comments on commit 6ac18b2

Please sign in to comment.