Skip to content

Commit

Permalink
INFRA-412: Add support for arbitrary scripts on host (#45)
Browse files Browse the repository at this point in the history
* INFRA-412: Add support for arbitrary scripts on host

* Remove debug lines

* Update bash to shell
  • Loading branch information
enyachoke authored Apr 9, 2024
1 parent 1cf84cf commit 0d7f989
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 13 deletions.
14 changes: 10 additions & 4 deletions node-scripts/spec/pipeline3/scripts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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",
Expand All @@ -303,7 +310,6 @@ describe("Scripts", function() {
config,
process.env
);

expect(scriptsToRun.script).toEqual([
"some commands",
scripts.remote(
Expand Down Expand Up @@ -435,7 +441,7 @@ describe("Scripts", function() {
uuid: "1-22-333",
scripts: [
{
type: "shell",
type: "dockerExecShell",
executionStage: "6",
conditions: ["data"],
value: "/a/script.sh"
Expand Down
10 changes: 5 additions & 5 deletions node-scripts/spec/utils/resources/test_instances_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions node-scripts/src/pipeline3/impl/dockerComposeFromArtifact.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions node-scripts/src/pipeline3/impl/dockerComposeGenericMaven.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions node-scripts/src/pipeline3/impl/dockerComposeGit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions node-scripts/src/pipeline3/impl/dockerComposeMaven.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions node-scripts/src/pipeline3/impl/dockerMonolith.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
*
Expand Down
10 changes: 8 additions & 2 deletions node-scripts/src/pipeline3/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ module.exports = {
instanceDef,
currentStage,
config,
processEnv
processEnv,
postStart = true
) {
var changes = [];
if (processEnv[config.varArtifactsChanges()] === "true") {
Expand Down Expand Up @@ -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") {
Expand Down
14 changes: 12 additions & 2 deletions node-scripts/src/pipeline3/start-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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")) {
Expand Down

0 comments on commit 0d7f989

Please sign in to comment.