From 9741c0b58ba7cc6dd77422cad414a627ee04de6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 23 Dec 2020 09:26:41 +0100 Subject: [PATCH 1/4] Initial katacodaDockerCompose --- runners/katacoda/index.ts | 12 ++++++++++++ runners/katacoda/templates/dockerCompose.md | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 runners/katacoda/templates/dockerCompose.md diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index d0450eab..63e4cd22 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -209,6 +209,18 @@ export class Katacoda extends Runner { } + runDockerCompose(step: Step, command: Command) : RunResult { + let cdCommand = this.changeCurrentDir(path.join("/root", "devonfw", "workspaces", "main")); + + this.steps.push({ + "title": "Execute Docker Compose", + "text": "step" +this.stepsCount + ".md" + }); + + this.renderTemplate("dockerCompose.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, filePath: command.parameters[0].replace(/\\/g, "/"); }) + return null; + } + private renderTemplate(name: string, targetPath: string, variables) { let template = fs.readFileSync(path.join(this.getRunnerDirectory(),"templates", name), 'utf8'); let result = ejs.render(template, variables); diff --git a/runners/katacoda/templates/dockerCompose.md b/runners/katacoda/templates/dockerCompose.md new file mode 100644 index 00000000..94b925af --- /dev/null +++ b/runners/katacoda/templates/dockerCompose.md @@ -0,0 +1,15 @@ +<%= text; %> + +## Docker Compose + +<%= cdCommand; %> + +Navigate to the folder in which your Dockerfile is. + +`cd <%= filePath; %>`{{execute}} + +Now you can use docker-compose up. + +`docker-compose up`{{execute}} + +<%= textAfter; %> \ No newline at end of file From a047f34d304d3ba5af1e764c794a3391f4ca1e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Wed, 23 Dec 2020 14:34:46 +0100 Subject: [PATCH 2/4] Added documentation and fixed a wrong semicolon --- documentation/Functions.md | 9 +++++++++ runners/katacoda/index.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/documentation/Functions.md b/documentation/Functions.md index a9eefb1a..07b0a8b0 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -6,6 +6,7 @@ The following functions are already implemented: * createDevon4jProject * buildJava * createFile +* dockerCompose *** @@ -96,3 +97,11 @@ A placeholder is optional. If you do not define a placeholder, the content in th Please try not to use custom placeholders. Keep in mind that you might want to build the project before changing them. Custom placeholders with a comment-syntax (e.g. "//PLACEHOLDER") will be removed by the console-environment and others might cause errors. *** + +### dockerCompose +#### parameter +1. Path to the Dockerfile +#### example +dockerCompose("exampleproject") + +*** diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 63e4cd22..0f23f654 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -217,7 +217,7 @@ export class Katacoda extends Runner { "text": "step" +this.stepsCount + ".md" }); - this.renderTemplate("dockerCompose.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, filePath: command.parameters[0].replace(/\\/g, "/"); }) + this.renderTemplate("dockerCompose.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, filePath: command.parameters[0].replace(/\\/g, "/") }); return null; } From f58e87b0c7aeae8b4a6a8f28ff8209642ce5278f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Fri, 12 Feb 2021 16:48:27 +0100 Subject: [PATCH 3/4] updated and integrated external terminal --- runners/katacoda/index.ts | 5 +++-- runners/katacoda/templates/dockerCompose.md | 16 +++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 501a68b4..c70fe14b 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -339,14 +339,15 @@ export class Katacoda extends Runner { } runDockerCompose(step: Step, command: Command) : RunResult { - let cdCommand = this.changeCurrentDir(path.join("/root", "devonfw", "workspaces", "main")); + let terminal = this.getTerminal('runDockerCompose'); + let cdCommand = this.changeCurrentDir(path.join(this.getVariable(this.workspaceDirectory), command.parameters[0]), terminal.terminalId, terminal.isRunning); this.steps.push({ "title": "Execute Docker Compose", "text": "step" +this.stepsCount + ".md" }); - this.renderTemplate("dockerCompose.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, filePath: command.parameters[0].replace(/\\/g, "/") }); + this.renderTemplate("dockerCompose.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, terminalId: terminal.terminalId, interrupt: terminal.isRunning, port: command.parameters[1].port, useDevonCommand: this.getVariable(this.useDevonCommand)}); return null; } diff --git a/runners/katacoda/templates/dockerCompose.md b/runners/katacoda/templates/dockerCompose.md index 94b925af..3b818ce1 100644 --- a/runners/katacoda/templates/dockerCompose.md +++ b/runners/katacoda/templates/dockerCompose.md @@ -4,12 +4,18 @@ <%= cdCommand; %> -Navigate to the folder in which your Dockerfile is. +<% if(!interrupt){ %> +Now run docker-compose. +<% } else { %> +The docker container is already running. +<% } %> -`cd <%= filePath; %>`{{execute}} +`<% if(useDevonCommand){ %>devon<% } %> docker-compose up`{{execute T<%= terminalId; %> <% if (interrupt) { %>interrupt<% } %>}} -Now you can use docker-compose up. - -`docker-compose up`{{execute}} +This will take some time. +<% if(port){ %> +Then you can open the following link to use the app. +https://[[HOST_SUBDOMAIN]]-<%= port %>-[[KATACODA_HOST]].environments.katacoda.com/ +<% } %> <%= textAfter; %> \ No newline at end of file From a849a93c8b2fcd5ca1c6354d5c16234e8db1ce75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Die=C3=9Fner?= Date: Mon, 15 Feb 2021 09:54:53 +0100 Subject: [PATCH 4/4] Removed devoncommand and other minor fixes --- runners/katacoda/index.ts | 2 +- runners/katacoda/templates/dockerCompose.md | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index c70fe14b..683a3b03 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -347,7 +347,7 @@ export class Katacoda extends Runner { "text": "step" +this.stepsCount + ".md" }); - this.renderTemplate("dockerCompose.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, terminalId: terminal.terminalId, interrupt: terminal.isRunning, port: command.parameters[1].port, useDevonCommand: this.getVariable(this.useDevonCommand)}); + this.renderTemplate("dockerCompose.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, terminalId: terminal.terminalId, interrupt: terminal.isRunning, port: command.parameters[1].port}); return null; } diff --git a/runners/katacoda/templates/dockerCompose.md b/runners/katacoda/templates/dockerCompose.md index 3b818ce1..092cf38f 100644 --- a/runners/katacoda/templates/dockerCompose.md +++ b/runners/katacoda/templates/dockerCompose.md @@ -1,16 +1,15 @@ <%= text; %> -## Docker Compose - <%= cdCommand; %> <% if(!interrupt){ %> Now run docker-compose. <% } else { %> The docker container is already running. +Usually you would type "Ctrl + C" and rerun the same command in this terminal to rebuild the app, but for now click on the command to stop and relaunch it automatically. <% } %> -`<% if(useDevonCommand){ %>devon<% } %> docker-compose up`{{execute T<%= terminalId; %> <% if (interrupt) { %>interrupt<% } %>}} +`docker-compose up`{{execute T<%= terminalId; %> <% if (interrupt) { %>interrupt<% } %>}} This will take some time.