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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# 2.0.1
* Improve matching in ``DockerfileCOPYParentsEmulator`` #134
* Now should properly handle ``./``

# 2.0.0
* Changed ignore backend to utilize [JGit](https://github.com/eclipse-jgit/jgit)
* This should now behave exactly like a ``.gitignore``
* Overall performance should be a lot faster
* Make it possible to modify transferred files
* Provide an option to emulate [``COPY --parents``](https://docs.docker.com/reference/dockerfile/#copy---parents) (which is currently not supported by Docker out of the box)
* Provide an option to emulate [``COPY --parents``](https://docs.docker.com/reference/dockerfile/#copy---parents) using ``DockerfileCOPYParentsEmulator`` (which is currently not supported by Docker out of the box)
* This option is required to utilize Docker's cache properly
```docker
# syntax=docker/dockerfile:1-labs
# ...

# Copy & Cache wrapper
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A re-implementation of [Testcontainers Image-Builder](https://java.testcontainer
* Makes logger non generic and therefore controllable
* Some general code cleanup and performance improvements

A common use case - that can also be seen [inside the demo](./testcontainers-advanced-imagebuilder-demo/src/main/java/software/xdev/Application.java) - is for creating an image - used in e.g. Integration tests - for an application that is also inside the same repo.
For more details have a look at [the demo](./testcontainers-advanced-imagebuilder-demo/src/main/java/software/xdev/Application.java).<br/>The demo showcases how an image for another application in the same repo can be built.

## Installation
[Installation guide for the latest release](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/releases/latest#Installation)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.25.0</version>
<version>10.25.1</version>
</dependency>
</dependencies>
<configuration>
Expand Down
9 changes: 1 addition & 8 deletions testcontainers-advanced-imagebuilder-demo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ARG JAVA_VERSION=21
FROM eclipse-temurin:$JAVA_VERSION-jdk-alpine AS build-env

RUN apk add --no-cache git bash
RUN apk add --no-cache bash

WORKDIR /build

Expand All @@ -21,13 +21,6 @@ RUN ${MAVEN_GO_OFFLINE_COMMAND}
# Copying all other files
COPY . ./

# A valid Git repo is required for the build
RUN git config --global user.email "[email protected]" \
&& git config --global user.name "Dynamic Build" \
&& git init --initial-branch=dynamically-built-tcst \
&& git add . \
&& git commit -m "Init commit"

ARG MAVEN_BUILD_COMMAND='./mvnw -B clean package -pl "testcontainers-advanced-imagebuilder-dummy-app" -am -T2C -Dmaven.test.skip'
RUN echo "Executing '$MAVEN_BUILD_COMMAND'"
RUN ${MAVEN_BUILD_COMMAND}
Expand Down
6 changes: 3 additions & 3 deletions testcontainers-advanced-imagebuilder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.21.1</version>
<version>1.21.2</version>
<exclusions>
<!-- No JUnit 4 -->
<exclusion>
Expand Down Expand Up @@ -205,7 +205,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.7.0</version>
<version>1.7.1</version>
<configuration>
<flattenMode>ossrh</flattenMode>
</configuration>
Expand Down Expand Up @@ -267,7 +267,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.25.0</version>
<version>10.25.1</version>
</dependency>
</dependencies>
<configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import software.xdev.testcontainers.imagebuilder.glob.GlobMatcher;
import software.xdev.testcontainers.imagebuilder.jgit.errors.InvalidPatternException;
import software.xdev.testcontainers.imagebuilder.jgit.ignore.internal.Strings;
import software.xdev.testcontainers.imagebuilder.transfer.DockerFileLineModifier;


Expand Down Expand Up @@ -118,9 +120,9 @@ protected Stream<String> handleLine(final String line, final Set<String> relativ
return Stream.of(args)
.limit((long)args.length - (isLastArg ? 1 : 0))
.flatMap(source -> {
if(!source.contains("*") && !source.contains("/"))
if(!source.contains("*"))
{
return Stream.of(Map.entry(source, targetPathFinal));
return Stream.of(Map.entry(source, targetPathFinalForRelative + removeRelativeStart(source)));
}

final GlobMatcher matcher = new GlobMatcher(source);
Expand All @@ -133,4 +135,38 @@ protected Stream<String> handleLine(final String line, final Set<String> relativ
+ (!lineAfterArgsFinal.isEmpty() ? " " + lineAfterArgsFinal : "")
+ " " + e.getValue());
}

protected static String removeRelativeStart(final String path)
{
return path.startsWith("./") ? path.substring(2) : path;
}

public static class GlobMatcher
{
protected final Pattern pattern;

public GlobMatcher(final String pattern)
{
try
{
this.pattern = Pattern.compile("\\/?" + Strings.convertGlob(removeRelativeStart(pattern)));
}
catch(final InvalidPatternException e)
{
throw new IllegalArgumentException(e);
}
}

@SuppressWarnings("checkstyle:FinalParameters")
protected String correctPathForMatching(String path)
{
path = removeRelativeStart(path);
return path.startsWith("/") ? path : ("/" + path);
}

public boolean matches(final String path)
{
return this.pattern.matcher(this.correctPathForMatching(path)).matches();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,39 @@ void simpleCheck()
"FROM alpine:3",
"COPY --parents mvnw .mvn/** --abc ./",
"COPY --parents **/pom.xml ./",
"COPY --parents abc/def.txt ./"
"COPY --parents abc/def.txt ./",
"COPY --parents ./d/e/** ./",
"COPY ./d/e/** ./", // Keep original
"COPY --parents ./it/mvnw ./it/.mvn/** ./xx"
), Set.of(
".mvn/wrapper/maven-wrapper.properties",
"mvnw",
".mvn/wrapper/maven-wrapper.properties",
"Dockerfile",
"pom.xml",
"a/pom.xml",
"a/b/pom.xml",
"a/b/c/pom.xml",
"abc/def.txt",
"ignoreme.txt"
"ignoreme.txt",
"d/e/example.txt",
"it/mvnw",
"it/.mvn/wrapper/maven-wrapper.properties"
));
Assertions.assertIterableEquals(
List.of(
"# syntax=docker/dockerfile:1-labs",
"FROM alpine:3",
"COPY mvnw --abc ./",
"COPY mvnw --abc ./mvnw",
"COPY .mvn/wrapper/maven-wrapper.properties --abc ./.mvn/wrapper/maven-wrapper.properties",
"COPY a/b/c/pom.xml ./a/b/c/pom.xml",
"COPY a/b/pom.xml ./a/b/pom.xml",
"COPY a/pom.xml ./a/pom.xml",
"COPY pom.xml ./pom.xml",
"COPY abc/def.txt ./abc/def.txt"
"COPY abc/def.txt ./abc/def.txt",
"COPY d/e/example.txt ./d/e/example.txt",
"COPY ./d/e/** ./", // Keep original
"COPY ./it/mvnw ./xx/it/mvnw",
"COPY it/.mvn/wrapper/maven-wrapper.properties ./xx/it/.mvn/wrapper/maven-wrapper.properties"
),
lines);
}
Expand Down