diff --git a/node-scripts/spec/pipeline3/scripts.spec.js b/node-scripts/spec/pipeline3/scripts.spec.js index 3098492..9a14e0e 100644 --- a/node-scripts/spec/pipeline3/scripts.spec.js +++ b/node-scripts/spec/pipeline3/scripts.spec.js @@ -188,10 +188,17 @@ describe("Scripts", function() { uuid: "1-22-333", scripts: [ { - type: "shell", + type: "dockerExecShell", executionStage: "6", conditions: ["data"], value: "/a/script.sh" + }, + { + type: "hostExecShell", + executionStage: "5", + conditions: ["data", "artifacts", "deployment"], + value: + "sudo chmod 777 -R /var/docker-volumes/ozone/ozone-dev/artifacts" } ], deployment: { @@ -289,7 +296,7 @@ describe("Scripts", function() { script = []; script.push("some commands"); instanceDef.scripts.push({ - type: "shell", + type: "dockerExecShell", executionStage: "6", conditions: ["artifacts"], restart: "true", @@ -303,7 +310,6 @@ describe("Scripts", function() { config, process.env ); - expect(scriptsToRun.script).toEqual([ "some commands", scripts.remote( @@ -435,7 +441,7 @@ describe("Scripts", function() { uuid: "1-22-333", scripts: [ { - type: "shell", + type: "dockerExecShell", executionStage: "6", conditions: ["data"], value: "/a/script.sh" diff --git a/node-scripts/spec/utils/resources/test_instances_1.json b/node-scripts/spec/utils/resources/test_instances_1.json index 65e2e35..bb3e51b 100644 --- a/node-scripts/spec/utils/resources/test_instances_1.json +++ b/node-scripts/spec/utils/resources/test_instances_1.json @@ -212,33 +212,33 @@ ], "scripts": [ { - "type": "shell", + "type": "dockerExecShell", "executionStage": "5", "conditions": ["data"], "value": "/stage/5/script.sh" }, { - "type": "shell", + "type": "dockerExecShell", "executionStage": "5", "conditions": ["data", "artifacts"], "value": "/usr/bin/bahmni -i local.inventory concat-configs" }, { - "type": "shell", + "type": "dockerExecShell", "executionStage": "7", "conditions": ["data", "deployment"], "restart": "false", "value": "/some/script.sh" }, { - "type": "shell", + "type": "dockerExecShell", "executionStage": "7", "conditions": ["data", "deployment"], "restart": "true", "value": "/some/script.sh" }, { - "type": "shell", + "type": "dockerExecShell", "executionStage": "6", "conditions": ["data", "deployment"], "value": "/another/script.sh" diff --git a/node-scripts/src/pipeline3/impl/dockerComposeFromArtifact.js b/node-scripts/src/pipeline3/impl/dockerComposeFromArtifact.js index a62e598..3dadb9d 100644 --- a/node-scripts/src/pipeline3/impl/dockerComposeFromArtifact.js +++ b/node-scripts/src/pipeline3/impl/dockerComposeFromArtifact.js @@ -310,6 +310,11 @@ module.exports = { return script + "\n"; }, + hostExec: command => { + let script = ""; + script += command + "\n"; + return script + "\n"; + }, setProperties: function(instanceDef, property, output) { let script = ""; let path = require("path"); diff --git a/node-scripts/src/pipeline3/impl/dockerComposeGenericMaven.js b/node-scripts/src/pipeline3/impl/dockerComposeGenericMaven.js index 5ce17e0..4f31a86 100644 --- a/node-scripts/src/pipeline3/impl/dockerComposeGenericMaven.js +++ b/node-scripts/src/pipeline3/impl/dockerComposeGenericMaven.js @@ -409,6 +409,11 @@ module.exports = { return script + "\n"; }, + hostExec: command => { + let script = ""; + script += command + "\n"; + return script + "\n"; + }, setProperties: function(instanceDef, property, output) { let script = ""; let path = require("path"); diff --git a/node-scripts/src/pipeline3/impl/dockerComposeGit.js b/node-scripts/src/pipeline3/impl/dockerComposeGit.js index f566379..059fabd 100644 --- a/node-scripts/src/pipeline3/impl/dockerComposeGit.js +++ b/node-scripts/src/pipeline3/impl/dockerComposeGit.js @@ -367,6 +367,11 @@ module.exports = { return script + "\n"; }, + hostExec: command => { + let script = ""; + script += command + "\n"; + return script + "\n"; + }, setProperties: function(instanceDef, property, output) { let script = ""; let path = require("path"); diff --git a/node-scripts/src/pipeline3/impl/dockerComposeMaven.js b/node-scripts/src/pipeline3/impl/dockerComposeMaven.js index 062b401..9fbfd9b 100644 --- a/node-scripts/src/pipeline3/impl/dockerComposeMaven.js +++ b/node-scripts/src/pipeline3/impl/dockerComposeMaven.js @@ -157,6 +157,7 @@ module.exports = { down: dockerComposeGit.down, pull: dockerComposeGit.pull, exec: dockerComposeGit.exec, + hostExec: dockerComposeGit.hostExec, setProperties: dockerComposeGit.setProperties, setLinks: dockerComposeGit.setLinks, getInstanceServicesAsStringList: diff --git a/node-scripts/src/pipeline3/impl/dockerMonolith.js b/node-scripts/src/pipeline3/impl/dockerMonolith.js index 09751fb..ec7f199 100644 --- a/node-scripts/src/pipeline3/impl/dockerMonolith.js +++ b/node-scripts/src/pipeline3/impl/dockerMonolith.js @@ -331,6 +331,12 @@ module.exports = { return script + "\n"; }, + hostExec: command => { + let script = ""; + script += command + "\n"; + return script + "\n"; + }, + /** * Copy 'source' located on the host to the container's 'destination'. * diff --git a/node-scripts/src/pipeline3/scripts.js b/node-scripts/src/pipeline3/scripts.js index 0003cf4..c80fc60 100644 --- a/node-scripts/src/pipeline3/scripts.js +++ b/node-scripts/src/pipeline3/scripts.js @@ -479,7 +479,8 @@ module.exports = { instanceDef, currentStage, config, - processEnv + processEnv, + postStart = true ) { var changes = []; if (processEnv[config.varArtifactsChanges()] === "true") { @@ -511,11 +512,16 @@ module.exports = { var deploymentTypeScripts = require("./impl/" + instanceDef.deployment.type); var runScript = ""; - if (item.type === "shell") { + if (item.type === "dockerExecShell" && postStart) { runScript += module.exports.remote( ssh, deploymentTypeScripts.exec(instanceDef, item.value, item.service) ); + } else if (item.type === "hostExecShell" && !postStart) { + runScript += module.exports.remote( + ssh, + deploymentTypeScripts.hostExec(item.value) + ); } else if (item.type === "python") { // TODO: to be implemented } else if (item.type === "sql") { diff --git a/node-scripts/src/pipeline3/start-instance.js b/node-scripts/src/pipeline3/start-instance.js index 252b6db..fa64962 100644 --- a/node-scripts/src/pipeline3/start-instance.js +++ b/node-scripts/src/pipeline3/start-instance.js @@ -49,6 +49,16 @@ script.headComment = "# Autogenerated script for the instance start/restart..."; script.body = []; script.body.push("set -e\n"); +var computedPreStartScripts = scripts.computeAdditionalScripts( + script.body, + instanceDef, + currentStage, + config, + process.env, + false +); +script.body = computedPreStartScripts.script; + // 'artifacts' if (process.env[config.varArtifactsChanges()] === "true") { @@ -96,14 +106,14 @@ if (process.env[config.varPropertiesChanges()] === "true") { } // Set the Timezone if provided -var computedScript = scripts.computeAdditionalScripts( +var computedPostStartScript = scripts.computeAdditionalScripts( script.body, instanceDef, currentStage, config, process.env ); -script.body = computedScript.script; +script.body = computedPostStartScript.script; // Final restart if (!(process.env[config.varDeploymentChanges()] === "true")) {