Skip to content

Commit 143b133

Browse files
Reimplement cleanup logic
Co-Authored-By: Johannes Rabauer <[email protected]>
1 parent ba7e0cd commit 143b133

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

testcontainers-advanced-imagebuilder/src/main/java/software/xdev/testcontainers/imagebuilder/AdvancedImageFromDockerFile.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,6 @@ protected String resolve()
149149

150150
try
151151
{
152-
if(this.deleteOnExit)
153-
{
154-
this.log().info("Registering image for cleanup when tests are finished");
155-
ResourceReaper.instance().registerImageForCleanup(this.dockerImageName);
156-
}
157-
158152
// We have to use pipes to avoid high memory consumption since users might want to build huge images
159153
final PipedInputStream in = new PipedInputStream();
160154
final PipedOutputStream out = new PipedOutputStream(in);
@@ -168,6 +162,7 @@ protected String resolve()
168162
{
169163
labels.putAll(buildImageCmd.getLabels());
170164
}
165+
this.deleteImageOnExitIfRequired(labels);
171166
labels.putAll(DockerClientFactory.DEFAULT_LABELS);
172167
buildImageCmd.withLabels(labels);
173168

@@ -209,6 +204,18 @@ protected String resolve()
209204
}
210205
}
211206

207+
@SuppressWarnings("deprecation") // There is no alternative and it's also used in the default implementation
208+
protected void deleteImageOnExitIfRequired(final Map<String, String> labels)
209+
{
210+
if(!this.deleteOnExit)
211+
{
212+
return;
213+
}
214+
215+
this.log().debug("Registering image for cleanup when finished");
216+
labels.putAll(ResourceReaper.instance().getLabels());
217+
}
218+
212219
protected long getBytesToDockerDaemon(final PipedOutputStream out) throws IOException
213220
{
214221
long bytesToDockerDaemon = 0L;

0 commit comments

Comments
 (0)