Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default labels to images created with ImageFromDockerfile #2809

Merged
merged 2 commits into from May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
@@ -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);
}

}