You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2022/10/20 01:41:21 UTC

[camel-karavan] branch main updated (edb761a -> c70c1bd)

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

marat pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git


    from edb761a  Fixed CSVMetadata
     new 42066bd  Openshift and image build properties
     new c70c1bd  Deploy project

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 karavan-vscode/package.json     | 122 ++++++++++++++++++++++++++++++++--------
 karavan-vscode/src/extension.ts |  24 ++++++--
 karavan-vscode/src/jbang.ts     |  54 +++++++++++++++---
 karavan-vscode/src/utils.ts     |   8 ++-
 4 files changed, 169 insertions(+), 39 deletions(-)


[camel-karavan] 02/02: Deploy project

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git

commit c70c1bd1c68ed17f3c50c37e83e2740f9374743e
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Wed Oct 19 21:41:10 2022 -0400

    Deploy project
---
 karavan-vscode/package.json     | 58 +++++++++++++++++++++++++++++------------
 karavan-vscode/src/extension.ts |  8 +++++-
 karavan-vscode/src/jbang.ts     | 54 ++++++++++++++++++++++++++++++++------
 karavan-vscode/src/utils.ts     |  2 +-
 4 files changed, 95 insertions(+), 27 deletions(-)

diff --git a/karavan-vscode/package.json b/karavan-vscode/package.json
index 85e9a13..6db1b1e 100644
--- a/karavan-vscode/package.json
+++ b/karavan-vscode/package.json
@@ -42,6 +42,7 @@
     "onCommand:karavan.create-crd",
     "onCommand:karavan.create-yaml",
     "onCommand:karavan.create-application",
+    "onCommand:karavan.deploy",
     "onCommand:karavan.open",
     "onCommand:karavan.open-file",
     "onCommand:karavan.jbang-run-file",
@@ -186,7 +187,7 @@
             "type": "string"
           },
           "default": [
-            "quarkus.container-image.group=${KUBERNETES_NAMESPACE}",
+            "quarkus.container-image.group=${NAMESPACE}",
             "quarkus.container-image.name=$NAME",
             "quarkus.container-image.builder=jib",
             "quarkus.container-image.build=true",
@@ -212,7 +213,7 @@
             "quarkus.kubernetes.labels.\"app.openshift.io/runtime\"=camel",
             "quarkus.kubernetes-client.trust-certs=true",
             "quarkus.kubernetes-client.master-url=kubernetes.default.svc",
-            "quarkus.kubernetes-client.namespace=${KUBERNETES_NAMESPACE}",
+            "quarkus.kubernetes-client.namespace=${NAMESPACE}",
             "quarkus.kubernetes-client.token=${TOKEN}",
             "quarkus.openshift.deployment-kind=Deployment",
             "quarkus.openshift.add-version-to-label-selectors=false",
@@ -268,6 +269,11 @@
         "title": "Karavan: Export",
         "icon": "$(export)"
       },
+      {
+        "command": "karavan.deploy",
+        "title": "Karavan: Deploy",
+        "icon": "$(layers)"
+      },
       {
         "command": "karavan.generate-rest",
         "title": "Karavan: Generate REST API"
@@ -303,35 +309,48 @@
       "explorer/context": [
         {
           "command": "karavan.create-crd",
-          "when": "explorerResourceIsFolder || explorerResourceIsRoot"
+          "when": "explorerResourceIsFolder || explorerResourceIsRoot",
+          "group": "karavan@1"
         },
         {
           "command": "karavan.create-yaml",
-          "when": "explorerResourceIsFolder || explorerResourceIsRoot"
+          "when": "explorerResourceIsFolder || explorerResourceIsRoot",
+          "group": "karavan@2"
         },
         {
           "command": "karavan.create-application",
-          "when": "explorerResourceIsFolder || explorerResourceIsRoot"
+          "when": "explorerResourceIsFolder || explorerResourceIsRoot",
+          "group": "karavan@3"
         },
         {
           "command": "karavan.open",
-          "when": "resourceExtname == .yaml"
+          "when": "resourceExtname == .yaml",
+          "group": "karavan@4"
         },
         {
           "command": "karavan.jbang-run-file",
-          "when": "resourceExtname == .yaml"
+          "when": "resourceExtname == .yaml",
+          "group": "karavan@5"
         },
         {
           "command": "karavan.jbang-run-project",
-          "when": "explorerResourceIsFolder || explorerResourceIsRoot"
+          "when": "explorerResourceIsFolder || explorerResourceIsRoot",
+          "group": "karavan@6"
         },
         {
           "command": "karavan.jbang-export",
-          "when": "explorerResourceIsFolder || explorerResourceIsRoot"
+          "when": "explorerResourceIsFolder || explorerResourceIsRoot",
+          "group": "karavan@7"
+        },
+        {
+          "command": "karavan.deploy",
+          "when": "explorerResourceIsFolder || explorerResourceIsRoot",
+          "group": "karavan@8"
         },
         {
           "command": "karavan.generate-rest",
-          "when": "resourceExtname == .json"
+          "when": "resourceExtname == .json",
+          "group": "karavan@9"
         }
       ],
       "editor/title": [
@@ -348,24 +367,29 @@
       ],
       "view/title": [
         {
-          "command": "integrations.refresh",
+          "command": "karavan.jbang-run-project",
           "when": "view == integrations",
-          "group": "navigation@4"
+          "group": "navigation@1"
         },
         {
-          "command": "karavan.jbang-run-project",
+          "command": "karavan.deploy",
           "when": "view == integrations",
-          "group": "navigation@1"
+          "group": "navigation@2"
         },
         {
-          "command": "karavan.create-crd",
+          "command": "karavan.jbang-export",
           "when": "view == integrations",
           "group": "navigation@3"
         },
         {
-          "command": "karavan.jbang-export",
+          "command": "karavan.create-crd",
           "when": "view == integrations",
-          "group": "navigation@2"
+          "group": "navigation@4"
+        },
+        {
+          "command": "integrations.refresh",
+          "when": "view == integrations",
+          "group": "navigation@5"
         },
         {
           "command": "openapi.refresh",
diff --git a/karavan-vscode/src/extension.ts b/karavan-vscode/src/extension.ts
index bef26f8..8b54520 100644
--- a/karavan-vscode/src/extension.ts
+++ b/karavan-vscode/src/extension.ts
@@ -145,6 +145,12 @@ export function activate(context: ExtensionContext) {
     });
     context.subscriptions.push(exportCommand);
 
+    // Deploy project
+    const deployCommand = commands.registerCommand("karavan.deploy", (...args: any[]) => {
+        jbang.camelDeploy(rootPath + path.sep + ".export");
+    });
+    context.subscriptions.push(deployCommand);
+
     // Run Integration in designer command
     const run = commands.registerCommand("karavan.jbang-run-file", (...args: any[]) => designer.jbangRun(args[0].fsPath));
     context.subscriptions.push(run);
@@ -155,7 +161,7 @@ export function activate(context: ExtensionContext) {
     });
     context.subscriptions.push(runProjectCommand);
 
-    // Generate RST API from OpenAPI specification command
+    // Generate REST API from OpenAPI specification command
     const generateOptions = ["Create new CRD", "Create new YAML", "Add to existing file"];
     const generateRest = commands.registerCommand('karavan.generate-rest', async (...args: any[]) => {
         const openApi: OpenApiItem = args[0];
diff --git a/karavan-vscode/src/jbang.ts b/karavan-vscode/src/jbang.ts
index 612e583..c9e3c02 100644
--- a/karavan-vscode/src/jbang.ts
+++ b/karavan-vscode/src/jbang.ts
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-import { workspace, window, Terminal } from "vscode";
+import { workspace, window, Terminal, ThemeIcon } from "vscode";
 import * as path from "path";
 import * as shell from 'shelljs';
 import { CamelDefinitionYaml } from "core/api/CamelDefinitionYaml";
@@ -23,7 +23,7 @@ import * as utils from "./utils";
 const TERMINALS: Map<string, Terminal> = new Map<string, Terminal>();
 
 export async function camelJbangGenerate(rootPath: string, openApiFullPath: string, fullPath: string, add: boolean, crd?: boolean, generateRoutes?: boolean) {
-    let command = prepareCommand("generate rest -i " + openApiFullPath); 
+    let command = prepareCommand("generate rest -i " + openApiFullPath);
     if (generateRoutes === true) command = command + " --routes";
     executeJbangCommand(rootPath, command, (code, stdout, stderr) => {
         console.log('Exit code:', code);
@@ -80,7 +80,7 @@ export function camelJbangRun(filename?: string) {
     const maxMessages: number = workspace.getConfiguration().get("camel.maxMessages") || -1;
     const kameletsPath: string | undefined = workspace.getConfiguration().get("Karavan.kameletsPath");
     const dev: boolean = workspace.getConfiguration().get("camel.dev") || false;
-    const cmd = (filename ? "run " + filename : "run * ") 
+    const cmd = (filename ? "run " + filename : "run * ")
         + (maxMessages > -1 ? " --max-messages=" + maxMessages : "")
         + (kameletsPath && kameletsPath.trim().length > 0 ? " --local-kamelet-dir=" + kameletsPath : "");
     const command = prepareCommand(cmd) + (dev === true ? " --dev" : "");
@@ -94,19 +94,57 @@ export function camelJbangRun(filename?: string) {
 }
 
 export function camelJbangExport(directory: string) {
-    const kameletsPath: string | undefined = workspace.getConfiguration().get("Karavan.kameletsPath");
-    const cmd = "export  --directory=" + directory
-        + (kameletsPath && kameletsPath.trim().length >0 ? " --local-kamelet-dir=" + kameletsPath : "");
-    const command = prepareCommand(cmd);
+    const command = createExportCommand(directory);
     const terminalId = "export";
     const existTerminal = TERMINALS.get(terminalId);
     if (existTerminal) existTerminal.dispose();
-    const terminal = window.createTerminal('Camel export');
+    const terminal = window.createTerminal('export');
     TERMINALS.set(terminalId, terminal);
     terminal.show();
     terminal.sendText(command);
 }
 
+export function createExportCommand(directory: string) {
+    const kameletsPath: string | undefined = workspace.getConfiguration().get("Karavan.kameletsPath");
+    const cmd = "export --directory=" + directory
+        + (kameletsPath && kameletsPath.trim().length > 0 ? " --local-kamelet-dir=" + kameletsPath : "");
+    return prepareCommand(cmd);
+}
+
+export function camelDeploy(directory: string) {
+    const command = createExportCommand(directory).concat(" && ").concat(createPackageCommand(directory));
+
+    utils.readFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
+        .then((readData: Uint8Array) => {
+            const namespace = Buffer.from(readData).toString('utf8');
+            utils.readFile("/var/run/secrets/kubernetes.io/serviceaccount/token")
+                .then((readData: Uint8Array) => {
+                    const token = Buffer.from(readData).toString('utf8');
+                    const env = { "TOKEN":token, "NAMESPACE": namespace, "DATE":  Date.now().toString() };
+                    camelRunDeploy(command, env);
+                    
+                }).catch((reason: any) => {
+                    window.showErrorMessage("Token file not found. Set TOKEN environment variable!\n" + reason.message);
+                });
+        }).catch((reason: any) => {
+            window.showErrorMessage("Namespace file not found. Set NAMESPACE environment variable!\n" + reason.message);
+        });
+}
+
+export function camelRunDeploy(command: string, env?: { [key: string]: string | null | undefined }) {
+    const terminalId = "deploy";
+    const existTerminal = TERMINALS.get(terminalId);
+    if (existTerminal) existTerminal.dispose();
+    const terminal = window.createTerminal({ name: terminalId, env: env, iconPath: new ThemeIcon("layers") });
+    TERMINALS.set(terminalId, terminal);
+    terminal.show();
+    terminal.sendText(command);
+}
+
+export function createPackageCommand(directory: string) {
+    return "mvn clean package -f " + directory;
+}
+
 function executeJbangCommand(rootPath: string, command: string, callback: (code: number, stdout: any, stderr: any) => any) {
     console.log("excute command", command)
     const jbang = shell.which('jbang');
diff --git a/karavan-vscode/src/utils.ts b/karavan-vscode/src/utils.ts
index 7949a46..e498e63 100644
--- a/karavan-vscode/src/utils.ts
+++ b/karavan-vscode/src/utils.ts
@@ -221,7 +221,7 @@ export async function createApplicationproperties(runtime: string, gav: string,
         const runtimeDefaults: [] = (runtime === 'quarkus') 
             ? workspace.getConfiguration().get("Karavan.quarkusApplicationProperties") || []
             : [];
-        const text = props.concat(runtimeDefaults).concat(imageBuildProps).concat(targetProps).map(v => {
+        const text = props.concat(runtimeDefaults).concat("\n").concat(imageBuildProps).concat("\n").concat(targetProps).map(v => {
             if (v.includes('$NAME')) return v.replace('$NAME', name)
             else if (v.includes('$GAV')) return v.replace('$GAV', gav)
             else if (v.includes('$RUNTIME_VERSION')) return v.replace('$RUNTIME_VERSION', runtimeVersion) // $RUNTIME_VERSION should be before $RUNTIME


[camel-karavan] 01/02: Openshift and image build properties

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git

commit 42066bdf73b6f763f907757ea73853b9348546ef
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Wed Oct 19 20:17:57 2022 -0400

    Openshift and image build properties
---
 karavan-vscode/package.json     | 68 +++++++++++++++++++++++++++++++++++------
 karavan-vscode/src/extension.ts | 16 +++++++---
 karavan-vscode/src/utils.ts     |  8 +++--
 3 files changed, 77 insertions(+), 15 deletions(-)

diff --git a/karavan-vscode/package.json b/karavan-vscode/package.json
index 4fb1df8..85e9a13 100644
--- a/karavan-vscode/package.json
+++ b/karavan-vscode/package.json
@@ -79,6 +79,18 @@
           "scope": "machine",
           "order": 20
         },
+        "camel.deployTarget": {
+          "type": "string",
+          "default": "openshift",
+          "enum": [
+            "kubernetes",
+            "openshift",
+            "none"
+          ],
+          "description": "Deploy Target",
+          "scope": "machine",
+          "order": 22
+        },
         "camel.quarkus-version": {
           "type": "string",
           "default": "2.13.2.Final",
@@ -88,7 +100,7 @@
         },
         "camel.maxMessages": {
           "type": "integer",
-          "default": 10,
+          "default": 0,
           "description": "Maximum number of messages to process before stopping",
           "scope": "machine",
           "order": 30
@@ -152,7 +164,7 @@
           ],
           "description": "Default application.properties template",
           "scope": "machine",
-          "order": 99
+          "order": 90
         },
         "Karavan.quarkusApplicationProperties": {
           "type": "array",
@@ -161,18 +173,56 @@
             "type": "string"
           },
           "default": [
-            "camel.jbang.quarkusVersion=$RUNTIME_VERSION",
-            "quarkus.kubernetes-client.trust-certs=true",
-            "quarkus.container-image.builder=jib",
-            "quarkus.container-image.group=karavan",
+            "camel.jbang.quarkusVersion=$RUNTIME_VERSION"
+          ],
+          "description": "Default application.properties template for Quarkus Runtime",
+          "scope": "machine",
+          "order": 95
+        },
+        "Karavan.imageBuildProperties": {
+          "type": "array",
+          "uniqueItems": true,
+          "items": {
+            "type": "string"
+          },
+          "default": [
+            "quarkus.container-image.group=${KUBERNETES_NAMESPACE}",
             "quarkus.container-image.name=$NAME",
+            "quarkus.container-image.builder=jib",
+            "quarkus.container-image.build=true",
+            "quarkus.container-image.push=true",
+            "quarkus.container-image.registry=image-registry.openshift-image-registry.svc:5000",
+            "quarkus.container-image.insecure=true",
+            "quarkus.container-image.username=sa",
+            "quarkus.container-image.password=${TOKEN}",
+            "quarkus.container-image.tag=${DATE}"
+          ],
+          "description": "Default application.properties template for image build",
+          "scope": "machine",
+          "order": 96
+        },
+        "Karavan.openshiftProperties": {
+          "type": "array",
+          "uniqueItems": true,
+          "items": {
+            "type": "string"
+          },
+          "default": [
+            "quarkus.kubernetes.deploy=true",
+            "quarkus.kubernetes.labels.\"app.openshift.io/runtime\"=camel",
+            "quarkus.kubernetes-client.trust-certs=true",
+            "quarkus.kubernetes-client.master-url=kubernetes.default.svc",
+            "quarkus.kubernetes-client.namespace=${KUBERNETES_NAMESPACE}",
+            "quarkus.kubernetes-client.token=${TOKEN}",
+            "quarkus.openshift.deployment-kind=Deployment",
+            "quarkus.openshift.add-version-to-label-selectors=false",
             "quarkus.openshift.route.expose=false",
             "quarkus.openshift.part-of=$NAME",
             "quarkus.openshift.replicas=1"
           ],
-          "description": "Default application.properties template for Quarkus Runtime",
+          "description": "Default application.properties template for Openshift",
           "scope": "machine",
-          "order": 100
+          "order": 97
         }
       }
     },
@@ -450,4 +500,4 @@
     "shelljs": "^0.8.5",
     "uuid": "8.3.2"
   }
-}
+}
\ No newline at end of file
diff --git a/karavan-vscode/src/extension.ts b/karavan-vscode/src/extension.ts
index a61977c..bef26f8 100644
--- a/karavan-vscode/src/extension.ts
+++ b/karavan-vscode/src/extension.ts
@@ -113,17 +113,25 @@ export function activate(context: ExtensionContext) {
     const applicationCommand = commands.registerCommand("karavan.create-application", (...args: any[]) => {
         if (rootPath){
             const defaultRuntime: string = workspace.getConfiguration().get("camel.runtimes") || '';
+            const deployTarget: string = workspace.getConfiguration().get("camel.deployTarget") || 'openshift';
             const runtimeOptions: QuickPickItem [] = [
                 {label: "quarkus", picked: "quarkus" === defaultRuntime},
                 {label: "spring-boot", picked: "spring-boot" === defaultRuntime},
                 {label: "camel-main", picked: "camel-main" === defaultRuntime}
             ];
+            const deployOptions: QuickPickItem [] = [
+                {label: "kubernetes", picked: "kubernetes" === deployTarget},
+                {label: "openshift", picked: "openshift" === deployTarget},
+                {label: "none", picked: "none" === deployTarget}
+            ];
             utils.hasApplicationProperties(rootPath).then(hasAP => {
                 if (hasAP){
                     window.showInformationMessage("Folder already contains application.properties");
                 } else {
-                    window.showQuickPick(runtimeOptions, { title: "Select Runtime", canPickMany: false }).then((value) => {
-                        if (value) inputExportGav(value.label) 
+                    window.showQuickPick(runtimeOptions, { title: "Select Runtime", canPickMany: false }).then((runtime) => {
+                        window.showQuickPick(deployOptions, { title: "Select Deploy Target", canPickMany: false }).then((target) => {
+                            if (runtime && target) inputExportGav(runtime.label, target.label) 
+                        })
                     })
                 }
             })
@@ -194,7 +202,7 @@ export async function inputExportFolder(rootPath?: string) {
 /**
  * export with gav
  */
-export async function inputExportGav(runtime: string) {
+export async function inputExportGav(runtime: string, target: string) {
     window.showInputBox({
         title: "Export project with " + runtime,
         ignoreFocusOut: true,
@@ -208,7 +216,7 @@ export async function inputExportGav(runtime: string) {
         }
     }).then(gav => {
         if (gav) {
-            utils.crateApplicationproperties(runtime, gav)
+            utils.createApplicationproperties(runtime, gav, target)
         }
     });
 }
diff --git a/karavan-vscode/src/utils.ts b/karavan-vscode/src/utils.ts
index 3d3279d..7949a46 100644
--- a/karavan-vscode/src/utils.ts
+++ b/karavan-vscode/src/utils.ts
@@ -206,7 +206,7 @@ export async function write(fullPath: string, code: string) {
     );
 }
 
-export async function crateApplicationproperties(runtime: string, gav: string, ) {
+export async function createApplicationproperties(runtime: string, gav: string, deployTarget: string ) {
     if (workspace.workspaceFolders) {
         const uriFolder: Uri = workspace.workspaceFolders[0].uri;
         const parts = uriFolder.fsPath.split(path.sep);
@@ -214,10 +214,14 @@ export async function crateApplicationproperties(runtime: string, gav: string, )
 
         const runtimeVersion: string = workspace.getConfiguration().get("camel." + runtime + "-version") || '';
         const props: string [] = workspace.getConfiguration().get("Karavan.applicationProperties") || [];
+        const imageBuildProps: string [] = workspace.getConfiguration().get("Karavan.imageBuildProperties") || [];
+        const targetProps: string [] = 
+                deployTarget === 'openshift' ? (workspace.getConfiguration().get("Karavan.openshiftProperties") || [])
+                : [];
         const runtimeDefaults: [] = (runtime === 'quarkus') 
             ? workspace.getConfiguration().get("Karavan.quarkusApplicationProperties") || []
             : [];
-        const text = props.concat(runtimeDefaults).map(v => {
+        const text = props.concat(runtimeDefaults).concat(imageBuildProps).concat(targetProps).map(v => {
             if (v.includes('$NAME')) return v.replace('$NAME', name)
             else if (v.includes('$GAV')) return v.replace('$GAV', gav)
             else if (v.includes('$RUNTIME_VERSION')) return v.replace('$RUNTIME_VERSION', runtimeVersion) // $RUNTIME_VERSION should be before $RUNTIME