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 2023/07/11 12:57:50 UTC
[camel] 01/02: CAMEL-19599: camel-jbang - Export to camel-main - Add support for Kubernetes
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
commit 71c684c268fb01a0aefdf58b51e7ef4f9117174a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Jul 11 11:53:19 2023 +0200
CAMEL-19599: camel-jbang - Export to camel-main - Add support for Kubernetes
---
.../dsl/jbang/core/commands/ExportCamelMain.java | 41 ++++++++++++++++++++--
.../resources/templates/main-kubernetes-pom.tmpl | 37 +++++++++++++++++++
.../src/main/resources/templates/main-pom.tmpl | 3 ++
3 files changed, 79 insertions(+), 2 deletions(-)
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 96e9a6cb658..a107fe7cda4 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
@@ -123,7 +123,7 @@ class ExportCamelMain extends Export {
// copy local lib JARs
copyLocalLibDependencies(deps);
if ("maven".equals(buildTool)) {
- createMavenPom(settings, new File(BUILD_DIR, "pom.xml"), deps, packageName);
+ createMavenPom(settings, profile, new File(BUILD_DIR, "pom.xml"), deps, packageName);
if (mavenWrapper) {
copyMavenWrapper();
}
@@ -139,7 +139,7 @@ class ExportCamelMain extends Export {
return 0;
}
- private void createMavenPom(File settings, File pom, Set<String> deps, String packageName) throws Exception {
+ private void createMavenPom(File settings, File profile, File pom, Set<String> deps, String packageName) throws Exception {
String[] ids = gav.split(":");
InputStream is = ExportCamelMain.class.getClassLoader().getResourceAsStream("templates/main-pom.tmpl");
@@ -241,9 +241,46 @@ class ExportCamelMain extends Export {
context = context.replaceFirst("\\{\\{ \\.CamelDependencies }}", sb.toString());
+ // include kubernetes?
+ context = enrichMavenPomKubernetes(context, settings, profile);
+
IOHelper.writeText(context, new FileOutputStream(pom, false));
}
+ protected String enrichMavenPomKubernetes(String context, File settings, File profile) throws Exception {
+ StringBuilder sb1 = new StringBuilder();
+ StringBuilder sb2 = new StringBuilder();
+
+ // is kubernetes included?
+ Properties prop = new CamelCaseOrderedProperties();
+ if (profile.exists()) {
+ RuntimeUtil.loadProperties(prop, profile);
+ }
+ boolean jkube = prop.stringPropertyNames().stream().anyMatch(s -> s.startsWith("jkube."));
+ if (jkube) {
+ // include all jib/jkube/label properties
+ for (String key : prop.stringPropertyNames()) {
+ String value = prop.getProperty(key);
+ boolean accept = key.startsWith("jkube.") || key.startsWith("jib.") || key.startsWith("label.");
+ if (accept) {
+ sb1.append(String.format(" <%s>%s</%s>%n", key, value, key));
+ }
+ }
+
+ InputStream is = ExportCamelMain.class.getClassLoader().getResourceAsStream("templates/main-kubernetes-pom.tmpl");
+ String context2 = IOHelper.loadText(is);
+ int port = httpServerPort(settings);
+ if (port == -1) {
+ port = 8080;
+ }
+ sb2.append(context2.replaceFirst("\\{\\{ \\.Port }}", String.valueOf(port)));
+ }
+
+ context = context.replaceFirst("\\{\\{ \\.CamelKubernetesProperties }}", sb1.toString());
+ context = context.replaceFirst("\\{\\{ \\.CamelKubernetesPlugins }}", sb2.toString());
+ return context;
+ }
+
@Override
protected Set<String> resolveDependencies(File settings, File profile) throws Exception {
Set<String> answer = super.resolveDependencies(settings, profile);
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
new file mode 100644
index 00000000000..211e9881b8c
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-pom.tmpl
@@ -0,0 +1,37 @@
+ <plugin>
+ <groupId>com.google.cloud.tools</groupId>
+ <artifactId>jib-maven-plugin</artifactId>
+ <version>3.3.2</version>
+ <configuration>
+ <container>
+ <ports>
+ <port>{{ .Port}}</port>
+ </ports>
+ </container>
+ <containerizingMode>packaged</containerizingMode>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.eclipse.jkube</groupId>
+ <artifactId>kubernetes-maven-plugin</artifactId>
+ <version>${jkube.version}</version>
+ <configuration>
+ <images>
+ <image>
+ <name>${jib.to.image}</name>
+ <build>
+ </build>
+ </image>
+ </images>
+ <resources>
+ <labels>
+ <all>
+ <property>
+ <name>${label.runtime}</name>
+ <value>camel</value>
+ </property>
+ </all>
+ </labels>
+ </resources>
+ </configuration>
+ </plugin>
\ No newline at end of file
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-pom.tmpl b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-pom.tmpl
index 6ae7762e9cb..37be8f8f8dc 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-pom.tmpl
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-pom.tmpl
@@ -9,6 +9,7 @@
<properties>
<java.version>{{ .JavaVersion }}</java.version>
+{{ .CamelKubernetesProperties }}
</properties>
<dependencyManagement>
@@ -69,6 +70,7 @@
<build>
<plugins>
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@@ -123,6 +125,7 @@
</execution>
</executions>
</plugin>
+{{ .CamelKubernetesPlugins }}
</plugins>
</build>