File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
main/java/org/testcontainers/images/builder
test/java/org/testcontainers/images/builder Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,12 @@ public void onNext(BuildResponseItem item) {
107107
108108 BuildImageCmd buildImageCmd = dockerClient .buildImageCmd (in );
109109 configure (buildImageCmd );
110+ Map <String , String > labels = new HashMap <>();
111+ if (buildImageCmd .getLabels () != null ) {
112+ labels .putAll (buildImageCmd .getLabels ());
113+ }
114+ labels .putAll (DockerClientFactory .DEFAULT_LABELS );
115+ buildImageCmd .withLabels (labels );
110116
111117 prePullDependencyImages (dependencyImageNames );
112118
Original file line number Diff line number Diff line change 1+ package org .testcontainers .images .builder ;
2+
3+ import com .github .dockerjava .api .DockerClient ;
4+ import com .github .dockerjava .api .command .InspectImageResponse ;
5+ import org .junit .Test ;
6+ import org .testcontainers .DockerClientFactory ;
7+
8+ import static org .assertj .core .api .Assertions .assertThat ;
9+
10+ public class ImageFromDockerfileTest {
11+
12+ @ Test
13+ public void shouldAddDefaultLabels () {
14+ ImageFromDockerfile image = new ImageFromDockerfile ()
15+ .withDockerfileFromBuilder (it -> it .from ("scratch" ));
16+
17+ String imageId = image .resolve ();
18+
19+ DockerClient dockerClient = DockerClientFactory .instance ().client ();
20+
21+ InspectImageResponse inspectImageResponse = dockerClient .inspectImageCmd (imageId ).exec ();
22+
23+ assertThat (inspectImageResponse .getConfig ().getLabels ())
24+ .containsAllEntriesOf (DockerClientFactory .DEFAULT_LABELS );
25+ }
26+
27+ }
You can’t perform that action at this time.
0 commit comments