This is an automated email from the ASF dual-hosted git repository.
fmariani pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 1361eac1a46 camel-test-infra-cli: Make repository and jbang version
configurable
1361eac1a46 is described below
commit 1361eac1a46d72d699909af3e532f0ceb28673cc
Author: Marco Carletti <[email protected]>
AuthorDate: Mon Jan 27 14:21:09 2025 +0100
camel-test-infra-cli: Make repository and jbang version configurable
---
test-infra/camel-test-infra-cli/README.adoc | 6 +-
test-infra/camel-test-infra-cli/pom.xml | 49 +++++++++
.../camel/test/infra/cli/common/CliProperties.java | 5 +
.../camel/test/infra/cli/it/CliConfigITCase.java | 103 ++++++++++++++++++
.../test/infra/cli/services/CliBuiltContainer.java | 121 ++++++++++++++++++---
.../cli/services/CliLocalContainerService.java | 24 ++--
.../src/test/resources/logback-test.xml | 35 ++++++
.../camel/test/infra/cli/services/Dockerfile | 14 ++-
8 files changed, 328 insertions(+), 29 deletions(-)
diff --git a/test-infra/camel-test-infra-cli/README.adoc
b/test-infra/camel-test-infra-cli/README.adoc
index fa572f76eeb..a2eb86cfe7f 100644
--- a/test-infra/camel-test-infra-cli/README.adoc
+++ b/test-infra/camel-test-infra-cli/README.adoc
@@ -11,10 +11,12 @@ This module is used to build a container based on
{image-name} image and Camel J
System variables are defined in link:{config-class}[CliProperties]
- - `cli.service.version` : name of the branch of the repo
`https://github.com/apache/camel/` used to install Camel JBang, default `main`
+ - `cli.service.repo` : the repo on github, default `apache/camel`
+ - `cli.service.branch` : the branch of the repo on github, default `main`
+ - `cli.service.version` : the version of the `camel.jbang.version` and the
`camel-kamelets.version` defined in the `CamelJBang.java` file, default value
is `default`, it means it uses the default values in the file
- `cli.service.data.folder` : mandatory - path to local folder to bind as
volume in the container
- `cli.service.ssh.password` : ssh password set to access to the container
via ssh, default `jbang`
- - `cli.service.execute.version` : version set just after container start,
default is empty so the version is the one in the branch defined in
`cli.service.version`
+ - `cli.service.execute.version` : Camel version set just after container
start, default is empty so the version is the one in the branch
- `cli.service.mvn.repos` : comma separated list of custom Maven
repositories, default empty
- `cli.service.extra.hosts` : comma separated host=ip pairs to add in the
hosts file
- `cli.service.trusted.paths` : commas separated paths, relative to the host,
of the files containing PEM trusted certificates
diff --git a/test-infra/camel-test-infra-cli/pom.xml
b/test-infra/camel-test-infra-cli/pom.xml
index 1918cbd70a1..489c08d55ef 100644
--- a/test-infra/camel-test-infra-cli/pom.xml
+++ b/test-infra/camel-test-infra-cli/pom.xml
@@ -29,6 +29,10 @@
<artifactId>camel-test-infra-cli</artifactId>
<name>Camel :: Test Infra :: Cli (Camel JBang)</name>
+
+ <properties>
+ <maven.test.skip>false</maven.test.skip>
+ </properties>
<dependencies>
<dependency>
@@ -48,6 +52,32 @@
<artifactId>testcontainers</artifactId>
<version>${testcontainers-version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.junit-pioneer</groupId>
+ <artifactId>junit-pioneer</artifactId>
+ <version>${junit-pioneer-version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>${logback-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${logback-version}</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<build>
<plugins>
@@ -55,6 +85,25 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <systemPropertyVariables>
+
<cli.service.data.folder>target/data</cli.service.data.folder>
+
<currentProjectVersion>${project.version}</currentProjectVersion>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git
a/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/common/CliProperties.java
b/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/common/CliProperties.java
index 4280228da95..4a03e537046 100644
---
a/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/common/CliProperties.java
+++
b/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/common/CliProperties.java
@@ -18,6 +18,11 @@
package org.apache.camel.test.infra.cli.common;
public final class CliProperties {
+
+ public static final String REPO = "cli.service.repo";
+
+ public static final String BRANCH = "cli.service.branch";
+
public static final String VERSION = "cli.service.version";
public static final String DATA_FOLDER = "cli.service.data.folder";
diff --git
a/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/it/CliConfigITCase.java
b/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/it/CliConfigITCase.java
new file mode 100644
index 00000000000..00c01781eff
--- /dev/null
+++
b/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/it/CliConfigITCase.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.test.infra.cli.it;
+
+import java.util.function.Consumer;
+
+import org.apache.camel.test.infra.cli.services.CliService;
+import org.apache.camel.test.infra.cli.services.CliServiceFactory;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
+import org.junitpioneer.jupiter.ReadsSystemProperty;
+import org.junitpioneer.jupiter.RestoreSystemProperties;
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+@RestoreSystemProperties
+public class CliConfigITCase {
+
+ @Test
+ @SetSystemProperty(key = "cli.service.version", value = "4.8.3")
+ public void setJBangVersionTest() {
+ execute(cliService -> {
+ String version = cliService.version();
+ Assertions.assertEquals("4.8.3", version, "Check specific Camel
JBang version");
+ });
+ }
+
+ @Test
+ @SetSystemProperty(key = "cli.service.execute.version", value = "4.8.0")
+ public void setCamelVersionTest() {
+ execute(cliService -> {
+ String version = cliService.version();
+ Assertions.assertEquals("4.8.0", version, "Check specific Camel
version");
+ });
+ }
+
+ @Test
+ @SetSystemProperty(key = "cli.service.version", value = "4.8.3")
+ @SetSystemProperty(key = "cli.service.execute.version", value = "4.8.0")
+ public void setJBangAndCamelVersionTest() {
+ execute(cliService -> {
+ String version = cliService.version();
+ Assertions.assertEquals("4.8.0", version, "Check specific Camel
JBang and Camel version");
+ });
+ }
+
+ @Test
+ @SetSystemProperty(key = "cli.service.branch", value = "camel-4.4.x")
+ public void setBranchTest() {
+ execute(cliService -> {
+ String version = cliService.version();
+ Assertions.assertEquals("4.4.3", version, "Check Camel JBang
version in a specific branch");
+ });
+ }
+
+ @Test
+ @SetSystemProperty(key = "cli.service.repo", value =
"mcarlett/apache-camel")
+ @SetSystemProperty(key = "cli.service.branch", value = "camel-cli-test")
+ public void setRepoTest() {
+ execute(cliService -> {
+ String version = cliService.version();
+ Assertions.assertEquals("4.9.0", version, "Check Camel JBang
version in a specific repository");
+ });
+ }
+
+ @Test
+ @ReadsSystemProperty
+ @EnabledIfSystemProperty(named = "currentProjectVersion", matches =
"^(?!\\s*$).+",
+ disabledReason = "currentProjectVersion system
property must be set")
+ public void setCurrentProjectVersionTest() {
+ String currentCamelVersion =
System.getProperty("currentProjectVersion");
+ System.setProperty("cli.service.version", currentCamelVersion);
+ execute(cliService -> {
+ String version = cliService.version();
+ Assertions.assertEquals(currentCamelVersion, version, "Check Camel
JBang version in the current codebase");
+ });
+ System.clearProperty("cli.service.version");
+ }
+
+ private void execute(Consumer<CliService> consumer) {
+ try (CliService containerService = CliServiceFactory.createService()) {
+ containerService.beforeAll(null);
+ consumer.accept(containerService);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
diff --git
a/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/services/CliBuiltContainer.java
b/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/services/CliBuiltContainer.java
index cd33390fc81..847ff9a8ea0 100644
---
a/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/services/CliBuiltContainer.java
+++
b/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/services/CliBuiltContainer.java
@@ -33,6 +33,8 @@ import org.testcontainers.utility.MountableFile;
public class CliBuiltContainer extends GenericContainer<CliBuiltContainer> {
private static final String CAMEL_REF_ARG = "CAMEL_REF";
+ private static final String CAMEL_REPO_ARG = "CAMEL_REPO";
+ private static final String CAMEL_JBANG_VERSION_ARG =
"CAMEL_JBANG_VERSION";
private static final String KEEP_RUNNING_ARG = "KEEP_RUNNING";
private static final String MOUNT_POINT = "/deployments/data";
private static final String SSH_PASSWORD_ARG = "SSH_PASSWORD_ARG";
@@ -44,10 +46,11 @@ public class CliBuiltContainer extends
GenericContainer<CliBuiltContainer> {
private final String sshPassword;
- public CliBuiltContainer(final String camelRef, final Boolean
keepContainerRunning, final String dataFolder,
- final String sshPassword, final Map<String,
String> extraHosts,
- final List<String> trustedCertPaths) {
- super(new ImageFromDockerfile("localhost/camel-cli:" + camelRef +
(keepContainerRunning ? "-R" : ""), false)
+ public CliBuiltContainer(CliBuiltContainerParams params) {
+ super(new ImageFromDockerfile(
+ "localhost/camel-cli:" + params.getCamelRef() + "-" +
params.getCamelJBangVersion()
+ + (params.getKeepContainerRunning() ?
"-R" : ""),
+ false)
.withFileFromClasspath("Dockerfile",
"org/apache/camel/test/infra/cli/services/Dockerfile")
.withFileFromClasspath("entrypoint.sh",
@@ -55,22 +58,24 @@ public class CliBuiltContainer extends
GenericContainer<CliBuiltContainer> {
.withFileFromClasspath("99-ssh-jbang.conf",
"org/apache/camel/test/infra/cli/services/99-ssh-jbang.conf")
.withBuildArg(FROM_IMAGE_ARG,
TestUtils.prependHubImageNamePrefixIfNeeded(FROM_IMAGE_NAME))
- .withBuildArg(CAMEL_REF_ARG, camelRef)
- .withBuildArg(KEEP_RUNNING_ARG,
String.valueOf(keepContainerRunning))
- .withBuildArg(SSH_PASSWORD_ARG, sshPassword));
- this.sshPassword = sshPassword;
- if (StringUtils.isNotBlank(dataFolder)) {
- withFileSystemBind(dataFolder, MOUNT_POINT, BindMode.READ_WRITE);
- }
- if (keepContainerRunning) {
+ .withBuildArg(CAMEL_REF_ARG, params.getCamelRef())
+ .withBuildArg(KEEP_RUNNING_ARG,
String.valueOf(params.getKeepContainerRunning()))
+ .withBuildArg(SSH_PASSWORD_ARG, params.getSshPassword())
+ .withBuildArg(CAMEL_REPO_ARG, params.getCamelRepo())
+ .withBuildArg(CAMEL_JBANG_VERSION_ARG,
params.getCamelJBangVersion()));
+ this.sshPassword = params.getSshPassword();
+ if (StringUtils.isNotBlank(params.getDataFolder())) {
+ withFileSystemBind(params.getDataFolder(), MOUNT_POINT,
BindMode.READ_WRITE);
+ }
+ if (params.getKeepContainerRunning()) {
waitingFor(Wait.forLogMessage(".*keep container running.*", 1));
}
withExposedPorts(DEV_CONSOLE_PORT, SSH_PORT);
- if (Objects.nonNull(extraHosts)) {
- extraHosts.forEach((host, ip) -> withExtraHost(host, ip));
+ if (Objects.nonNull(params.getExtraHosts())) {
+ params.getExtraHosts().forEach((host, ip) -> withExtraHost(host,
ip));
}
- if (Objects.nonNull(trustedCertPaths)) {
- trustedCertPaths.forEach(t -> {
+ if (Objects.nonNull(params.getTrustedCertPaths())) {
+ params.getTrustedCertPaths().forEach(t -> {
final Path path = Paths.get(t);
withCopyToContainer(MountableFile.forHostPath(path),
String.format("%s/%s", TRUSTED_CERT_FOLDER,
path.getFileName()));
@@ -85,4 +90,88 @@ public class CliBuiltContainer extends
GenericContainer<CliBuiltContainer> {
public String getSshPassword() {
return sshPassword;
}
+
+ public static class CliBuiltContainerParams {
+
+ private String camelRepo;
+ private String camelRef;
+ private String camelJBangVersion;
+ private Boolean keepContainerRunning;
+ private String dataFolder;
+ private String sshPassword;
+ private Map<String, String> extraHosts;
+ private List<String> trustedCertPaths;
+
+ public String getCamelRepo() {
+ return camelRepo;
+ }
+
+ public CliBuiltContainerParams setCamelRepo(String camelRepo) {
+ this.camelRepo = camelRepo;
+ return this;
+ }
+
+ public String getCamelJBangVersion() {
+ return camelJBangVersion;
+ }
+
+ public CliBuiltContainerParams setCamelJBangVersion(String
camelJBangVersion) {
+ this.camelJBangVersion = camelJBangVersion;
+ return this;
+ }
+
+ public String getCamelRef() {
+ return camelRef;
+ }
+
+ public CliBuiltContainerParams setCamelRef(String camelRef) {
+ this.camelRef = camelRef;
+ return this;
+ }
+
+ public Boolean getKeepContainerRunning() {
+ return keepContainerRunning;
+ }
+
+ public CliBuiltContainerParams setKeepContainerRunning(Boolean
keepContainerRunning) {
+ this.keepContainerRunning = keepContainerRunning;
+ return this;
+ }
+
+ public String getDataFolder() {
+ return dataFolder;
+ }
+
+ public CliBuiltContainerParams setDataFolder(String dataFolder) {
+ this.dataFolder = dataFolder;
+ return this;
+ }
+
+ public String getSshPassword() {
+ return sshPassword;
+ }
+
+ public CliBuiltContainerParams setSshPassword(String sshPassword) {
+ this.sshPassword = sshPassword;
+ return this;
+ }
+
+ public Map<String, String> getExtraHosts() {
+ return extraHosts;
+ }
+
+ public CliBuiltContainerParams setExtraHosts(Map<String, String>
extraHosts) {
+ this.extraHosts = extraHosts;
+ return this;
+ }
+
+ public List<String> getTrustedCertPaths() {
+ return trustedCertPaths;
+ }
+
+ public CliBuiltContainerParams setTrustedCertPaths(List<String>
trustedCertPaths) {
+ this.trustedCertPaths = trustedCertPaths;
+ return this;
+ }
+ }
}
diff --git
a/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/services/CliLocalContainerService.java
b/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/services/CliLocalContainerService.java
index c7471a215c3..77dcf7a69d5 100644
---
a/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/services/CliLocalContainerService.java
+++
b/test-infra/camel-test-infra-cli/src/test/java/org/apache/camel/test/infra/cli/services/CliLocalContainerService.java
@@ -43,15 +43,21 @@ public class CliLocalContainerService implements
CliService, ContainerService<Cl
private String mavenRepos;
public CliLocalContainerService() {
- this(System.getProperty(CliProperties.VERSION, "main"), true,
System.getProperty(CliProperties.DATA_FOLDER),
- System.getProperty(CliProperties.SSH_PASSWORD, "jbang"),
System.getProperty(CliProperties.FORCE_RUN_VERSION, ""),
- System.getProperty(CliProperties.MVN_REPOS), getHostsMap(),
getCertPaths());
- }
-
- protected CliLocalContainerService(String camelRef, Boolean keepRunning,
String dataFolder, String sshPassword,
- String forceToRunVersion, String
mavenRepos, Map<String, String> extraHosts,
- List<String> trustedCertPaths) {
- container = new CliBuiltContainer(camelRef, keepRunning, dataFolder,
sshPassword, extraHosts, trustedCertPaths);
+ this(new CliBuiltContainer.CliBuiltContainerParams()
+ .setCamelRepo(System.getProperty(CliProperties.REPO,
"apache/camel"))
+ .setCamelRef(System.getProperty(CliProperties.BRANCH, "main"))
+
.setCamelJBangVersion(System.getProperty(CliProperties.VERSION, "default"))
+ .setKeepContainerRunning(true)
+ .setDataFolder(System.getProperty(CliProperties.DATA_FOLDER))
+ .setSshPassword(System.getProperty(CliProperties.SSH_PASSWORD,
"jbang"))
+ .setExtraHosts(getHostsMap())
+ .setTrustedCertPaths(getCertPaths()),
+ System.getProperty(CliProperties.FORCE_RUN_VERSION, ""),
System.getProperty(CliProperties.MVN_REPOS));
+ }
+
+ protected
CliLocalContainerService(CliBuiltContainer.CliBuiltContainerParams
containerParams,
+ String forceToRunVersion, String
mavenRepos) {
+ container = new CliBuiltContainer(containerParams);
this.forceToRunVersion = forceToRunVersion;
this.mavenRepos = mavenRepos;
}
diff --git
a/test-infra/camel-test-infra-cli/src/test/resources/logback-test.xml
b/test-infra/camel-test-infra-cli/src/test/resources/logback-test.xml
new file mode 100644
index 00000000000..169e12ec2f5
--- /dev/null
+++ b/test-infra/camel-test-infra-cli/src/test/resources/logback-test.xml
@@ -0,0 +1,35 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>[%highlight(%level)] %logger{36}.%M - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <root level="info">
+ <appender-ref ref="STDOUT"/>
+ </root>
+
+ <logger name="org.testcontainers" level="INFO"/>
+ <logger name="tc" level="INFO"/>
+ <logger name="com.github.dockerjava" level="WARN"/>
+ <logger
name="com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.wire"
level="OFF"/>
+ <logger name="org.apache.camel.test.infra" level="DEBUG"/>
+</configuration>
diff --git
a/test-infra/camel-test-infra-cli/src/test/resources/org/apache/camel/test/infra/cli/services/Dockerfile
b/test-infra/camel-test-infra-cli/src/test/resources/org/apache/camel/test/infra/cli/services/Dockerfile
index 2ecbc46ba0e..a763192b8ed 100644
---
a/test-infra/camel-test-infra-cli/src/test/resources/org/apache/camel/test/infra/cli/services/Dockerfile
+++
b/test-infra/camel-test-infra-cli/src/test/resources/org/apache/camel/test/infra/cli/services/Dockerfile
@@ -19,7 +19,9 @@ ARG FROMIMAGE
FROM $FROMIMAGE
+ARG CAMEL_JBANG_VERSION=default
ARG CAMEL_REF=main
+ARG CAMEL_REPO=apache/camel
ARG KEEP_RUNNING=true
ARG SSH_PASSWORD=jbang
@@ -50,8 +52,16 @@ RUN echo "Installing JBang..."
RUN curl -Ls https://sh.jbang.dev | bash -s - app setup \
&& source ~/.bashrc \
&& jbang version --update \
- && jbang trust add https://github.com/apache/camel/ \
- && jbang app install camel@apache/camel/$CAMEL_REF
+ && jbang trust add https://github.com/$CAMEL_REPO/ \
+
+RUN echo "Using JBang $CAMEL_JBANG_VERSION version from $CAMEL_REPO/$CAMEL_REF"
+RUN source ~/.bashrc \
+ && if [[ "$CAMEL_JBANG_VERSION" == "default" ]] ; \
+ then jbang app install camel@$CAMEL_REPO/$CAMEL_REF ; \
+ else jbang app install \
+ -Dcamel.jbang.version=$CAMEL_JBANG_VERSION \
+ -Dcamel-kamelets.version=$CAMEL_JBANG_VERSION \
+ camel@$CAMEL_REPO/$CAMEL_REF ; fi
LABEL "camel.ref"=$CAMEL_REF
LABEL "keep.container.running"=$KEEP_RUNNING