You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2024/01/31 09:13:18 UTC

(camel) branch main updated: CAMEL-20379: Camel CLI infra, add maven repos config (#12955)

This is an automated email from the ASF dual-hosted git repository.

davsclaus 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 c872e8656b1 CAMEL-20379: Camel CLI infra, add maven repos config (#12955)
c872e8656b1 is described below

commit c872e8656b157afc76a4ae073569b0c1e20d3165
Author: Marco Carletti <mc...@redhat.com>
AuthorDate: Wed Jan 31 10:13:11 2024 +0100

    CAMEL-20379: Camel CLI infra, add maven repos config (#12955)
---
 dsl/camel-jbang/camel-jbang-it/README.adoc         |  7 +++++
 .../dsl/jbang/it/support/JBangTestSupport.java     | 13 +++++----
 test-infra/camel-test-infra-cli/README.adoc        |  3 ++
 .../camel/test/infra/cli/common/CliProperties.java |  6 ++++
 .../test/infra/cli/services/CliBuiltContainer.java | 21 +++++++++++++-
 .../cli/services/CliLocalContainerService.java     | 33 ++++++++++++++++++++--
 .../camel/test/infra/cli/services/Dockerfile       |  4 ++-
 .../camel/test/infra/cli/services/entrypoint.sh    |  3 ++
 8 files changed, 80 insertions(+), 10 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-it/README.adoc b/dsl/camel-jbang/camel-jbang-it/README.adoc
index cca49cd03d2..274c9d1bace 100644
--- a/dsl/camel-jbang/camel-jbang-it/README.adoc
+++ b/dsl/camel-jbang/camel-jbang-it/README.adoc
@@ -12,3 +12,10 @@ To run tests use the dedicated Maven profile `jbang-it-test` activated by the sa
 ----
 mvn verify -Djbang-it-test
 ----
+
+== Configuration
+
+Camel CLI infra configuration is defined in link:../../../test-infra/camel-test-infra-cli/README.adoc[README.adoc]
+
+- `jbang.it.assert.wait.timeout` : timeout in seconds for log assertions, default `60`
+
diff --git a/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/support/JBangTestSupport.java b/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/support/JBangTestSupport.java
index 08b99d67497..e0c7e578b20 100644
--- a/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/support/JBangTestSupport.java
+++ b/dsl/camel-jbang/camel-jbang-it/src/test/java/org/apache/camel/dsl/jbang/it/support/JBangTestSupport.java
@@ -51,6 +51,9 @@ public abstract class JBangTestSupport {
 
     private static final String DATA_FOLDER = System.getProperty(CliProperties.DATA_FOLDER);
 
+    protected static final int ASSERTION_WAIT_SECONDS
+            = Integer.parseInt(System.getProperty("jbang.it.assert.wait.timeout", "60"));
+
     protected static final String DEFAULT_ROUTE_FOLDER = "/home/jbang";
 
     public static final String DEFAULT_MSG = "Hello Camel from";
@@ -138,7 +141,7 @@ public abstract class JBangTestSupport {
     }
 
     protected void checkLogContainsAllOf(String... contains) {
-        checkLogContainsAllOf(60, contains);
+        checkLogContainsAllOf(ASSERTION_WAIT_SECONDS, contains);
     }
 
     protected void checkLogContainsAllOf(int waitForSeconds, String... contains) {
@@ -149,11 +152,11 @@ public abstract class JBangTestSupport {
     }
 
     protected void checkLogContains(String contains) {
-        checkLogContains(contains, 60);
+        checkLogContains(contains, ASSERTION_WAIT_SECONDS);
     }
 
     protected void checkLogContains(String route, String contains) {
-        checkLogContains(route, contains, 60);
+        checkLogContains(route, contains, ASSERTION_WAIT_SECONDS);
     }
 
     protected void checkLogContains(String contains, int waitForSeconds) {
@@ -169,11 +172,11 @@ public abstract class JBangTestSupport {
     }
 
     protected void checkLogContainsPattern(String contains) {
-        checkLogContainsPattern(contains, 60);
+        checkLogContainsPattern(contains, ASSERTION_WAIT_SECONDS);
     }
 
     protected void checkLogContainsPattern(String route, String contains) {
-        checkLogContainsPattern(route, contains, 60);
+        checkLogContainsPattern(route, contains, ASSERTION_WAIT_SECONDS);
     }
 
     protected void checkLogContainsPattern(String contains, int waitForSeconds) {
diff --git a/test-infra/camel-test-infra-cli/README.adoc b/test-infra/camel-test-infra-cli/README.adoc
index 6ce981321ad..fa572f76eeb 100644
--- a/test-infra/camel-test-infra-cli/README.adoc
+++ b/test-infra/camel-test-infra-cli/README.adoc
@@ -15,3 +15,6 @@ System variables are defined in link:{config-class}[CliProperties]
  - `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.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/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 d42b7a4fa2b..4280228da95 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
@@ -26,6 +26,12 @@ public final class CliProperties {
 
     public static final String FORCE_RUN_VERSION = "cli.service.execute.version";
 
+    public static final String MVN_REPOS = "cli.service.mvn.repos";
+
+    public static final String EXTRA_HOSTS = "cli.service.extra.hosts";
+
+    public static final String TRUSTED_CERT_PATHS = "cli.service.trusted.paths";
+
     private CliProperties() {
     }
 }
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 f397581aa97..09f937a0e38 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
@@ -16,12 +16,19 @@
  */
 package org.apache.camel.test.infra.cli.services;
 
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
 import org.apache.camel.test.infra.common.TestUtils;
 import org.junit.platform.commons.util.StringUtils;
 import org.testcontainers.containers.BindMode;
 import org.testcontainers.containers.GenericContainer;
 import org.testcontainers.containers.wait.strategy.Wait;
 import org.testcontainers.images.builder.ImageFromDockerfile;
+import org.testcontainers.utility.MountableFile;
 
 public class CliBuiltContainer extends GenericContainer<CliBuiltContainer> {
 
@@ -33,11 +40,13 @@ public class CliBuiltContainer extends GenericContainer<CliBuiltContainer> {
     private static final String FROM_IMAGE_ARG = "FROMIMAGE";
     protected static final int DEV_CONSOLE_PORT = 8080;
     protected static final int SSH_PORT = 22;
+    protected static final String TRUSTED_CERT_FOLDER = "/etc/pki/ca-trust/source/anchors";
 
     private final String sshPassword;
 
     public CliBuiltContainer(final String camelRef, final Boolean keepContainerRunning, final String dataFolder,
-                             final String sshPassword) {
+                             final String sshPassword, final Map<String, String> extraHosts,
+                             final List<String> trustedCertPaths) {
         super(new ImageFromDockerfile("localhost/camel-cli:" + camelRef + (keepContainerRunning ? "-R" : ""), false)
                 .withFileFromClasspath("Dockerfile",
                         "org/apache/camel/test/infra/cli/services/Dockerfile")
@@ -57,6 +66,16 @@ public class CliBuiltContainer extends GenericContainer<CliBuiltContainer> {
             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(trustedCertPaths)) {
+            trustedCertPaths.forEach(t -> {
+                final Path path = Paths.get(t);
+                withCopyToContainer(MountableFile.forHostPath(path),
+                        String.format("%s/%s", TRUSTED_CERT_FOLDER, path.getFileName()));
+            });
+        }
     }
 
     public String getMountPoint() {
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 9cde137297c..b16af9b6547 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
@@ -18,7 +18,10 @@ package org.apache.camel.test.infra.cli.services;
 
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
 import java.util.Optional;
+import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 import org.apache.camel.test.infra.cli.common.CliProperties;
@@ -37,15 +40,20 @@ public class CliLocalContainerService implements CliService, ContainerService<Cl
 
     private String forceToRunVersion;
 
+    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.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) {
-        container = new CliBuiltContainer(camelRef, keepRunning, dataFolder, sshPassword);
+                                       String forceToRunVersion, String mavenRepos, Map<String, String> extraHosts,
+                                       List<String> trustedCertPaths) {
+        container = new CliBuiltContainer(camelRef, keepRunning, dataFolder, sshPassword, extraHosts, trustedCertPaths);
         this.forceToRunVersion = forceToRunVersion;
+        this.mavenRepos = mavenRepos;
     }
 
     @Override
@@ -65,6 +73,10 @@ public class CliLocalContainerService implements CliService, ContainerService<Cl
                 LOG.info("force to use version {}", forceToRunVersion);
                 execute("version set " + forceToRunVersion);
             }
+            if (StringUtils.isNotBlank(mavenRepos)) {
+                LOG.info("set repositories {}", mavenRepos);
+                execute(String.format("config set repos=%s", mavenRepos));
+            }
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Camel JBang version {}", version());
             }
@@ -180,4 +192,19 @@ public class CliLocalContainerService implements CliService, ContainerService<Cl
     public String getSshPassword() {
         return container.getSshPassword();
     }
+
+    private static Map<String, String> getHostsMap() {
+        return Optional.ofNullable(System.getProperty(CliProperties.EXTRA_HOSTS))
+                .map(p -> p.split(","))
+                .stream().flatMap(strings -> Arrays.asList(strings).stream())
+                .map(s -> s.split("="))
+                .collect(Collectors.toMap(entry -> entry[0], entry -> entry[1]));
+    }
+
+    private static List<String> getCertPaths() {
+        return Optional.ofNullable(System.getProperty(CliProperties.TRUSTED_CERT_PATHS))
+                .map(p -> p.split(","))
+                .stream().flatMap(strings -> Arrays.asList(strings).stream())
+                .collect(Collectors.toList());
+    }
 }
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 c6bf569329a..cd55278fac5 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
@@ -25,7 +25,7 @@ ARG SSH_PASSWORD=jbang
 
 #update os and install tools
 RUN dnf update -y \
-    && dnf install java-17-openjdk openssh-server xauth -y
+    && dnf install java-17-openjdk-devel openssh-server xauth -y
 
 RUN ssh-keygen -A
 
@@ -44,6 +44,8 @@ USER jbang
 ENV HOME=/home/jbang
 WORKDIR $HOME
 
+ENV JAVA_HOME=/usr/lib/jvm/java
+
 RUN curl -Ls https://sh.jbang.dev | bash -s - app setup \
     && source ~/.bashrc \
     && jbang version --update \
diff --git a/test-infra/camel-test-infra-cli/src/test/resources/org/apache/camel/test/infra/cli/services/entrypoint.sh b/test-infra/camel-test-infra-cli/src/test/resources/org/apache/camel/test/infra/cli/services/entrypoint.sh
index 3ba622c1579..52d5882dd4a 100644
--- a/test-infra/camel-test-infra-cli/src/test/resources/org/apache/camel/test/infra/cli/services/entrypoint.sh
+++ b/test-infra/camel-test-infra-cli/src/test/resources/org/apache/camel/test/infra/cli/services/entrypoint.sh
@@ -16,6 +16,9 @@
 # limitations under the License.
 #
 
+#upated trusted certificates
+su - root -c "update-ca-trust"
+
 if [ "$KEEP_RUNNING" == "true" ]; then
     echo "keep container running"
     su - root -c "/usr/sbin/sshd -D"