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 9486700633b CAMEL-20125: camel-jbang - Export to camel-main - Allow to configure auth for jib-maven-plugin (#12080) 9486700633b is described below commit 9486700633b155d687890d48e7af30358a748a16 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sun Nov 19 11:46:05 2023 +0100 CAMEL-20125: camel-jbang - Export to camel-main - Allow to configure auth for jib-maven-plugin (#12080) --- .../modules/ROOT/pages/camel-jbang.adoc | 24 +++++++++++++++++- .../dsl/jbang/core/commands/ExportCamelMain.java | 29 +++++++++++++++++++++- .../templates/main-kubernetes-from-auth-pom.tmpl | 4 +++ .../resources/templates/main-kubernetes-pom.tmpl | 10 +++++++- .../templates/main-kubernetes-to-auth-pom.tmpl | 4 +++ 5 files changed, 68 insertions(+), 3 deletions(-) diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc index c9996a0a3fa..dc4ac941fd5 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc @@ -2526,11 +2526,33 @@ jkube.recreate=true TIP: You can specify the jib-maven-plugin version using the `camel.jbang.jib-maven-plugin-version` property in `application.properties`. +===== Configuring from and to image + +The jib-maven-plugin must be configured with a from and to image. The from image will default be `eclipse-temurin:17-jre` +for Java 17 and `eclipse-temurin:21-jre` for Java 21. However, companies often have their own base images to be used, so +you can configure this in the properties (together with authentication if needed): + +[source,properties] +---- +jib.from.image=com.mycompany/base-images/ubi17/java17-builder:latest +jib.from.auth.username = myuser +jib.from.auth.password = mypass +---- + +The to image is configured in the same way, such as: + +[source,properties] +---- +jib.to.image=com.mycompany/myproject/myapp +jib.to.auth.username = myuser +jib.to.auth.password = mypass +---- + You can find more details in the https://eclipse.dev/jkube/docs/[Eclipse JKube] and https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin[Jib] documentations. ===== Resource fragments -Resource fragments allows to store external configuration in YAML resource descriptions, which +Resource fragments for JKube allows to store external configuration in YAML resource descriptions, which will be exported to `src/main/jkube` directory. Camel JBang will export files that ends with `jkube.yaml` or `jkube.yml` into `src/main/jkube` directory. diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java index e39290f0f9a..bd9b6d25c9f 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java @@ -243,23 +243,50 @@ class ExportCamelMain extends Export { boolean jkube = prop.stringPropertyNames().stream().anyMatch(s -> s.startsWith("jkube.")); if (jkube) { // include all jib/jkube/label properties + String fromImage = null; for (String key : prop.stringPropertyNames()) { String value = prop.getProperty(key); + if ("jib.from.image".equals(key)) { + fromImage = value; + } boolean accept = key.startsWith("jkube.") || key.startsWith("jib.") || key.startsWith("label."); if (accept) { sb1.append(String.format(" <%s>%s</%s>%n", key, value, key)); } } + // from image is mandatory so use a default image if none provided + if (fromImage == null) { + fromImage = "eclipse-temurin:" + javaVersion + "-jre"; + sb1.append(String.format(" <%s>%s</%s>%n", "jib.from.image", fromImage, "jib.from.image")); + } InputStream is = ExportCamelMain.class.getClassLoader().getResourceAsStream("templates/main-kubernetes-pom.tmpl"); String context2 = IOHelper.loadText(is); IOHelper.close(is); + + context2 = context2.replaceFirst("\\{\\{ \\.JibMavenPluginVersion }}", jibMavenPluginVersion(settings)); + + // image from/to auth + String auth = ""; + if (prop.stringPropertyNames().stream().anyMatch(s -> s.startsWith("jib.from.auth."))) { + is = ExportCamelMain.class.getClassLoader().getResourceAsStream("templates/main-kubernetes-from-auth-pom.tmpl"); + auth = IOHelper.loadText(is); + IOHelper.close(is); + } + context2 = context2.replace("{{ .JibFromImageAuth }}", auth); + auth = ""; + if (prop.stringPropertyNames().stream().anyMatch(s -> s.startsWith("jib.to.auth."))) { + is = ExportCamelMain.class.getClassLoader().getResourceAsStream("templates/main-kubernetes-to-auth-pom.tmpl"); + auth = IOHelper.loadText(is); + IOHelper.close(is); + } + context2 = context2.replace("{{ .JibToImageAuth }}", auth); + // http port setting int port = httpServerPort(settings); if (port == -1) { port = 8080; } context2 = context2.replaceFirst("\\{\\{ \\.Port }}", String.valueOf(port)); - context2 = context2.replaceFirst("\\{\\{ \\.JibMavenPluginVersion }}", jibMavenPluginVersion(settings)); sb2.append(context2); } diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-from-auth-pom.tmpl b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-from-auth-pom.tmpl new file mode 100644 index 00000000000..9ec06c4aa27 --- /dev/null +++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-from-auth-pom.tmpl @@ -0,0 +1,4 @@ + <auth> + <username>${jib.from.auth.username}</username> + <password>${jib.from.auth.password}</password> + </auth> diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-pom.tmpl b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-pom.tmpl index 0623bd06a0b..5046b334e23 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-pom.tmpl +++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-pom.tmpl @@ -3,12 +3,20 @@ <artifactId>jib-maven-plugin</artifactId> <version>{{ .JibMavenPluginVersion }}</version> <configuration> + <from> + <image>${jib.from.image}</image> +{{ .JibFromImageAuth }} + </from> + <to> + <image>${jib.to.image}</image> +{{ .JibToImageAuth }} + </to> + <containerizingMode>packaged</containerizingMode> <container> <ports> <port>{{ .Port }}</port> </ports> </container> - <containerizingMode>packaged</containerizingMode> </configuration> </plugin> <plugin> diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-to-auth-pom.tmpl b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-to-auth-pom.tmpl new file mode 100644 index 00000000000..9bd2171ee91 --- /dev/null +++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-to-auth-pom.tmpl @@ -0,0 +1,4 @@ + <auth> + <username>${jib.to.auth.username}</username> + <password>${jib.to.auth.password}</password> + </auth>