Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a0b4be2
initial dockerCompose
MarcelDiessner Dec 22, 2020
292168d
Merge remote-tracking branch 'UPSTREAM/main' into feature/consoleDock…
MarcelDiessner Jan 13, 2021
b270020
Merge remote-tracking branch 'UPSTREAM/main' into feature/consoleDock…
MarcelDiessner Jan 20, 2021
769bf9f
Added dokumentation and dockercompose async execution for observable …
MarcelDiessner Jan 20, 2021
ccb3ed8
Removed unused import
MarcelDiessner Jan 20, 2021
259dfc9
Added logging for execution of docker-compose
MarcelDiessner Jan 22, 2021
d18d2fc
Fixed logging
MarcelDiessner Jan 22, 2021
0bbc0cd
small changes
MarcelDiessner Jan 22, 2021
337651e
Merge remote-tracking branch 'UPSTREAM/main' into feature/consoleDock…
MarcelDiessner Jan 29, 2021
af71426
Added switch to linux engine if on windows
MarcelDiessner Jan 29, 2021
da82b6f
In assertion catch any error
MarcelDiessner Feb 5, 2021
29282b7
Merge branch 'main' into feature/consoleDockerCompose
MarcelDiessner Feb 5, 2021
44e8a4e
Added skip function
MarcelDiessner Feb 10, 2021
f20ccb2
try catch on assert in engine
MarcelDiessner Feb 10, 2021
64a2c2b
Throws Error if Docker-compose does not exit with code 0
MarcelDiessner Feb 10, 2021
8a79cbe
Added break if skippable
MarcelDiessner Feb 10, 2021
b928462
next test
MarcelDiessner Feb 10, 2021
79a3399
next test for windows pipeline
MarcelDiessner Feb 10, 2021
f99dca2
removed some unnessessary logging
MarcelDiessner Feb 10, 2021
b332032
Added missing logic
MarcelDiessner Feb 10, 2021
b786674
Added skippableCommands as console parameter
MarcelDiessner Feb 12, 2021
f5194ff
Added dependency for minimist
MarcelDiessner Feb 12, 2021
94ee1b7
use one parameter skipCommands
MarcelDiessner Feb 12, 2021
5c60621
added logging to debug
MarcelDiessner Feb 12, 2021
728a0b3
Different parsing
MarcelDiessner Feb 12, 2021
d0bed5b
Removed logging
MarcelDiessner Feb 12, 2021
ceb9d68
Removed logs and changed small part in commandIsSkippable
MarcelDiessner Feb 12, 2021
ef751db
removed else branch of comamndIsSkippable
MarcelDiessner Feb 12, 2021
066b4f1
Added parameter for path in assertion
MarcelDiessner Feb 15, 2021
9b32064
path handling
MarcelDiessner Feb 15, 2021
c6aeb08
Update Functions.md
MarcelDiessner Feb 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildRun.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Copy-Item -Force -Recurse -Path $PSScriptRoot\playbooks\ -Destination $PSScriptR
Copy-Item -Force -Recurse -Path $PSScriptRoot\environments\ -Destination $PSScriptRoot\build
Copy-Item -Force -Recurse -Path $PSScriptRoot\runners\ -Destination $PSScriptRoot\build
npm test
node $PSScriptRoot\build\engine\run.js
node $PSScriptRoot\build\engine\run.js --skipCommands.console dockerCompose
15 changes: 15 additions & 0 deletions documentation/Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The following functions are already implemented:
* runServerJava
* buildNg
* npmInstall
* dockerCompose
* downloadFile

***
Expand Down Expand Up @@ -152,6 +153,20 @@ npmInstall("my-thai-star/angular")

***

### dockerCompose
#### parameter
1. Path to the directory where the docker-compose.yml file is located, relative to workspace.
2. Assertion information. Only needed for the console runner to check if the server was started properly.
#### example
dockerCompose("my-thai-star", { "startupTime": 600, "port": 8081, "path": "" })

##### Assertion information
startupTime = Time in seconds to wait before checking if the server is running
port: Port on which the server is running
path: The URL path on which is checked if the server is running

***

### downloadFile
#### parameter
1. URL of the file to be downloaded.
Expand Down
13 changes: 12 additions & 1 deletion engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,33 @@ export class Engine {
(await this.getRunner(this.environment.runners[runnerIndex])).init(this.playbook);
}

for (let stepIndex in this.playbook.steps) {
mainloop: for (let stepIndex in this.playbook.steps) {
for (let lineIndex in this.playbook.steps[stepIndex].lines) {
let foundRunnerToExecuteCommand = false;
for (let runnerIndex in this.environment.runners) {
let runner = await this.getRunner(this.environment.runners[runnerIndex]);
if (runner.supports(this.playbook.steps[stepIndex].lines[lineIndex].name)) {
var result = new RunResult();
if(runner.commandIsSkippable(this.playbook.steps[stepIndex].lines[lineIndex].name)) {
console.log("Command " + this.playbook.steps[stepIndex].lines[lineIndex].name + " will be skipped.");
continue;
}
try {
result = runner.run(this.playbook.steps[stepIndex], this.playbook.steps[stepIndex].lines[lineIndex]);
}
catch (e) {
result.exceptions.push(e);
}

await runner.assert(this.playbook.steps[stepIndex], this.playbook.steps[stepIndex].lines[lineIndex], result);

foundRunnerToExecuteCommand = true;
break;
}
}
if(!foundRunnerToExecuteCommand) {
break mainloop;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion engine/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class Run {
traverseArgs(parentName, obj) {

for (let index in obj) {
if (isObject(obj[index])) {
if (obj[index] instanceof Object) {
this.args.set(parentName + index, obj[index]);
this.traverseArgs(parentName + index + ".", obj[index]);
}
else {
Expand Down
11 changes: 11 additions & 0 deletions engine/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,15 @@ export abstract class Runner {
fs.mkdirSync(path, { recursive: true });
return path;
}

commandIsSkippable(command: String): Boolean {
let returnVal = false;
let runner = this.getVariable("skipCommands." + this.getRunnerName());
if(runner) {
if((runner instanceof Array && runner.indexOf(command) != -1) || runner == command) {
returnVal = true;
}
}
return returnVal;
}
}
58 changes: 56 additions & 2 deletions runners/console/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class Console extends Runner {
}
this.setVariable(this.workspaceDirectory, path.join(this.getWorkingDirectory()));
this.env = process.env;

}

destroy(playbook: Playbook): void {
Expand Down Expand Up @@ -207,6 +208,27 @@ export class Console extends Runner {
return result;
}


runDockerCompose(step: Step, command: Command): RunResult {
let result = new RunResult();
result.returnCode = 0;

let filepath = path.join(this.getVariable(this.workspaceDirectory), command.parameters[0]);

let process = this.executeCommandAsync("docker-compose up", filepath, result);
process.on('close', (code) => {
if (code !== 0) {
result.returnCode = code;
}
});
if(process.pid && command.parameters.length == 2) {
this.asyncProcesses.push({ pid: process.pid, name: "dockerCompose", port: command.parameters[1].port });
}

return result;

}

runRunServerJava(step: Step, command: Command): RunResult {
let result = new RunResult();
result.returnCode = 0;
Expand Down Expand Up @@ -238,6 +260,7 @@ export class Console extends Runner {
this.executeCommandSync("git clone " + command.parameters[1], directorypath, result);

return result;

}

runNpmInstall(step: Step, command: Command): RunResult {
Expand Down Expand Up @@ -415,7 +438,37 @@ export class Console extends Runner {
throw error;
}
}


async assertDockerCompose(step: Step, command: Command, result: RunResult) {
try {
let assert = new Assertions()
.noErrorCode(result)
.noException(result);

if(command.parameters.length > 1) {
if(!command.parameters[1].startupTime) {
console.warn("No startup time for command dockerCompose has been set")
}
let startupTimeInSeconds = command.parameters[1].startupTime ? command.parameters[1].startupTime : 0;
await this.sleep(command.parameters[1].startupTime);

if(!command.parameters[1].port) {
this.killAsyncProcesses();
throw new Error("Missing arguments for command dockerCompose. You have to specify a port and a path for the server. For further information read the function documentation.");
} else {
let isReachable = await assert.serverIsReachable(command.parameters[1].port, command.parameters[1].path);
if(!isReachable) {
this.killAsyncProcesses();
throw new Error("The server has not become reachable in " + startupTimeInSeconds + " seconds: " + "http://localhost:" + command.parameters[1].port + "/" + command.parameters[1].path);
}
}
}
} catch(error) {
this.cleanUp();
throw error;
}
}

async assertRunServerJava(step: Step, command: Command, result: RunResult) {
try {
let assert = new Assertions()
Expand Down Expand Up @@ -637,5 +690,6 @@ export class Console extends Runner {
}
}



}
}