Skip to content

Commit ff33a46

Browse files
authored
Merge pull request #5 from xdev-software/develop
Release
2 parents bf4fbd9 + 74d3f2d commit ff33a46

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 1.0.1
2+
* Minor improvements in cleanup behavior (backported from upstream)
3+
4+
# 1.0.0
5+
_Initial release_

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ See the [contributing guide](./CONTRIBUTING.md) for detailed instructions on how
2828

2929
## Dependencies and Licenses
3030
View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/testcontainers-advanced-imagebuilder/dependencies)
31+
32+
<sub>Disclaimer: This is not an official Testcontainers product and not associated</sub>

renovate.json5

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
{
22
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3-
"rebaseWhen": "behind-base-branch"
3+
"rebaseWhen": "behind-base-branch",
4+
"packageRules": [
5+
{
6+
"description": "Docker - Java LTS",
7+
"packagePattern": "^eclipse-temurin",
8+
"matchDatasources": [
9+
"docker"
10+
],
11+
"allowedVersions": "/^21\\-alpine$/"
12+
}
13+
]
414
}

testcontainers-advanced-imagebuilder-demo/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ARG mvncmd='clean package -pl "testcontainers-advanced-imagebuilder-dummy-app" -
2828

2929
RUN echo "Executing '$mvncmd'"
3030
RUN chmod +x ./mvnw \
31-
&& ./mvnw -B $mvncmd
31+
&& ./mvnw -B ${mvncmd}
3232

3333
# Stage 2: Build the executable image
3434
FROM eclipse-temurin:21-jre-alpine
@@ -40,8 +40,8 @@ ARG gid=1000
4040
ARG APP_DIR=/opt/dummy-app
4141

4242
# Create user + group + home
43-
RUN mkdir -p $APP_DIR \
44-
&& chown ${uid}:${gid} $APP_DIR \
43+
RUN mkdir -p ${APP_DIR} \
44+
&& chown ${uid}:${gid} ${APP_DIR} \
4545
&& addgroup -g ${gid} ${group} \
4646
&& adduser -h "$APP_DIR" -u ${uid} -G ${group} -s /bin/bash -D ${user}
4747

@@ -51,4 +51,4 @@ USER ${user}
5151

5252
COPY --from=build-env --chown=${user}:${group} build/testcontainers-advanced-imagebuilder-dummy-app/target/dummy-app.jar ${APP_DIR}/dummy-app.jar
5353

54-
CMD java $JAVA_OPTS -jar /opt/dummy-app/dummy-app.jar
54+
CMD java ${JAVA_OPTS} -jar /opt/dummy-app/dummy-app.jar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a dummy application that can be started as a container

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class AdvancedImageFromDockerFile
8585
StringsTrait<AdvancedImageFromDockerFile>,
8686
DockerfileTrait<AdvancedImageFromDockerFile>
8787
{
88-
protected static final Logger LOG = LoggerFactory.getLogger(AdvancedImageFromDockerFile.class);
88+
protected static final Logger LOGGER = LoggerFactory.getLogger(AdvancedImageFromDockerFile.class);
8989
protected final String dockerImageName;
9090

9191
protected final boolean deleteOnExit;
@@ -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;
@@ -406,7 +413,7 @@ protected void prePullDependencyImages(final Set<String> imagesToPull)
406413

407414
protected Logger log()
408415
{
409-
return LOG;
416+
return LOGGER;
410417
}
411418

412419
public AdvancedImageFromDockerFile withBuildArg(final String key, final String value)

0 commit comments

Comments
 (0)