Skip to content

Commit 40612c9

Browse files
authored
Merge pull request #126 from xdev-software/v2
V2
2 parents 3a9a7e1 + 94efd01 commit 40612c9

35 files changed

+3037
-290
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
# 2.0.0
2+
* Changed ignore backend to utilize [JGit](https://github.com/eclipse-jgit/jgit)
3+
* This should now behave exactly like a ``.gitignore``
4+
* Overall performance should be a lot faster
5+
* 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)
7+
* This option is required to utilize Docker's cache properly
8+
```docker
9+
# ...
10+
11+
# Copy & Cache wrapper
12+
COPY --parents mvnw .mvn/** ./
13+
RUN ./mvnw --version
14+
15+
# Copy & Cache poms/dependencies
16+
COPY --parents **/pom.xml ./
17+
# Resolve jars so that they can be cached and don't need to be downloaded when a Java file changes
18+
RUN ./mvnw -B dependency:go-offline -pl app -am -DincludeScope=runtime -T2C
19+
20+
# Copying all other files
21+
COPY . ./
22+
# Run the actual build
23+
RUN ./mvnw -B clean package -pl app -am -T2C -Dmaven.test.skip
24+
```
25+
* At ton of minor optimizations and improvements
26+
127
# 1.2.0
228
* Provide an option to always transfer specific paths
329
* Always transfer Dockerfile - as it is required for building - by default

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ A re-implementation of [Testcontainers Image-Builder](https://java.testcontainer
88
* Allows passing a custom logger to the image build - [testcontainers-java#3093](https://github.com/testcontainers/testcontainers-java/issues/3093)
99
* Allows using ``ARG``s for ``FROM`` - [testcontainers-java#3238](https://github.com/testcontainers/testcontainers-java/issues/3238)
1010
* Brings a custom [build-context](https://docs.docker.com/build/building/context/) processor
11-
* Works more efficient and reliable than the default implementation (however likely still not perfect)
11+
* Works more efficient and reliable than the default implementation (utilizes [JGit](https://github.com/eclipse-jgit/jgit))
1212
* uses ``.gitignore`` if available
1313
* Allows adding custom ignores
1414
* This way the build-context can be fine tuned in a way that the build cache works very efficiently (e.g. only re-built when actual code that matters changes)
15+
* Makes it possible to modify files that are transferred
16+
* Provide a compatibility layer to emulate [``COPY --parents``](https://docs.docker.com/reference/dockerfile/#copy---parents) (which is currently not supported by Docker out of the box)
1517
* Do not pull images that are declared inside the Dockerfile
1618
* Makes logger non generic and therefore controllable
1719
* Did some general code cleanup

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>software.xdev</groupId>
88
<artifactId>testcontainers-advanced-imagebuilder-root</artifactId>
9-
<version>1.2.1-SNAPSHOT</version>
9+
<version>2.0.0-SNAPSHOT</version>
1010
<packaging>pom</packaging>
1111

1212
<organization>

testcontainers-advanced-imagebuilder-demo/Dockerfile

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1+
# syntax=docker/dockerfile:1-labs
12
# Stage 1: Build the dummy app
23
ARG JAVA_VERSION=21
34
FROM eclipse-temurin:$JAVA_VERSION-jdk-alpine AS build-env
45

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

7-
# Create non root user
8-
ARG userName=limitedbuild
9-
ARG groupName=limitedbuild
10-
ARG userId=1000
11-
12-
RUN addgroup --system ${groupName} \
13-
&& adduser --uid ${userId} --system --disabled-password --shell /bin/bash ${userName} \
14-
&& adduser ${userName} ${groupName}
15-
16-
# Create build dir
17-
RUN mkdir /build \
18-
&& chown ${userName}:${groupName} /build
198
WORKDIR /build
209

21-
USER ${userName}
22-
23-
# Copying context is prepared by Testcontainers
24-
COPY --chown=${userName}:${groupName} . ./
25-
26-
# RUN chmod +x ./mvnw
27-
ARG mvncmd='clean package -pl "testcontainers-advanced-imagebuilder-dummy-app" -am -T2C -Dmaven.test.skip'
28-
29-
RUN echo "Executing '$mvncmd'"
30-
RUN chmod +x ./mvnw \
31-
&& ./mvnw -B ${mvncmd}
10+
# Copy & Cache wrapper
11+
COPY --parents mvnw .mvn/** ./
12+
RUN ./mvnw --version
13+
14+
# Copy & Cache poms/dependencies
15+
COPY --parents **/pom.xml ./
16+
# Resolve jars so that they can be cached and don't need to be downloaded when a Java file changes
17+
ARG MAVEN_GO_OFFLINE_COMMAND='./mvnw -B dependency:go-offline -pl "testcontainers-advanced-imagebuilder-dummy-app" -am -DincludeScope=runtime -T2C'
18+
RUN echo "Executing '$MAVEN_GO_OFFLINE_COMMAND'"
19+
RUN ${MAVEN_GO_OFFLINE_COMMAND}
20+
21+
# Copying all other files
22+
COPY . ./
23+
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+
31+
ARG MAVEN_BUILD_COMMAND='./mvnw -B clean package -pl "testcontainers-advanced-imagebuilder-dummy-app" -am -T2C -Dmaven.test.skip'
32+
RUN echo "Executing '$MAVEN_BUILD_COMMAND'"
33+
RUN ${MAVEN_BUILD_COMMAND}
3234

3335
# Stage 2: Build the executable image
3436
FROM eclipse-temurin:21-jre-alpine

testcontainers-advanced-imagebuilder-demo/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<parent>
88
<groupId>software.xdev</groupId>
99
<artifactId>testcontainers-advanced-imagebuilder-root</artifactId>
10-
<version>1.2.1-SNAPSHOT</version>
10+
<version>2.0.0-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>testcontainers-advanced-imagebuilder-demo</artifactId>
14-
<version>1.2.1-SNAPSHOT</version>
14+
<version>2.0.0-SNAPSHOT</version>
1515
<packaging>jar</packaging>
1616

1717
<organization>

testcontainers-advanced-imagebuilder-demo/src/main/java/software/xdev/Application.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.slf4j.LoggerFactory;
66

77
import software.xdev.testcontainers.imagebuilder.AdvancedImageFromDockerFile;
8+
import software.xdev.testcontainers.imagebuilder.compat.DockerfileCOPYParentsEmulator;
89

910

1011
public final class Application
@@ -14,7 +15,7 @@ public static void main(final String[] args)
1415
{
1516
final AdvancedImageFromDockerFile builder = new AdvancedImageFromDockerFile("dynamically-built")
1617
.withLoggerForBuild(LoggerFactory.getLogger("container.build"))
17-
.withAdditionalIgnoreLines(
18+
.withPostGitIgnoreLines(
1819
// Ignore files that aren't related to the built code
1920
".git/**",
2021
".config/**",
@@ -26,11 +27,11 @@ public static void main(final String[] args)
2627
"/renovate.json5",
2728
// We need to keep the pom.xml as maven can't resolve the modules otherwise
2829
"testcontainers-advanced-imagebuilder/src/**",
29-
"testcontainers-advanced-imagebuilder/test/**",
3030
"testcontainers-advanced-imagebuilder-demo/src/**"
3131
)
3232
.withDockerFilePath(Paths.get("../testcontainers-advanced-imagebuilder-demo/Dockerfile"))
33-
.withBaseDir(Paths.get("../"));
33+
.withBaseDir(Paths.get("../"))
34+
.withDockerFileLinesModifier(new DockerfileCOPYParentsEmulator());
3435

3536
final String imageName = builder.get();
3637

testcontainers-advanced-imagebuilder-dummy-app/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>software.xdev</groupId>
88
<artifactId>testcontainers-advanced-imagebuilder-dummy-app</artifactId>
9-
<version>1.2.1-SNAPSHOT</version>
9+
<version>2.0.0-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111

1212
<organization>

testcontainers-advanced-imagebuilder/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>software.xdev</groupId>
88
<artifactId>testcontainers-advanced-imagebuilder</artifactId>
9-
<version>1.2.1-SNAPSHOT</version>
9+
<version>2.0.0-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111

1212
<name>testcontainers-advanced-imagebuilder</name>

0 commit comments

Comments
 (0)