Skip to content

Commit 505722a

Browse files
committed
Init code
1 parent dbcf45d commit 505722a

File tree

12 files changed

+1143
-9
lines changed

12 files changed

+1143
-9
lines changed

.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/') }}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<modules>
1818
<module>testcontainers-java-advanced-imagebuilder</module>
19+
<module>testcontainers-java-advanced-imagebuilder-dummy-app</module>
1920
<module>testcontainers-java-advanced-imagebuilder-demo</module>
2021
</modules>
2122

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Stage 1: Build the dummy app
2+
FROM eclipse-temurin:21-jdk-alpine AS build-env
3+
4+
RUN apk add --no-cache git
5+
6+
# Create non root user
7+
ARG userName=limitedbuild
8+
ARG groupName=limitedbuild
9+
ARG userId=1000
10+
11+
RUN addgroup --system ${groupName} \
12+
&& adduser --uid ${userId} --system --disabled-password --shell /bin/bash ${userName} \
13+
&& adduser ${userName} ${groupName}
14+
15+
# Create build dir
16+
RUN mkdir /build \
17+
&& chown ${userName}:${groupName} /build
18+
WORKDIR /build
19+
20+
USER ${userName}
21+
22+
# Copying context is prepared by Testcontainers
23+
COPY --chown=${userName}:${groupName} . ./
24+
25+
# RUN chmod +x ./mvnw
26+
ARG mvncmd='clean package -pl "testcontainers-java-advanced-imagebuilder-dummy-app" -am -T2C -Dmaven.test.skip'
27+
28+
RUN echo "Executing '$mvncmd'"
29+
RUN chmod +x ./mvnw \
30+
&& ./mvnw -B $mvncmd
31+
32+
# Stage 2: Build the executable image
33+
FROM eclipse-temurin:21-jre-alpine
34+
35+
ARG user=dummy-app
36+
ARG group=dummy-app
37+
ARG uid=1000
38+
ARG gid=1000
39+
ARG APP_DIR=/opt/dummy-app
40+
41+
# Create user + group + home
42+
RUN mkdir -p $APP_DIR \
43+
&& chown ${uid}:${gid} $APP_DIR \
44+
&& addgroup -g ${gid} ${group} \
45+
&& adduser -h "$APP_DIR" -u ${uid} -G ${group} -s /bin/bash -D ${user}
46+
47+
EXPOSE 8080
48+
49+
USER ${user}
50+
51+
COPY --from=build-env --chown=${user}:${group} build/testcontainers-java-advanced-imagebuilder-dummy-app/target/dummy-app.jar ${APP_DIR}/dummy-app.jar
52+
53+
CMD java $JAVA_OPTS -jar /opt/dummy-app/dummy-app.jar

testcontainers-java-advanced-imagebuilder-demo/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
<artifactId>testcontainers-java-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-java-advanced-imagebuilder/src/**",
29+
"testcontainers-java-advanced-imagebuilder/test/**",
30+
"testcontainers-java-advanced-imagebuilder-demo/src/**"
31+
)
32+
.withDockerFilePath(Paths.get("../testcontainers-java-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+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>software.xdev</groupId>
8+
<artifactId>testcontainers-java-advanced-imagebuilder-dummy-app</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<organization>
13+
<name>XDEV Software</name>
14+
<url>https://xdev.software</url>
15+
</organization>
16+
17+
<properties>
18+
<javaVersion>17</javaVersion>
19+
<maven.compiler.release>${javaVersion}</maven.compiler.release>
20+
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23+
24+
<mainClass>software.xdev.Application</mainClass>
25+
</properties>
26+
27+
<build>
28+
<finalName>dummy-app</finalName>
29+
30+
<plugins>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-compiler-plugin</artifactId>
34+
<version>3.13.0</version>
35+
<configuration>
36+
<release>${maven.compiler.release}</release>
37+
<compilerArgs>
38+
<arg>-proc:none</arg>
39+
</compilerArgs>
40+
</configuration>
41+
</plugin>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-assembly-plugin</artifactId>
45+
<version>3.7.1</version>
46+
<configuration>
47+
<archive>
48+
<manifest>
49+
<mainClass>${mainClass}</mainClass>
50+
</manifest>
51+
<manifestEntries>
52+
<Multi-Release>true</Multi-Release>
53+
</manifestEntries>
54+
</archive>
55+
<descriptorRefs>
56+
<descriptorRef>jar-with-dependencies</descriptorRef>
57+
</descriptorRefs>
58+
<appendAssemblyId>false</appendAssemblyId>
59+
</configuration>
60+
<executions>
61+
<execution>
62+
<id>make-assembly</id> <!-- this is used for inheritance merges -->
63+
<phase>package</phase> <!-- bind to the packaging phase -->
64+
<goals>
65+
<goal>single</goal>
66+
</goals>
67+
</execution>
68+
</executions>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
<profiles>
73+
<profile>
74+
<id>checkstyle</id>
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-checkstyle-plugin</artifactId>
80+
<version>3.3.1</version>
81+
<dependencies>
82+
<dependency>
83+
<groupId>com.puppycrawl.tools</groupId>
84+
<artifactId>checkstyle</artifactId>
85+
<version>10.15.0</version>
86+
</dependency>
87+
</dependencies>
88+
<configuration>
89+
<configLocation>../.config/checkstyle/checkstyle.xml</configLocation>
90+
</configuration>
91+
<executions>
92+
<execution>
93+
<goals>
94+
<goal>check</goal>
95+
</goals>
96+
</execution>
97+
</executions>
98+
</plugin>
99+
</plugins>
100+
</build>
101+
</profile>
102+
</profiles>
103+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package software.xdev;
2+
3+
public final class Application
4+
{
5+
@SuppressWarnings("java:S106")
6+
public static void main(final String[] args)
7+
{
8+
System.out.println("I'm a dummy app. I could also be something more complex like webapp if I want to ;)");
9+
}
10+
11+
private Application()
12+
{
13+
}
14+
}

testcontainers-java-advanced-imagebuilder/pom.xml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<connection>scm:git:https://github.com/xdev-software/testcontainers-java-advanced-imagebuilder.git</connection>
1919
</scm>
2020

21-
<inceptionYear>2023</inceptionYear>
21+
<inceptionYear>2024</inceptionYear>
2222

2323
<organization>
2424
<name>XDEV Software</name>
@@ -47,6 +47,9 @@
4747

4848
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4949
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
50+
51+
<!-- by default run no tests as Docker is required -->
52+
<skipTests>true</skipTests>
5053
</properties>
5154

5255
<repositories>
@@ -84,6 +87,34 @@
8487
</repository>
8588
</distributionManagement>
8689

90+
<dependencies>
91+
<dependency>
92+
<groupId>org.testcontainers</groupId>
93+
<artifactId>testcontainers</artifactId>
94+
<version>1.19.7</version>
95+
</dependency>
96+
<!-- Testcontainers is using outdated v1 -->
97+
<dependency>
98+
<groupId>org.slf4j</groupId>
99+
<artifactId>slf4j-api</artifactId>
100+
<version>2.0.13</version>
101+
</dependency>
102+
103+
<!-- Tests -->
104+
<dependency>
105+
<groupId>org.junit.jupiter</groupId>
106+
<artifactId>junit-jupiter</artifactId>
107+
<version>5.10.2</version>
108+
<scope>test</scope>
109+
</dependency>
110+
<dependency>
111+
<groupId>org.slf4j</groupId>
112+
<artifactId>slf4j-simple</artifactId>
113+
<version>2.0.13</version>
114+
<scope>test</scope>
115+
</dependency>
116+
</dependencies>
117+
87118
<build>
88119
<pluginManagement>
89120
<plugins>
@@ -172,9 +203,24 @@
172203
</execution>
173204
</executions>
174205
</plugin>
206+
207+
<plugin>
208+
<groupId>org.apache.maven.plugins</groupId>
209+
<artifactId>maven-surefire-plugin</artifactId>
210+
<version>3.2.5</version>
211+
<configuration>
212+
<skipTests>${skipTests}</skipTests>
213+
</configuration>
214+
</plugin>
175215
</plugins>
176216
</build>
177217
<profiles>
218+
<profile>
219+
<id>run-integration-tests</id>
220+
<properties>
221+
<skipTests>false</skipTests>
222+
</properties>
223+
</profile>
178224
<profile>
179225
<id>ossrh</id>
180226
<build>

0 commit comments

Comments
 (0)