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 c4af988f4cde CAMEL-25430: camel infra run shows the progress of
pulling the container image (#27537)
c4af988f4cde is described below
commit c4af988f4cde14195b8c5f47af426e612d6ae83f
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Oct 8 09:35:52 2026 +0200
CAMEL-25430: camel infra run shows the progress of pulling the container
image (#27537)
* CAMEL-25430: camel infra run shows the progress of pulling the container
image
camel infra run never configured logging, so log4j ran on its default
configuration at level ERROR and the pull progress of Testcontainers
was lost: a first start that pulls a large image printed nothing for
minutes. It now prints the pull messages of Testcontainers as plain
lines, and nothing else of its logging.
The camel-jbang monitor, which keeps the output of the camel infra run
it starts, shows the progress while the service starts, such as
"Pulling image of ollama: 2 of 5 layers, 1.2 GB of 3.4 GB (35%)". The
total is known only once Docker has reported the size of every layer;
until then it shows the layers and the size pulled.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
* CAMEL-25430: review nits: integer size units, say why one pull message is
left out
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
---------
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
---
.../dsl/jbang/core/commands/infra/InfraRun.java | 8 +++
.../src/main/resources/log4j2-infra.properties | 45 +++++++++++++++
.../dsl/jbang/core/commands/tui/LaunchManager.java | 65 ++++++++++++++++++++++
.../core/commands/tui/LaunchManagerInfraTest.java | 44 +++++++++++++++
4 files changed, 162 insertions(+)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/infra/InfraRun.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/infra/InfraRun.java
index 244707de8287..993284c2e2b0 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/infra/InfraRun.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/infra/InfraRun.java
@@ -19,6 +19,7 @@ package org.apache.camel.dsl.jbang.core.commands.infra;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
+import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -37,6 +38,7 @@ import org.apache.camel.dsl.jbang.core.common.RuntimeUtil;
import org.apache.camel.main.download.DependencyDownloaderClassLoader;
import org.apache.camel.main.download.MavenDependencyDownloader;
import org.apache.camel.tooling.maven.MavenArtifact;
+import org.apache.logging.log4j.core.config.Configurator;
import picocli.CommandLine;
import static
org.apache.camel.dsl.jbang.core.commands.RunHelper.addCamelCLICommand;
@@ -197,6 +199,12 @@ public class InfraRun extends InfraBaseCommand {
}
if (!jsonOutput) {
+ // show the progress of pulling the container image, which can
take minutes the first time
+ // (logging may have started already with the default
configuration, so reconfigure it)
+ URL logConfig =
InfraRun.class.getClassLoader().getResource("log4j2-infra.properties");
+ if (logConfig != null) {
+ Configurator.reconfigure(logConfig.toURI());
+ }
String prefix = "";
if (testServiceImplementation != null) {
prefix = " with implementation " + testServiceImplementation;
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/resources/log4j2-infra.properties
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/log4j2-infra.properties
new file mode 100644
index 000000000000..23ad7b86df04
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/resources/log4j2-infra.properties
@@ -0,0 +1,45 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+# camel infra run: the progress of pulling the container image, as plain
lines, and errors
+status = warn
+name = CamelInfraLog4jConfiguration
+
+appender.out.type = Console
+appender.out.name = out
+appender.out.layout.type = PatternLayout
+appender.out.layout.pattern = %m%n
+
+appender.pull.type = Console
+appender.pull.name = pull
+appender.pull.layout.type = PatternLayout
+appender.pull.layout.pattern = %m%n
+# only the pull messages of Testcontainers, not the creating and starting of
the container
+# (not "Starting to pull image" either: it repeats the "Pulling docker image"
line just before it)
+appender.pull.filter.pull.type = RegexFilter
+appender.pull.filter.pull.regex = (Pulling docker image|Pulling image
layers|Pull complete|Retrying pull|Failed to pull|Docker image pull).*
+appender.pull.filter.pull.onMatch = ACCEPT
+appender.pull.filter.pull.onMismatch = DENY
+
+rootLogger.level = error
+rootLogger.appenderRef.out.ref = out
+
+# Testcontainers logs the pull of an image on the logger tc.<image>
+logger.tc.name = tc
+logger.tc.level = info
+logger.tc.additivity = false
+logger.tc.appenderRef.pull.ref = pull
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManager.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManager.java
index f5e1bea720dd..0dded3a0874d 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManager.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManager.java
@@ -477,6 +477,11 @@ class LaunchManager {
}
it.remove();
} else if (pl.infraAlias != null) {
+ // a first start pulls the image, which can take minutes: show
how far it got
+ if (pl.pullProgress != null &&
!pl.pullProgress.equals(pl.shownPullProgress)) {
+ notify("Pulling image of " + pl.name + ": " +
pl.pullProgress, false);
+ pl.shownPullProgress = pl.pullProgress;
+ }
if (now - pl.startTime > INFRA_WATCH_MS) {
// not up after the longest an image pull should take: a
failed start, as the other ends record
outcomes.put(pl.name, LaunchOutcome.failed(pl.outputFile));
@@ -559,6 +564,57 @@ class LaunchManager {
/** What Camel prints when it has started, whatever the runtime: the start
did not fail. */
static final Pattern STARTED = Pattern.compile("Apache Camel \\S+ \\(.*\\)
started in");
+ /** What camel infra run prints while it pulls the image of a service (the
pull progress of Testcontainers). */
+ static final Pattern PULL_PROGRESS = Pattern.compile(
+ "Pulling image layers:\\s*(\\d+) pending,\\s*(\\d+)
downloaded,\\s*\\d+ extracted, \\((.+?)/(.+?)\\)");
+ private static final Pattern SIZE = Pattern.compile("(\\d+(?:\\.\\d+)?)
(bytes|KB|MB|GB|TB)");
+
+ /**
+ * The progress of an image pull in the given output, from its last
progress line, such as {@code 2 of 4 layers,
+ * 22 MB}, or {@code 2 of 4 layers, 1 GB of 3 GB (33%)} once the total is
known: Docker reports the size of a layer
+ * only when it starts on it. Null when the output has no progress, or the
pull has completed since.
+ */
+ static String pullProgress(String text) {
+ var m = PULL_PROGRESS.matcher(text);
+ String answer = null;
+ int last = -1;
+ while (m.find()) {
+ last = m.start();
+ int pending = Integer.parseInt(m.group(1));
+ int downloaded = Integer.parseInt(m.group(2));
+ String done = m.group(3).trim();
+ String total = m.group(4).trim();
+ if (pending + downloaded == 0) {
+ // no layer reported yet
+ continue;
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append(downloaded).append(" of ").append(pending +
downloaded).append(" layers, ").append(done);
+ long doneBytes = bytes(done);
+ long totalBytes = bytes(total);
+ if (doneBytes >= 0 && totalBytes > 0) {
+ sb.append(" of ").append(total).append("
(").append(Math.min(100, doneBytes * 100 / totalBytes))
+ .append("%)");
+ }
+ answer = sb.toString();
+ }
+ if (answer != null && text.lastIndexOf("Pull complete") > last) {
+ return null;
+ }
+ return answer;
+ }
+
+ /** The bytes of a size as Testcontainers prints it (such as 22 MB), or -1
when it is not known (? MB). */
+ private static long bytes(String size) {
+ var m = SIZE.matcher(size);
+ if (!m.matches()) {
+ return -1;
+ }
+ double n = Double.parseDouble(m.group(1));
+ int power = List.of("bytes", "KB", "MB", "GB",
"TB").indexOf(m.group(2));
+ return (long) (n * (1L << (10 * power)));
+ }
+
/** A started process, watched until it is up for a while, ends, or fails
to start. */
static final class PendingLaunch {
final String name;
@@ -570,6 +626,9 @@ class LaunchManager {
boolean announced;
// Camel said it started: the launch is no longer watched for a failed
start
boolean started;
+ // the progress of pulling the image of an infra service, and the one
last shown
+ String pullProgress;
+ String shownPullProgress;
private long offset;
PendingLaunch(String name, Process process, Path outputFile, long
startTime) {
@@ -600,6 +659,12 @@ class LaunchManager {
return true;
}
started |= STARTED.matcher(text).find();
+ if (text.contains("Pull")) {
+ String progress = pullProgress(text);
+ if (progress != null || text.contains("Pull complete")) {
+ pullProgress = progress;
+ }
+ }
return false;
} catch (IOException e) {
return false;
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManagerInfraTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManagerInfraTest.java
index e3befe7d9ff0..583e079227f5 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManagerInfraTest.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManagerInfraTest.java
@@ -112,6 +112,50 @@ class LaunchManagerInfraTest {
assertThat(notices).contains("Not started: mqtt (its infra services
failed to start)");
}
+ @Test
+ void thePullProgressOfAnImage() {
+ // the total is not known until Docker has reported the size of every
layer
+ assertThat(LaunchManager.pullProgress("""
+ Pulling docker image: mirror.gcr.io/openfga/openfga:v1.21.0.
Please be patient
+ Pulling image layers: 0 pending, 0 downloaded, 0 extracted,
(0 bytes/0 bytes)
+ Pulling image layers: 2 pending, 2 downloaded, 1 extracted,
(21 MB/? MB)
+ """)).isEqualTo("2 of 4 layers, 21 MB");
+ assertThat(LaunchManager.pullProgress(
+ "Pulling image layers: 3 pending, 2 downloaded, 0
extracted, (1.2 GB/3.4 GB)"))
+ .isEqualTo("2 of 5 layers, 1.2 GB of 3.4 GB (35%)");
+ // nothing pulled yet, and a pull that has completed
+ assertThat(LaunchManager.pullProgress(
+ "Pulling image layers: 0 pending, 0 downloaded, 0
extracted, (0 bytes/0 bytes)")).isNull();
+ assertThat(LaunchManager.pullProgress("""
+ Pulling image layers: 1 pending, 3 downloaded, 3 extracted,
(22 MB/? MB)
+ Pull complete. 4 layers, pulled in 3s (downloaded 22 MB at 7
MB/s)
+ """)).isNull();
+ }
+
+ @Test
+ void theProgressOfAPullIsShownWhileTheInfraStarts() throws Exception {
+ List<String> notices = new ArrayList<>();
+ lm.setNotificationCallback((msg, error) -> notices.add(msg));
+ lm.launchInfra("ollama", List.of("sh", "-c",
+ "echo 'Pulling image layers: 3 pending, 2 downloaded, 0
extracted, (1.2 GB/3.4 GB)'; sleep 30"));
+ long deadline = System.currentTimeMillis() + 10_000;
+ while (notices.isEmpty() && System.currentTimeMillis() < deadline) {
+ lm.tick(System.currentTimeMillis());
+ Thread.sleep(50);
+ }
+
+ assertThat(notices).containsExactly("Pulling image of ollama: 2 of 5
layers, 1.2 GB of 3.4 GB (35%)");
+ // the same progress is not shown again
+ lm.tick(System.currentTimeMillis());
+ assertThat(notices).hasSize(1);
+ ProcessHandle.current().children()
+ .filter(p -> p.info().command().map(c ->
c.endsWith("sh")).orElse(false))
+ .forEach(ph -> {
+ ph.descendants().forEach(ProcessHandle::destroy);
+ ph.destroy();
+ });
+ }
+
private static InfraInfo infra(String alias) {
InfraInfo info = new InfraInfo();
info.alias = alias;