Skip to content

Commit 02dbae3

Browse files
authored
Merge pull request #136 from xdev-software/develop
Release
2 parents 58a669c + ad8e601 commit 02dbae3

File tree

8 files changed

+66
-74
lines changed

8 files changed

+66
-74
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
# 2.0.1
2+
* Improve matching in ``DockerfileCOPYParentsEmulator`` #134
3+
* Now should properly handle ``./``
4+
15
# 2.0.0
26
* Changed ignore backend to utilize [JGit](https://github.com/eclipse-jgit/jgit)
37
* This should now behave exactly like a ``.gitignore``
48
* Overall performance should be a lot faster
59
* Make it possible to modify transferred files
6-
* 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)
10+
* 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)
711
* This option is required to utilize Docker's cache properly
812
```docker
13+
# syntax=docker/dockerfile:1-labs
914
# ...
1015
1116
# Copy & Cache wrapper

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ A re-implementation of [Testcontainers Image-Builder](https://java.testcontainer
1818
* Makes logger non generic and therefore controllable
1919
* Some general code cleanup and performance improvements
2020

21-
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.
21+
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.
2222

2323
## Installation
2424
[Installation guide for the latest release](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/releases/latest#Installation)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<dependency>
4747
<groupId>com.puppycrawl.tools</groupId>
4848
<artifactId>checkstyle</artifactId>
49-
<version>10.25.0</version>
49+
<version>10.25.1</version>
5050
</dependency>
5151
</dependencies>
5252
<configuration>

testcontainers-advanced-imagebuilder-demo/Dockerfile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
ARG JAVA_VERSION=21
44
FROM eclipse-temurin:$JAVA_VERSION-jdk-alpine AS build-env
55

6-
RUN apk add --no-cache git bash
6+
RUN apk add --no-cache bash
77

88
WORKDIR /build
99

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

24-
# A valid Git repo is required for the build
25-
RUN git config --global user.email "[email protected]" \
26-
&& git config --global user.name "Dynamic Build" \
27-
&& git init --initial-branch=dynamically-built-tcst \
28-
&& git add . \
29-
&& git commit -m "Init commit"
30-
3124
ARG MAVEN_BUILD_COMMAND='./mvnw -B clean package -pl "testcontainers-advanced-imagebuilder-dummy-app" -am -T2C -Dmaven.test.skip'
3225
RUN echo "Executing '$MAVEN_BUILD_COMMAND'"
3326
RUN ${MAVEN_BUILD_COMMAND}

testcontainers-advanced-imagebuilder/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<dependency>
5757
<groupId>org.testcontainers</groupId>
5858
<artifactId>testcontainers</artifactId>
59-
<version>1.21.1</version>
59+
<version>1.21.2</version>
6060
<exclusions>
6161
<!-- No JUnit 4 -->
6262
<exclusion>
@@ -205,7 +205,7 @@
205205
<plugin>
206206
<groupId>org.codehaus.mojo</groupId>
207207
<artifactId>flatten-maven-plugin</artifactId>
208-
<version>1.7.0</version>
208+
<version>1.7.1</version>
209209
<configuration>
210210
<flattenMode>ossrh</flattenMode>
211211
</configuration>
@@ -267,7 +267,7 @@
267267
<dependency>
268268
<groupId>com.puppycrawl.tools</groupId>
269269
<artifactId>checkstyle</artifactId>
270-
<version>10.25.0</version>
270+
<version>10.25.1</version>
271271
</dependency>
272272
</dependencies>
273273
<configuration>

testcontainers-advanced-imagebuilder/src/main/java/software/xdev/testcontainers/imagebuilder/compat/DockerfileCOPYParentsEmulator.java

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
import java.util.List;
1919
import java.util.Map;
2020
import java.util.Set;
21+
import java.util.regex.Pattern;
2122
import java.util.stream.Stream;
2223

23-
import software.xdev.testcontainers.imagebuilder.glob.GlobMatcher;
24+
import software.xdev.testcontainers.imagebuilder.jgit.errors.InvalidPatternException;
25+
import software.xdev.testcontainers.imagebuilder.jgit.ignore.internal.Strings;
2426
import software.xdev.testcontainers.imagebuilder.transfer.DockerFileLineModifier;
2527

2628

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

126128
final GlobMatcher matcher = new GlobMatcher(source);
@@ -133,4 +135,38 @@ protected Stream<String> handleLine(final String line, final Set<String> relativ
133135
+ (!lineAfterArgsFinal.isEmpty() ? " " + lineAfterArgsFinal : "")
134136
+ " " + e.getValue());
135137
}
138+
139+
protected static String removeRelativeStart(final String path)
140+
{
141+
return path.startsWith("./") ? path.substring(2) : path;
142+
}
143+
144+
public static class GlobMatcher
145+
{
146+
protected final Pattern pattern;
147+
148+
public GlobMatcher(final String pattern)
149+
{
150+
try
151+
{
152+
this.pattern = Pattern.compile("\\/?" + Strings.convertGlob(removeRelativeStart(pattern)));
153+
}
154+
catch(final InvalidPatternException e)
155+
{
156+
throw new IllegalArgumentException(e);
157+
}
158+
}
159+
160+
@SuppressWarnings("checkstyle:FinalParameters")
161+
protected String correctPathForMatching(String path)
162+
{
163+
path = removeRelativeStart(path);
164+
return path.startsWith("/") ? path : ("/" + path);
165+
}
166+
167+
public boolean matches(final String path)
168+
{
169+
return this.pattern.matcher(this.correctPathForMatching(path)).matches();
170+
}
171+
}
136172
}

testcontainers-advanced-imagebuilder/src/main/java/software/xdev/testcontainers/imagebuilder/glob/GlobMatcher.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

testcontainers-advanced-imagebuilder/src/test/java/software/xdev/testcontainers/imagebuilder/compat/DockerfileCOPYParentsEmulatorTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,39 @@ void simpleCheck()
3333
"FROM alpine:3",
3434
"COPY --parents mvnw .mvn/** --abc ./",
3535
"COPY --parents **/pom.xml ./",
36-
"COPY --parents abc/def.txt ./"
36+
"COPY --parents abc/def.txt ./",
37+
"COPY --parents ./d/e/** ./",
38+
"COPY ./d/e/** ./", // Keep original
39+
"COPY --parents ./it/mvnw ./it/.mvn/** ./xx"
3740
), Set.of(
38-
".mvn/wrapper/maven-wrapper.properties",
3941
"mvnw",
42+
".mvn/wrapper/maven-wrapper.properties",
4043
"Dockerfile",
4144
"pom.xml",
4245
"a/pom.xml",
4346
"a/b/pom.xml",
4447
"a/b/c/pom.xml",
4548
"abc/def.txt",
46-
"ignoreme.txt"
49+
"ignoreme.txt",
50+
"d/e/example.txt",
51+
"it/mvnw",
52+
"it/.mvn/wrapper/maven-wrapper.properties"
4753
));
4854
Assertions.assertIterableEquals(
4955
List.of(
5056
"# syntax=docker/dockerfile:1-labs",
5157
"FROM alpine:3",
52-
"COPY mvnw --abc ./",
58+
"COPY mvnw --abc ./mvnw",
5359
"COPY .mvn/wrapper/maven-wrapper.properties --abc ./.mvn/wrapper/maven-wrapper.properties",
5460
"COPY a/b/c/pom.xml ./a/b/c/pom.xml",
5561
"COPY a/b/pom.xml ./a/b/pom.xml",
5662
"COPY a/pom.xml ./a/pom.xml",
5763
"COPY pom.xml ./pom.xml",
58-
"COPY abc/def.txt ./abc/def.txt"
64+
"COPY abc/def.txt ./abc/def.txt",
65+
"COPY d/e/example.txt ./d/e/example.txt",
66+
"COPY ./d/e/** ./", // Keep original
67+
"COPY ./it/mvnw ./xx/it/mvnw",
68+
"COPY it/.mvn/wrapper/maven-wrapper.properties ./xx/it/.mvn/wrapper/maven-wrapper.properties"
5969
),
6070
lines);
6171
}

0 commit comments

Comments
 (0)