You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by va...@apache.org on 2021/02/11 15:40:32 UTC

[camel] 01/02: fixed CAMEL-16182: test-infra modules don't support testcontainers hub.image.name.prefix configuration.

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

valdar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit dc28e3b1b23c710e7bbdbf15296ee885cb7c398e
Author: Andrea Tarocchi <an...@gmail.com>
AuthorDate: Thu Feb 11 01:49:30 2021 +0100

    fixed CAMEL-16182: test-infra modules don't support testcontainers hub.image.name.prefix configuration.
---
 .../camel/test/infra/artemis/services/ArtemisContainer.java   |  8 ++++++--
 .../org/apache/camel/test/infra/artemis/services/Dockerfile   |  3 ++-
 .../java/org/apache/camel/test/infra/common/TestUtils.java    | 11 +++++++++++
 .../dispatch/router/services/DispatchRouterContainer.java     |  8 ++++++--
 .../camel/test/infra/dispatch/router/services/Dockerfile      |  3 ++-
 .../test/infra/hdfs/v2/services/HadoopBaseContainer.java      | 10 ++++++++--
 .../org/apache/camel/test/infra/hdfs/v2/services/Dockerfile   |  8 +++++---
 7 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/test-infra/camel-test-infra-artemis/src/test/java/org/apache/camel/test/infra/artemis/services/ArtemisContainer.java b/test-infra/camel-test-infra-artemis/src/test/java/org/apache/camel/test/infra/artemis/services/ArtemisContainer.java
index 50353ed..d1fb6b4 100644
--- a/test-infra/camel-test-infra-artemis/src/test/java/org/apache/camel/test/infra/artemis/services/ArtemisContainer.java
+++ b/test-infra/camel-test-infra-artemis/src/test/java/org/apache/camel/test/infra/artemis/services/ArtemisContainer.java
@@ -17,6 +17,7 @@
 
 package org.apache.camel.test.infra.artemis.services;
 
+import org.apache.camel.test.infra.common.TestUtils;
 import org.apache.camel.test.infra.messaging.services.MessagingContainer;
 import org.testcontainers.containers.GenericContainer;
 import org.testcontainers.containers.wait.strategy.Wait;
@@ -27,11 +28,14 @@ public class ArtemisContainer extends GenericContainer<ArtemisContainer> impleme
     private static final int DEFAULT_AMQP_PORT = 5672;
     private static final int DEFAULT_ADMIN_PORT = 8161;
     private static final int DEFAULT_ACCEPTOR_PORT = 61616;
+    private static final String FROM_IMAGE_NAME = "fedora:33";
+    private static final String FROM_IMAGE_ARG = "FROMIMAGE";
 
     public ArtemisContainer() {
-        super(new ImageFromDockerfile("apache-artemis:ckc", false)
+        super(new ImageFromDockerfile("localhost/apache-artemis:ckc", false)
                 .withFileFromClasspath("Dockerfile",
-                        "org/apache/camel/test/infra/artemis/services/Dockerfile"));
+                        "org/apache/camel/test/infra/artemis/services/Dockerfile")
+                .withBuildArg(FROM_IMAGE_ARG, TestUtils.prependHubImageNamePrefixIfNeeded(FROM_IMAGE_NAME)));
 
         withExposedPorts(DEFAULT_MQTT_PORT, DEFAULT_AMQP_PORT,
                 DEFAULT_ADMIN_PORT, DEFAULT_ACCEPTOR_PORT);
diff --git a/test-infra/camel-test-infra-artemis/src/test/resources/org/apache/camel/test/infra/artemis/services/Dockerfile b/test-infra/camel-test-infra-artemis/src/test/resources/org/apache/camel/test/infra/artemis/services/Dockerfile
index f0b4a18..e366df4 100644
--- a/test-infra/camel-test-infra-artemis/src/test/resources/org/apache/camel/test/infra/artemis/services/Dockerfile
+++ b/test-infra/camel-test-infra-artemis/src/test/resources/org/apache/camel/test/infra/artemis/services/Dockerfile
@@ -12,7 +12,8 @@
 #  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.
-FROM fedora:33 as artemis-base
+ARG FROMIMAGE
+FROM $FROMIMAGE as artemis-base
 LABEL maintainer="orpiske@apache.org"
 ARG ARTEMIS_VERSION
 ENV ARTEMIS_VERSION ${ARTEMIS_VERSION:-2.7.0}
diff --git a/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/TestUtils.java b/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/TestUtils.java
index e2d3962..e679285 100644
--- a/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/TestUtils.java
+++ b/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/TestUtils.java
@@ -22,6 +22,7 @@ import java.util.function.Predicate;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.testcontainers.utility.TestcontainersConfiguration;
 
 /**
  * Test utilities
@@ -101,4 +102,14 @@ public final class TestUtils {
 
         return (int) (Math.random() * range) + min;
     }
+
+    /**
+     * Prepend imageName with configured hub.image.name.prefix if any is configured in testcontainers
+     *
+     * @param  imageName
+     * @return           a String composed of hub.image.name.prefix as configured in testcontainers + imageName
+     */
+    public static String prependHubImageNamePrefixIfNeeded(String imageName) {
+        return TestcontainersConfiguration.getInstance().getEnvVarOrProperty("hub.image.name.prefix", "") + imageName;
+    }
 }
diff --git a/test-infra/camel-test-infra-dispatch-router/src/test/java/org/apache/camel/test/infra/dispatch/router/services/DispatchRouterContainer.java b/test-infra/camel-test-infra-dispatch-router/src/test/java/org/apache/camel/test/infra/dispatch/router/services/DispatchRouterContainer.java
index c1e96b8..f55fc66 100644
--- a/test-infra/camel-test-infra-dispatch-router/src/test/java/org/apache/camel/test/infra/dispatch/router/services/DispatchRouterContainer.java
+++ b/test-infra/camel-test-infra-dispatch-router/src/test/java/org/apache/camel/test/infra/dispatch/router/services/DispatchRouterContainer.java
@@ -17,6 +17,7 @@
 
 package org.apache.camel.test.infra.dispatch.router.services;
 
+import org.apache.camel.test.infra.common.TestUtils;
 import org.apache.camel.test.infra.messaging.services.MessagingContainer;
 import org.testcontainers.containers.GenericContainer;
 import org.testcontainers.containers.wait.strategy.Wait;
@@ -24,11 +25,14 @@ import org.testcontainers.images.builder.ImageFromDockerfile;
 
 public class DispatchRouterContainer extends GenericContainer<DispatchRouterContainer> implements MessagingContainer {
     private static final int DEFAULT_AMQP_PORT = 5672;
+    private static final String FROM_IMAGE_NAME = "fedora:33";
+    private static final String FROM_IMAGE_ARG = "FROMIMAGE";
 
     public DispatchRouterContainer() {
-        super(new ImageFromDockerfile("qpid-dispatch:camel", false)
+        super(new ImageFromDockerfile("localhost/qpid-dispatch:camel", false)
                 .withFileFromClasspath("Dockerfile",
-                        "org/apache/camel/test/infra/dispatch/router/services/Dockerfile"));
+                        "org/apache/camel/test/infra/dispatch/router/services/Dockerfile")
+                .withBuildArg(FROM_IMAGE_ARG, TestUtils.prependHubImageNamePrefixIfNeeded(FROM_IMAGE_NAME)));
 
         withExposedPorts(DEFAULT_AMQP_PORT);
 
diff --git a/test-infra/camel-test-infra-dispatch-router/src/test/resources/org/apache/camel/test/infra/dispatch/router/services/Dockerfile b/test-infra/camel-test-infra-dispatch-router/src/test/resources/org/apache/camel/test/infra/dispatch/router/services/Dockerfile
index b70fe96..339ae7e 100644
--- a/test-infra/camel-test-infra-dispatch-router/src/test/resources/org/apache/camel/test/infra/dispatch/router/services/Dockerfile
+++ b/test-infra/camel-test-infra-dispatch-router/src/test/resources/org/apache/camel/test/infra/dispatch/router/services/Dockerfile
@@ -12,7 +12,8 @@
 #  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.
-FROM fedora:33
+ARG FROMIMAGE
+FROM $FROMIMAGE
 LABEL maintainer="orpiske@apache.org"
 EXPOSE 5672
 RUN dnf install -y qpid-dispatch-router && dnf clean all
diff --git a/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/HadoopBaseContainer.java b/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/HadoopBaseContainer.java
index 908602b..402599f 100644
--- a/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/HadoopBaseContainer.java
+++ b/test-infra/camel-test-infra-hdfs/src/test/java/org/apache/camel/test/infra/hdfs/v2/services/HadoopBaseContainer.java
@@ -17,16 +17,22 @@
 
 package org.apache.camel.test.infra.hdfs.v2.services;
 
+import org.apache.camel.test.infra.common.TestUtils;
 import org.testcontainers.containers.GenericContainer;
 import org.testcontainers.containers.Network;
 import org.testcontainers.images.builder.ImageFromDockerfile;
 
 abstract class HadoopBaseContainer<T extends GenericContainer<T>> extends GenericContainer<T> {
+    private static final String FROM_IMAGE_NAME = "fedora:33";
+    private static final String FROM_IMAGE_BUILDER_ARG = "FROMIMAGE_BUILDER";
+    private static final String FROM_IMAGE_ARG = "FROMIMAGE";
 
     public HadoopBaseContainer(Network network, String name) {
-        super(new ImageFromDockerfile("hadoop-2x:ckc", false)
+        super(new ImageFromDockerfile("localhost/hadoop-2x:ckc", false)
                 .withFileFromClasspath(".",
-                        "org/apache/camel/test/infra/hdfs/v2/services/"));
+                        "org/apache/camel/test/infra/hdfs/v2/services/")
+                .withBuildArg(FROM_IMAGE_BUILDER_ARG, TestUtils.prependHubImageNamePrefixIfNeeded(FROM_IMAGE_NAME))
+                .withBuildArg(FROM_IMAGE_ARG, TestUtils.prependHubImageNamePrefixIfNeeded(FROM_IMAGE_NAME)));
 
         withNetwork(network);
 
diff --git a/test-infra/camel-test-infra-hdfs/src/test/resources/org/apache/camel/test/infra/hdfs/v2/services/Dockerfile b/test-infra/camel-test-infra-hdfs/src/test/resources/org/apache/camel/test/infra/hdfs/v2/services/Dockerfile
index bc99e76..1ed4497 100644
--- a/test-infra/camel-test-infra-hdfs/src/test/resources/org/apache/camel/test/infra/hdfs/v2/services/Dockerfile
+++ b/test-infra/camel-test-infra-hdfs/src/test/resources/org/apache/camel/test/infra/hdfs/v2/services/Dockerfile
@@ -12,8 +12,9 @@
 #  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.
-
-FROM fedora:33 as builder
+ARG FROMIMAGE_BUILDER
+ARG FROMIMAGE
+FROM ${FROMIMAGE_BUILDER} as builder
 ARG HADOOP_VERSION
 ENV HADOOP_VERSION ${HADOOP_VERSION:-2.10.0}
 RUN curl https://archive.apache.org/dist/hadoop/common/hadoop-${HADOOP_VERSION}/hadoop-${HADOOP_VERSION}.tar.gz -o hadoop.tar.gz
@@ -23,7 +24,8 @@ ADD hdfs-site.xml /hadoop/etc/hadoop/hdfs-site.xml
 ADD run-datanode.sh /hadoop
 ADD run-namenode.sh /hadoop
 
-FROM fedora:33
+ARG FROMIMAGE
+FROM $FROMIMAGE
 LABEL maintainer="orpiske@apache.org"
 ARG HADOOP_VERSION
 ENV HADOOP_VERSION ${HADOOP_VERSION:-2.10.0}