Skip to content

Commit 345c9f3

Browse files
authored
do not use anymore fabricio docker-maven-plugin to build images with maven but use on the fly testcontainers (#884)
Signed-off-by: Olivier Lamy <[email protected]>
1 parent 347c4b6 commit 345c9f3

File tree

15 files changed

+56
-260
lines changed

15 files changed

+56
-260
lines changed

pipeline-maven/pom.xml

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -477,142 +477,4 @@
477477
</plugins>
478478
</build>
479479

480-
<profiles>
481-
<profile>
482-
<id>build-docker-images</id>
483-
<activation>
484-
<os>
485-
<family>unix</family>
486-
</os>
487-
<file>
488-
<exists>/var/run/docker.sock</exists>
489-
</file>
490-
</activation>
491-
<build>
492-
<plugins>
493-
<plugin>
494-
<groupId>io.fabric8</groupId>
495-
<artifactId>docker-maven-plugin</artifactId>
496-
<configuration>
497-
<imagePullPolicy>IfNotPresent</imagePullPolicy>
498-
<skip>${skipTests}</skip>
499-
</configuration>
500-
<executions>
501-
<execution>
502-
<id>build-first-sshd-image</id>
503-
<goals>
504-
<goal>build</goal>
505-
</goals>
506-
<phase>process-test-resources</phase>
507-
<configuration>
508-
<images>
509-
<image>
510-
<build>
511-
<contextDir>${project.basedir}/src/test/resources/org/jenkinsci/plugins/pipeline/maven/docker/SshdContainer/</contextDir>
512-
</build>
513-
<name>localhost/pipeline-maven/sshd</name>
514-
</image>
515-
</images>
516-
</configuration>
517-
</execution>
518-
<execution>
519-
<id>build-java-git-image</id>
520-
<goals>
521-
<goal>build</goal>
522-
</goals>
523-
<phase>process-test-resources</phase>
524-
<configuration>
525-
<images>
526-
<image>
527-
<build>
528-
<contextDir>${project.basedir}/src/test/resources/org/jenkinsci/plugins/pipeline/maven/docker/JavaGitContainer/</contextDir>
529-
</build>
530-
<name>localhost/pipeline-maven/java-git</name>
531-
</image>
532-
</images>
533-
</configuration>
534-
</execution>
535-
<execution>
536-
<id>build-java-maven-git-image</id>
537-
<goals>
538-
<goal>build</goal>
539-
</goals>
540-
<phase>process-test-resources</phase>
541-
<configuration>
542-
<images>
543-
<image>
544-
<build>
545-
<contextDir>${project.basedir}/src/test/resources/org/jenkinsci/plugins/pipeline/maven/docker/JavaMavenContainer/</contextDir>
546-
</build>
547-
<name>localhost/pipeline-maven/java-maven-git</name>
548-
</image>
549-
</images>
550-
</configuration>
551-
</execution>
552-
<execution>
553-
<id>build-javas-image</id>
554-
<goals>
555-
<goal>build</goal>
556-
</goals>
557-
<phase>process-test-resources</phase>
558-
<configuration>
559-
<images>
560-
<image>
561-
<build>
562-
<contextDir>${project.basedir}/src/test/resources/org/jenkinsci/plugins/pipeline/maven/docker/JavasContainer/</contextDir>
563-
</build>
564-
<name>localhost/pipeline-maven/javas</name>
565-
</image>
566-
</images>
567-
</configuration>
568-
</execution>
569-
<execution>
570-
<id>build-maven-home-image</id>
571-
<goals>
572-
<goal>build</goal>
573-
</goals>
574-
<phase>process-test-resources</phase>
575-
<configuration>
576-
<images>
577-
<image>
578-
<build>
579-
<contextDir>${project.basedir}/src/test/resources/org/jenkinsci/plugins/pipeline/maven/docker/JavaMavenWithMavenHomeContainer/</contextDir>
580-
</build>
581-
<name>localhost/pipeline-maven/maven-home</name>
582-
</image>
583-
</images>
584-
</configuration>
585-
</execution>
586-
</executions>
587-
</plugin>
588-
<plugin>
589-
<groupId>org.codehaus.mojo</groupId>
590-
<artifactId>exec-maven-plugin</artifactId>
591-
<executions>
592-
<execution>
593-
<id>remove-test-images</id>
594-
<goals>
595-
<goal>exec</goal>
596-
</goals>
597-
<phase>prepare-package</phase>
598-
<configuration>
599-
<skip>${skipTests}</skip>
600-
<executable>docker</executable>
601-
<arguments>
602-
<argument>rmi</argument>
603-
<argument>localhost/pipeline-maven/sshd</argument>
604-
<argument>localhost/pipeline-maven/java-git</argument>
605-
<argument>localhost/pipeline-maven/java-maven-git</argument>
606-
<argument>localhost/pipeline-maven/javas</argument>
607-
<argument>localhost/pipeline-maven/maven-home</argument>
608-
</arguments>
609-
</configuration>
610-
</execution>
611-
</executions>
612-
</plugin>
613-
</plugins>
614-
</build>
615-
</profile>
616-
</profiles>
617-
618480
</project>

pipeline-maven/src/test/java/org/jenkinsci/plugins/pipeline/maven/AbstractIntegrationTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.jvnet.hudson.test.BuildWatcher;
3030
import org.jvnet.hudson.test.JenkinsRule;
3131
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
32+
import org.testcontainers.containers.GenericContainer;
33+
import org.testcontainers.images.builder.ImageFromDockerfile;
3234

3335
/**
3436
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a>
@@ -44,6 +46,14 @@ public abstract class AbstractIntegrationTest {
4446

4547
String mavenInstallationName;
4648

49+
public static GenericContainer<?> createContainer(String target) {
50+
return new GenericContainer<>(new ImageFromDockerfile(
51+
"localhost/pipeline-maven/" + target, Boolean.parseBoolean(System.getenv("CI")))
52+
.withFileFromClasspath(".", "/org/jenkinsci/plugins/pipeline/maven/docker")
53+
.withTarget(target))
54+
.withExposedPorts(22);
55+
}
56+
4757
@BeforeAll
4858
public static void setupWatcher() {
4959
buildWatcher = new BuildWatcher();

pipeline-maven/src/test/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepMavenExecResolutionTest.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public class WithMavenStepMavenExecResolutionTest extends AbstractIntegrationTes
5858

5959
@Test
6060
public void testMavenNotInstalledInDockerImage() throws Exception {
61-
try (GenericContainer<?> nonMavenContainerRule =
62-
new GenericContainer<>("localhost/pipeline-maven/java-git").withExposedPorts(22)) {
61+
try (GenericContainer<?> nonMavenContainerRule = createContainer("java-git")) {
6362
nonMavenContainerRule.start();
6463
assertThat(nonMavenContainerRule.execInContainer("mvn", "--version").getStdout())
6564
.contains("exec: \"mvn\": executable file not found in $PATH");
@@ -68,8 +67,7 @@ public void testMavenNotInstalledInDockerImage() throws Exception {
6867

6968
@Test
7069
public void testMavenGlobalToolRecognizedInScriptedPipeline() throws Exception {
71-
try (GenericContainer<?> nonMavenContainerRule =
72-
new GenericContainer<>("localhost/pipeline-maven/java-git").withExposedPorts(22)) {
70+
try (GenericContainer<?> nonMavenContainerRule = createContainer("java-git")) {
7371
nonMavenContainerRule.start();
7472
registerAgentForContainer(nonMavenContainerRule);
7573
String version = registerLatestMavenVersionAsGlobalTool();
@@ -96,8 +94,7 @@ public void testMavenGlobalToolRecognizedInScriptedPipeline() throws Exception {
9694

9795
@Test
9896
public void testMavenGlobalToolRecognizedInDeclarativePipeline() throws Exception {
99-
try (GenericContainer<?> nonMavenContainerRule =
100-
new GenericContainer<>("localhost/pipeline-maven/java-git").withExposedPorts(22)) {
97+
try (GenericContainer<?> nonMavenContainerRule = createContainer("java-git")) {
10198
nonMavenContainerRule.start();
10299
registerAgentForContainer(nonMavenContainerRule);
103100
String version = registerLatestMavenVersionAsGlobalTool();
@@ -131,8 +128,7 @@ public void testMavenGlobalToolRecognizedInDeclarativePipeline() throws Exceptio
131128

132129
@Test
133130
public void testPreInstalledMavenRecognizedWithoutMavenHome() throws Exception {
134-
try (GenericContainer<?> javaMavenGitContainerRule =
135-
new GenericContainer<>("localhost/pipeline-maven/java-maven-git").withExposedPorts(22)) {
131+
try (GenericContainer<?> javaMavenGitContainerRule = createContainer("java-maven-git")) {
136132
javaMavenGitContainerRule.start();
137133
registerAgentForContainer(javaMavenGitContainerRule);
138134

@@ -154,8 +150,7 @@ public void testPreInstalledMavenRecognizedWithoutMavenHome() throws Exception {
154150

155151
@Test
156152
public void testPreInstalledMavenRecognizedWithMavenHome() throws Exception {
157-
try (GenericContainer<?> mavenWithMavenHomeContainerRule =
158-
new GenericContainer<>("localhost/pipeline-maven/maven-home").withExposedPorts(22)) {
153+
try (GenericContainer<?> mavenWithMavenHomeContainerRule = createContainer("maven-home")) {
159154
mavenWithMavenHomeContainerRule.start();
160155
registerAgentForContainer(mavenWithMavenHomeContainerRule);
161156

pipeline-maven/src/test/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ public class WithMavenStepTest extends AbstractIntegrationTest {
7474
@Issue("SECURITY-441")
7575
@Test
7676
public void testMavenBuildOnRemoteAgentWithSettingsFileOnMasterFails() throws Exception {
77-
try (GenericContainer<?> mavenContainerRule =
78-
new GenericContainer<>("localhost/pipeline-maven/java-maven-git").withExposedPorts(22)) {
77+
try (GenericContainer<?> mavenContainerRule = createContainer("java-maven-git")) {
7978
mavenContainerRule.start();
8079
registerAgentForContainer(mavenContainerRule);
8180

@@ -100,8 +99,7 @@ public void testMavenBuildOnRemoteAgentWithSettingsFileOnMasterFails() throws Ex
10099

101100
@Test
102101
public void testDisableAllPublishers() throws Exception {
103-
try (GenericContainer<?> mavenContainerRule =
104-
new GenericContainer<>("localhost/pipeline-maven/java-maven-git").withExposedPorts(22)) {
102+
try (GenericContainer<?> mavenContainerRule = createContainer("java-maven-git")) {
105103
mavenContainerRule.start();
106104
registerAgentForContainer(mavenContainerRule);
107105
loadMonoDependencyMavenProjectInGitRepo(this.gitRepoRule);
@@ -135,8 +133,7 @@ private static Stream<Arguments> jdkMapProvider() {
135133
@MethodSource("jdkMapProvider")
136134
@Issue("JENKINS-71949")
137135
public void tesWithDifferentJavasForBuild(String jdkName, String jdkPath) throws Exception {
138-
try (GenericContainer<?> javasContainerRule =
139-
new GenericContainer<>("localhost/pipeline-maven/javas").withExposedPorts(22)) {
136+
try (GenericContainer<?> javasContainerRule = createContainer("javas")) {
140137
javasContainerRule.start();
141138
loadMonoDependencyMavenProjectInGitRepo(this.gitRepoRule);
142139
String gitRepoPath = this.gitRepoRule.toString();

pipeline-maven/src/test/java/org/jenkinsci/plugins/pipeline/maven/docker/JavaGitContainerTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
public class JavaGitContainerTest extends AbstractIntegrationTest {
3737

3838
@Container
39-
public GenericContainer<?> containerRule =
40-
new GenericContainer<>("localhost/pipeline-maven/java-git").withExposedPorts(22);
39+
public GenericContainer<?> containerRule = createContainer("java-git");
4140

4241
@Test
4342
public void smokes() throws Exception {
Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:noble
1+
FROM ubuntu:noble as base
22

33
# install SSHD
44
RUN apt-get update -y && \
@@ -24,3 +24,39 @@ ENV LANG en_US.UTF-8
2424

2525
# run SSHD in the foreground with error messages to stderr
2626
ENTRYPOINT ["/usr/sbin/sshd", "-D", "-e"]
27+
28+
FROM base as java-git
29+
30+
RUN apt-get update && \
31+
apt-get install --no-install-recommends -y \
32+
software-properties-common \
33+
openjdk-17-jdk-headless \
34+
curl \
35+
ant \
36+
git
37+
38+
FROM java-git as java-maven-git
39+
40+
RUN apt-get update && \
41+
apt-get install --no-install-recommends -y \
42+
maven
43+
44+
FROM java-maven-git as javas
45+
46+
COPY --from=eclipse-temurin:8u382-b05-jdk /opt/java/openjdk /opt/java/jdk8
47+
COPY --from=eclipse-temurin:11.0.20.1_1-jdk /opt/java/openjdk /opt/java/jdk11
48+
COPY --from=eclipse-temurin:17.0.8.1_1-jdk /opt/java/openjdk /opt/java/jdk17
49+
COPY --from=eclipse-temurin:21.0.6_7-jdk /opt/java/openjdk /opt/java/jdk21
50+
51+
FROM java-maven-git as maven-home
52+
53+
ENV MAVEN_HOME="/usr/share/maven"
54+
55+
# see https://www.jenkins.io/doc/book/using/using-agents/ and https://github.com/jenkinsci/docker-ssh-agent/issues/33
56+
# probably, it would be better to use the official image docker-ssh-agent as a base
57+
RUN VARS1="HOME=|USER=|MAIL=|LC_ALL=|LS_COLORS=|LANG=" \
58+
VARS2="HOSTNAME=|PWD=|TERM=|SHLVL=|LANGUAGE=|_=" \
59+
VARS="${VARS1}|${VARS2}" \
60+
env | egrep -v '^(${VARS})' >> /etc/environment
61+
62+

pipeline-maven/src/test/resources/org/jenkinsci/plugins/pipeline/maven/docker/JavaGitContainer/Dockerfile

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

pipeline-maven/src/test/resources/org/jenkinsci/plugins/pipeline/maven/docker/JavaMavenContainer/Dockerfile

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

pipeline-maven/src/test/resources/org/jenkinsci/plugins/pipeline/maven/docker/JavaMavenWithMavenHomeContainer/Dockerfile

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

pipeline-maven/src/test/resources/org/jenkinsci/plugins/pipeline/maven/docker/JavasContainer/Dockerfile

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

0 commit comments

Comments
 (0)