Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/broken-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

- name: Link Checker
id: lychee
uses: lycheeverse/lychee-action@8646ba30535128ac92d33dfc9133794bfdd9b411 # v2
uses: lycheeverse/lychee-action@e7477775783ea5526144ba13e8db5eec57747ce8 # v2
with:
args: "--verbose --no-progress './**/*.md'"
fail: false # Don't fail on broken links, create an issue instead
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 4.1.0
* New method `copyForExactRebuild`

# 4.0.0
* Add `NativeAdvancedImageFromDockerfile`
* Builds the image using a new `docker build` process
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>software.xdev</groupId>
<artifactId>testcontainers-advanced-imagebuilder-root</artifactId>
<version>4.0.1-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<organization>
Expand Down
4 changes: 2 additions & 2 deletions testcontainers-advanced-imagebuilder-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>software.xdev</groupId>
<artifactId>testcontainers-advanced-imagebuilder-root</artifactId>
<version>4.0.1-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
</parent>

<artifactId>testcontainers-advanced-imagebuilder-demo</artifactId>
<version>4.0.1-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<organization>
Expand Down
2 changes: 1 addition & 1 deletion testcontainers-advanced-imagebuilder-dummy-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>software.xdev</groupId>
<artifactId>testcontainers-advanced-imagebuilder-dummy-app</artifactId>
<version>4.0.1-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<organization>
Expand Down
2 changes: 1 addition & 1 deletion testcontainers-advanced-imagebuilder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>software.xdev</groupId>
<artifactId>testcontainers-advanced-imagebuilder</artifactId>
<version>4.0.1-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>testcontainers-advanced-imagebuilder</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,41 @@ protected Logger log()
@Override
protected abstract String resolve();

/**
* Creates a copy of the image-builder that will build the exact same image.
* <p>
* NOTE: Requires {@link #createTransferFilesCache} to be set to <code>true</code> and an initial build, so that
* {@link #transferFileCache} is seeded.
* </p>
*/
public abstract S copyForExactRebuild(final String dockerImageName);

protected S copyForExactRebuild(final BiFunction<String, Boolean, S> createNewFunc, final String dockerImageName)
{
if(!this.createTransferFilesCache)
{
throw new IllegalStateException(
"createTransferFilesCache must be true to execute this operation");
}
if(this.transferFileCache == null)
{
throw new IllegalStateException("No transferFileCache. Did you build this image?");
}

final S image = createNewFunc.apply(dockerImageName, this.deleteOnExit)
.withBuildArgs(this.buildArgs)
.withLoggerForBuild(this.loggerForBuild)
.withCreateTransferFilesCache(false)
.withTransferFileCache(this.transferFileCache)
.withDisablePull(true);

this.optDockerFilePath.ifPresent(image::withDockerFilePath);
this.optBaseDir.ifPresent(image::withBaseDir);
this.optTarget.ifPresent(image::withTarget);

return image;
}

// region with

public S withLoggerForBuild(final Logger loggerForBuild)
Expand Down Expand Up @@ -485,6 +520,11 @@ public S withUseWinNTFSJunctionFixIfApplicable(

// endregion

public String getDockerImageName()
{
return this.dockerImageName;
}

@SuppressWarnings("unchecked")
protected S self()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.zip.GZIPOutputStream;

Expand Down Expand Up @@ -259,6 +260,22 @@ protected void prepareImagePull(
state.setExternalDependencyImageNames(externalDependencyImageNames);
}

@Override
public AdvancedImageFromDockerFile copyForExactRebuild(final String dockerImageName)
{
return this.copyForExactRebuild(AdvancedImageFromDockerFile::new, dockerImageName);
}

@Override
protected AdvancedImageFromDockerFile copyForExactRebuild(
final BiFunction<String, Boolean, AdvancedImageFromDockerFile> createNewFunc,
final String dockerImageName)
{
return super.copyForExactRebuild(createNewFunc, dockerImageName)
.withExplicitTransferables(this.explicitTransferables)
.withBuildImageCmdModifiers(this.buildImageCmdModifiers);
}

/**
* @see #copyForIntermediateTag(String, String)
*/
Expand All @@ -278,29 +295,7 @@ public AdvancedImageFromDockerFile copyForIntermediateTag(final String target)
public AdvancedImageFromDockerFile copyForIntermediateTag(
final String dockerImageName, final String target)
{
if(!this.createTransferFilesCache)
{
throw new IllegalStateException(
"createTransferFilesCache must be true to execute this operation");
}
if(this.transferFileCache == null)
{
throw new IllegalStateException("No transferFileCache. Did you build this image?");
}

return new AdvancedImageFromDockerFile(dockerImageName, this.deleteOnExit)
// Copy defaults
.withExplicitTransferables(this.explicitTransferables)
.withBuildArgs(this.buildArgs)
.withLoggerForBuild(this.loggerForBuild)
.withDockerFilePath(this.optDockerFilePath.orElse(null))
.withBaseDir(this.optBaseDir.orElse(null))
.withBuildImageCmdModifiers(this.buildImageCmdModifiers)
// Special
.withCreateTransferFilesCache(false)
.withTransferFileCache(this.transferFileCache)
.withTarget(target)
.withDisablePull(true);
return this.copyForExactRebuild(dockerImageName).withTarget(target);
}

public void cleanCreatedTransferFilesCache()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.stream.Stream;

Expand Down Expand Up @@ -280,6 +281,28 @@ protected void logStream(final InputStream src, final Consumer<String> logFunc)
}, this.executorService());
}

@Override
public NativeAdvancedImageFromDockerfile copyForExactRebuild(final String dockerImageName)
{
return this.copyForExactRebuild(NativeAdvancedImageFromDockerfile::new, dockerImageName);
}

@Override
protected NativeAdvancedImageFromDockerfile copyForExactRebuild(
final BiFunction<String, Boolean, NativeAdvancedImageFromDockerfile> createNewFunc,
final String dockerImageName)
{
final NativeAdvancedImageFromDockerfile image = super.copyForExactRebuild(createNewFunc, dockerImageName)
.withAdditionalArgs(this.additionalArgs)
.withLoad(this.load)
.withTimeout(this.timeout);

this.optCacheFrom.ifPresent(image::withCacheFrom);
this.optCacheTo.ifPresent(image::withCacheTo);

return image;
}

// region with

public NativeAdvancedImageFromDockerfile withBaseCommand(final List<String> baseCommand)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void checkGitHubCaching()
if(System.getenv("GITHUB_ACTIONS") == null)
{
Assumptions.abort("Not running on GitHub Actions");
return;
}

this.checkIfDockerIsPresentOrAbort();
Expand Down