Skip to content

Commit e1194b9

Browse files
authored
Merge pull request #2 from xdev-software/develop
Release
2 parents 9cdaa5e + 0643e52 commit e1194b9

File tree

17 files changed

+1180
-30
lines changed

17 files changed

+1180
-30
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
# Auto detect text files and perform LF normalization
22
* text=auto
3+
4+
# Force sh files to have LF
5+
*.sh text eol=lf
6+
7+
# Force MVN Wrapper Linux files LF
8+
mvnw text eol=lf
9+
.mvn/wrapper/maven-wrapper.properties text eol=lf

.github/workflows/checkBuild.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
cache: 'maven'
4444

4545
- name: Build with Maven
46-
run: ./mvnw -B clean package
46+
run: ./mvnw -B clean package -P run-integration-tests
4747

4848
- name: Check for uncommited changes
4949
run: |
@@ -63,13 +63,6 @@ jobs:
6363
exit 1
6464
fi
6565
66-
- name: Upload demo files
67-
uses: actions/upload-artifact@v4
68-
with:
69-
name: demo-files-java-${{ matrix.java }}
70-
path: ${{ env.DEMO_MAVEN_MODULE }}/target/${{ env.DEMO_MAVEN_MODULE }}.jar
71-
if-no-files-found: error
72-
7366
code-style:
7467
runs-on: ubuntu-latest
7568
if: ${{ github.event_name != 'pull_request' || !startsWith(github.head_ref, 'renovate/') }}

.run/Run Demo.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Run Demo" type="Application" factoryName="Application">
33
<option name="MAIN_CLASS_NAME" value="software.xdev.Application" />
4-
<module name="template-placeholder-demo" />
4+
<module name="testcontainers-advanced-imagebuilder-demo" />
55
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
66
<extension name="coverage">
77
<pattern>

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ You should have the following things installed:
3333
* Ensure that the JDK/Java-Version is correct
3434

3535

36-
## Releasing [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/template-placeholder/release.yml?branch=master)](https://github.com/xdev-software/template-placeholder/actions/workflows/release.yml)
36+
## Releasing [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/testcontainers-advanced-imagebuilder/release.yml?branch=master)](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/actions/workflows/release.yml)
3737

3838
Before releasing:
39-
* Consider doing a [test-deployment](https://github.com/xdev-software/template-placeholder/actions/workflows/test-deploy.yml?query=branch%3Adevelop) before actually releasing.
39+
* Consider doing a [test-deployment](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/actions/workflows/test-deploy.yml?query=branch%3Adevelop) before actually releasing.
4040
* Check the [changelog](CHANGELOG.md)
4141

4242
If the ``develop`` is ready for release, create a pull request to the ``master``-Branch and merge the changes

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
[![Latest version](https://img.shields.io/maven-central/v/software.xdev/template-placeholder?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/template-placeholder)
2-
[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/template-placeholder/checkBuild.yml?branch=develop)](https://github.com/xdev-software/template-placeholder/actions/workflows/checkBuild.yml?query=branch%3Adevelop)
3-
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_template-placeholder&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_template-placeholder)
1+
[![Latest version](https://img.shields.io/maven-central/v/software.xdev/testcontainers-advanced-imagebuilder?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/testcontainers-advanced-imagebuilder)
2+
[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/testcontainers-advanced-imagebuilder/checkBuild.yml?branch=develop)](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/actions/workflows/checkBuild.yml?query=branch%3Adevelop)
3+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_testcontainers-advanced-imagebuilder&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_testcontainers-advanced-imagebuilder)
44

5-
# template-placeholder
5+
# Advanced Image-Builder for Testcontainers Java
66

7+
A re-implementation of [Testcontainers Image-Builder](https://java.testcontainers.org/features/creating_images/) with the following improvements:
8+
* Allows passing a custom logger to the image build - [testcontainers-java#3093](https://github.com/testcontainers/testcontainers-java/issues/3093)
9+
* Allows using ``ARG``s for ``FROM`` - [testcontainers-java#3238](https://github.com/testcontainers/testcontainers-java/issues/3238)
10+
* 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)
12+
* uses ``.gitignore`` if available
13+
* Allows to adding custom ignores
14+
* 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 logger non generic and therefore controllable
16+
* Cleaned up some code
17+
18+
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.
719

820
## Installation
9-
[Installation guide for the latest release](https://github.com/xdev-software/template-placeholder/releases/latest#Installation)
21+
[Installation guide for the latest release](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/releases/latest#Installation)
1022

1123
## Support
1224
If you need support as soon as possible and you can't wait for any pull request, feel free to use [our support](https://xdev.software/en/services/support).
@@ -15,4 +27,4 @@ If you need support as soon as possible and you can't wait for any pull request,
1527
See the [contributing guide](./CONTRIBUTING.md) for detailed instructions on how to get started with our project.
1628

1729
## Dependencies and Licenses
18-
View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/template-placeholder/dependencies)
30+
View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/testcontainers-advanced-imagebuilder/dependencies)

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
## Reporting a Vulnerability
44

5-
Please report a security vulnerability [on GitHub Security Advisories](https://github.com/xdev-software/template-placeholder/security/advisories/new).
5+
Please report a security vulnerability [on GitHub Security Advisories](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/security/advisories/new).

pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<groupId>software.xdev</groupId>
8-
<artifactId>template-placeholder-root</artifactId>
8+
<artifactId>testcontainers-advanced-imagebuilder-root</artifactId>
99
<version>1.0.0-SNAPSHOT</version>
1010
<packaging>pom</packaging>
1111

@@ -15,8 +15,9 @@
1515
</organization>
1616

1717
<modules>
18-
<module>template-placeholder</module>
19-
<module>template-placeholder-demo</module>
18+
<module>testcontainers-advanced-imagebuilder</module>
19+
<module>testcontainers-advanced-imagebuilder-dummy-app</module>
20+
<module>testcontainers-advanced-imagebuilder-demo</module>
2021
</modules>
2122

2223
<licenses>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Stage 1: Build the dummy app
2+
ARG JAVA_VERSION=21
3+
FROM eclipse-temurin:$JAVA_VERSION-jdk-alpine AS build-env
4+
5+
RUN apk add --no-cache git bash
6+
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
19+
WORKDIR /build
20+
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
32+
33+
# Stage 2: Build the executable image
34+
FROM eclipse-temurin:21-jre-alpine
35+
36+
ARG user=dummy-app
37+
ARG group=dummy-app
38+
ARG uid=1000
39+
ARG gid=1000
40+
ARG APP_DIR=/opt/dummy-app
41+
42+
# Create user + group + home
43+
RUN mkdir -p $APP_DIR \
44+
&& chown ${uid}:${gid} $APP_DIR \
45+
&& addgroup -g ${gid} ${group} \
46+
&& adduser -h "$APP_DIR" -u ${uid} -G ${group} -s /bin/bash -D ${user}
47+
48+
EXPOSE 8080
49+
50+
USER ${user}
51+
52+
COPY --from=build-env --chown=${user}:${group} build/testcontainers-advanced-imagebuilder-dummy-app/target/dummy-app.jar ${APP_DIR}/dummy-app.jar
53+
54+
CMD java $JAVA_OPTS -jar /opt/dummy-app/dummy-app.jar

template-placeholder-demo/pom.xml renamed to testcontainers-advanced-imagebuilder-demo/pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<groupId>software.xdev</groupId>
8-
<artifactId>template-placeholder-demo</artifactId>
8+
<artifactId>testcontainers-advanced-imagebuilder-demo</artifactId>
99
<version>1.0.0-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111

@@ -27,9 +27,15 @@
2727
<dependencies>
2828
<dependency>
2929
<groupId>software.xdev</groupId>
30-
<artifactId>template-placeholder</artifactId>
30+
<artifactId>testcontainers-advanced-imagebuilder</artifactId>
3131
<version>${project.version}</version>
3232
</dependency>
33+
34+
<dependency>
35+
<groupId>org.slf4j</groupId>
36+
<artifactId>slf4j-simple</artifactId>
37+
<version>2.0.13</version>
38+
</dependency>
3339
</dependencies>
3440

3541
<build>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package software.xdev;
2+
3+
import java.nio.file.Paths;
4+
5+
import org.slf4j.LoggerFactory;
6+
7+
import software.xdev.testcontainers.imagebuilder.AdvancedImageFromDockerFile;
8+
9+
10+
public final class Application
11+
{
12+
@SuppressWarnings("java:S106")
13+
public static void main(final String[] args)
14+
{
15+
final AdvancedImageFromDockerFile builder = new AdvancedImageFromDockerFile("dynamically-built")
16+
.withLoggerForBuild(LoggerFactory.getLogger("container.build"))
17+
.withAdditionalIgnoreLines(
18+
// Ignore files that aren't related to the built code
19+
".git/**",
20+
".config/**",
21+
".github/**",
22+
".idea/**",
23+
".run/**",
24+
".md",
25+
".cmd",
26+
"/renovate.json5",
27+
// We need to keep the pom.xml as maven can't resolve the modules otherwise
28+
"testcontainers-advanced-imagebuilder/src/**",
29+
"testcontainers-advanced-imagebuilder/test/**",
30+
"testcontainers-advanced-imagebuilder-demo/src/**"
31+
)
32+
.withDockerFilePath(Paths.get("../testcontainers-advanced-imagebuilder-demo/Dockerfile"))
33+
.withBaseDir(Paths.get("../"));
34+
35+
final String imageName = builder.get();
36+
37+
System.out.println("Successfully build " + imageName);
38+
}
39+
40+
private Application()
41+
{
42+
}
43+
}

0 commit comments

Comments
 (0)