cob-cli 2.53.0-beta-1 → 2.53.0-beta-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/handleAutoComplete.js +19 -4
- package/lib/commands/cleanup.js +13 -3
- package/lib/commands/deploy.js +33 -34
- package/lib/commands/test.js +4 -1
- package/lib/task_lists/common_enviromentHandler.js +9 -3
- package/lib/task_lists/common_helpers.js +36 -4
- package/lib/task_lists/common_releaseManager.js +10 -8
- package/lib/task_lists/common_syncFiles.js +5 -5
- package/lib/task_lists/test_otherFilesContiousReload.js +8 -7
- package/lib/task_lists/test_syncFile.js +5 -4
- package/lib/task_lists/test_validate.js +3 -2
- package/package.json +1 -1
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
2
3
|
|
|
3
4
|
/* Autocomplete Component*/
|
|
4
5
|
var omelette = require('omelette');
|
|
5
6
|
const commandStructure = {
|
|
6
|
-
'init' : [],
|
|
7
|
-
'customize' : [],
|
|
8
|
-
'test' : [],
|
|
9
|
-
'deploy' : [],
|
|
7
|
+
'init' : [],
|
|
8
|
+
'customize' : [],
|
|
9
|
+
'test' : [],
|
|
10
|
+
'deploy' : [],
|
|
10
11
|
'updateFromServer' : [],
|
|
11
12
|
'upgradeRepo' : []
|
|
12
13
|
}
|
|
@@ -19,9 +20,23 @@ if (~process.argv.indexOf('--setup')) {
|
|
|
19
20
|
// we exit cleanly so that postinstall completes successfuly
|
|
20
21
|
process.exit(0)
|
|
21
22
|
}
|
|
23
|
+
if (isAutocompleteAlreadyInstalled()) {
|
|
24
|
+
console.log("Autocomplete already set up, skipping.")
|
|
25
|
+
process.exit(0)
|
|
26
|
+
}
|
|
22
27
|
console.log("Setting up...")
|
|
23
28
|
completion.setupShellInitFile()
|
|
24
29
|
}
|
|
30
|
+
|
|
31
|
+
function isAutocompleteAlreadyInstalled() {
|
|
32
|
+
try {
|
|
33
|
+
const initFile = completion.getDefaultShellInitFile()
|
|
34
|
+
if (!initFile || !fs.existsSync(initFile)) return false
|
|
35
|
+
return fs.readFileSync(initFile, 'utf8').includes('# begin cob-cli completion')
|
|
36
|
+
} catch (e) {
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
}
|
|
25
40
|
// remove from system profiles
|
|
26
41
|
if (~process.argv.indexOf('--cleanup')) {
|
|
27
42
|
if (process.platform === 'win32') {
|
package/lib/commands/cleanup.js
CHANGED
|
@@ -11,6 +11,7 @@ const { SERVER_COB_CLI_DIRECTORY } = require("../task_lists/common_helpers");
|
|
|
11
11
|
const { restoreServerFilesToLastDeployed } = require("../task_lists/test_otherFilesContiousReload");
|
|
12
12
|
const { loadOperationState, clearOperationState } = require("../task_lists/common_operationState");
|
|
13
13
|
const { checkRepoVersion } = require("../commands/upgradeRepo");
|
|
14
|
+
const { getSshArgs } = require("../task_lists/common_helpers");
|
|
14
15
|
|
|
15
16
|
const LOCAL_TEST_LOCK_FILE = ".test.in.execution";
|
|
16
17
|
const SERVER_TEST_LOCK_FILE = SERVER_COB_CLI_DIRECTORY + "test.in.execution";
|
|
@@ -20,6 +21,10 @@ async function cleanup(args) {
|
|
|
20
21
|
checkRepoVersion()
|
|
21
22
|
|
|
22
23
|
const savedState = loadOperationState();
|
|
24
|
+
if (!savedState && !args.environment) {
|
|
25
|
+
console.log("No saved state and no explicit environment, aborting".bold);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
23
28
|
if (savedState) {
|
|
24
29
|
if (!args.environment) args.environment = savedState.environment;
|
|
25
30
|
if (!args.servername) args.servername = savedState.servername;
|
|
@@ -50,11 +55,16 @@ async function cleanup(args) {
|
|
|
50
55
|
task: async () => {
|
|
51
56
|
let changedFiles = [];
|
|
52
57
|
try {
|
|
53
|
-
const result = await execa('ssh', [cmdEnv.server, "cat " + SERVER_TEST_LOCK_FILE]);
|
|
58
|
+
const result = await execa('ssh', [...getSshArgs(cmdEnv.server), "cat " + SERVER_TEST_LOCK_FILE]);
|
|
54
59
|
changedFiles = result.stdout.split("\n")
|
|
55
60
|
.map(l => l.split(" ")[0].trim())
|
|
56
61
|
.filter(f => f);
|
|
57
|
-
} catch {
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (error.exitCode === 255) {
|
|
64
|
+
throw new Error(`SSH connection to '${cmdEnv.server}' failed: ${error.shortMessage}`);
|
|
65
|
+
}
|
|
66
|
+
/* no test.in.execution on server = nothing to restore */
|
|
67
|
+
}
|
|
58
68
|
|
|
59
69
|
if (changedFiles.length === 0) return;
|
|
60
70
|
|
|
@@ -77,7 +87,7 @@ async function cleanup(args) {
|
|
|
77
87
|
{
|
|
78
88
|
title: "Remove server test lock file".bold,
|
|
79
89
|
skip: () => args.localOnly ? "Skipping server cleanup (--localOnly)" : false,
|
|
80
|
-
task: () => execa('ssh', [cmdEnv.server, "rm -f " + SERVER_TEST_LOCK_FILE])
|
|
90
|
+
task: () => execa('ssh', [...getSshArgs(cmdEnv.server), "rm -f " + SERVER_TEST_LOCK_FILE])
|
|
81
91
|
.catch(() => {}) // non-critical if server unreachable
|
|
82
92
|
},
|
|
83
93
|
], {
|
package/lib/commands/deploy.js
CHANGED
|
@@ -7,46 +7,45 @@ const { checkRepoVersion } = require("../commands/upgradeRepo");
|
|
|
7
7
|
const { saveOperationState, clearOperationState, checkNoInterruptedRun } = require("../task_lists/common_operationState");
|
|
8
8
|
|
|
9
9
|
async function deploy(args) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
saveOperationState(cmdEnv.name, cmdEnv.servername)
|
|
16
|
-
stateSaved = true
|
|
17
|
-
if(args.resync) args.force = true;
|
|
10
|
+
checkRepoVersion()
|
|
11
|
+
const cmdEnv = await getCurrentCommandEnviroment(args)
|
|
12
|
+
await checkNoInterruptedRun()
|
|
13
|
+
saveOperationState(cmdEnv.name, cmdEnv.servername)
|
|
14
|
+
if(args.resync) args.force = true;
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
console.log(`Checking conditions to deploy ${cmdEnv.branchStr} to ${cmdEnv.serverStr}...` );
|
|
20
17
|
|
|
18
|
+
try {
|
|
21
19
|
await validateDeployConditions(cmdEnv,args).run()
|
|
20
|
+
} catch (err) {
|
|
21
|
+
// we should clear the operation state
|
|
22
|
+
clearOperationState();
|
|
23
|
+
throw err
|
|
24
|
+
}
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
await cmdEnv.applyCurrentCommandEnvironmentChanges()
|
|
27
|
+
let changes = [];
|
|
28
|
+
try {
|
|
29
|
+
changes = await confirmExecutionOfChanges(cmdEnv)
|
|
30
|
+
} catch (err) {
|
|
31
|
+
await cmdEnv.unApplyCurrentCommandEnvironmentChanges()
|
|
32
|
+
clearOperationState()
|
|
33
|
+
throw err
|
|
34
|
+
}
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
console.log(" Just updating deploy information.")
|
|
36
|
+
if(changes.length == 0) {
|
|
37
|
+
if(!args.force) {
|
|
38
|
+
await cmdEnv.unApplyCurrentCommandEnvironmentChanges()
|
|
39
|
+
clearOperationState()
|
|
40
|
+
console.log("\nCanceled!".yellow + " nothing todo\n")
|
|
41
|
+
return
|
|
40
42
|
}
|
|
43
|
+
console.log(" Just updating deploy information.")
|
|
44
|
+
}
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (stateSaved) clearOperationState()
|
|
45
|
-
console.log("\nDone!".green, "\nEnjoy!")
|
|
46
|
+
await executeTasks(cmdEnv, args).run();
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
console.error("\n",err.message);
|
|
50
|
-
}
|
|
48
|
+
clearOperationState()
|
|
49
|
+
console.log("\nDone!".green, "\nEnjoy!")
|
|
51
50
|
}
|
|
52
|
-
module.exports = deploy;
|
|
51
|
+
module.exports = deploy;
|
package/lib/commands/test.js
CHANGED
|
@@ -13,6 +13,7 @@ async function test (args) {
|
|
|
13
13
|
let cmdEnv
|
|
14
14
|
let spawned
|
|
15
15
|
let stateSaved = false
|
|
16
|
+
let envChangesApplied = false
|
|
16
17
|
|
|
17
18
|
let rejectOnSignal;
|
|
18
19
|
const signalPromise = new Promise((_, reject) => { rejectOnSignal = reject; });
|
|
@@ -31,9 +32,11 @@ async function test (args) {
|
|
|
31
32
|
if(!args.localOnly) {
|
|
32
33
|
await validateTestingConditions(cmdEnv, args)
|
|
33
34
|
await cmdEnv.applyCurrentCommandEnvironmentChanges()
|
|
35
|
+
envChangesApplied = true
|
|
34
36
|
restoreChanges = await otherFilesContiousReload(cmdEnv)
|
|
35
37
|
} else {
|
|
36
38
|
await cmdEnv.applyCurrentCommandEnvironmentChanges()
|
|
39
|
+
envChangesApplied = true
|
|
37
40
|
}
|
|
38
41
|
spawned = await customUIsContinuosReload(cmdEnv, args.dashboard)
|
|
39
42
|
|
|
@@ -52,8 +55,8 @@ async function test (args) {
|
|
|
52
55
|
process.off('SIGTERM', handleSignal);
|
|
53
56
|
process.off('SIGHUP', handleSignal);
|
|
54
57
|
try { process.stdin.setRawMode(false); } catch {}
|
|
55
|
-
cmdEnv && await cmdEnv.unApplyCurrentCommandEnvironmentChanges() // Repõe as configurações
|
|
56
58
|
restoreChanges && await restoreChanges()
|
|
59
|
+
envChangesApplied && cmdEnv && await cmdEnv.unApplyCurrentCommandEnvironmentChanges() // Repõe as configurações
|
|
57
60
|
if (stateSaved) clearOperationState()
|
|
58
61
|
spawned && await spawned.stop();
|
|
59
62
|
// Dá tempo aos subprocessos para morrer (acho que já não é preciso)
|
|
@@ -5,6 +5,7 @@ const git = require('simple-git');
|
|
|
5
5
|
const fs = require('fs-extra');
|
|
6
6
|
const { getCurrentBranch } = require("./common_releaseManager");
|
|
7
7
|
const { SERVER_COB_CLI_DIRECTORY } = require("./common_helpers")
|
|
8
|
+
const { getSshArgs } = require("./common_helpers")
|
|
8
9
|
|
|
9
10
|
const SERVER_LAST_ENV_FILE = SERVER_COB_CLI_DIRECTORY + "lastDeployEnv";
|
|
10
11
|
|
|
@@ -66,7 +67,7 @@ exports.getCurrentCommandEnviroment = getCurrentCommandEnviroment;
|
|
|
66
67
|
|
|
67
68
|
/* ************************************ */
|
|
68
69
|
async function _applySpecific(environmentName) {
|
|
69
|
-
const envSpecificFiles = await fg(['**/*.ENV__'+ environmentName +'__.*'], { onlyFiles: false, dot: true });
|
|
70
|
+
const envSpecificFiles = await fg(['**/*.ENV__'+ environmentName +'__.*'], { onlyFiles: false, dot: true });
|
|
70
71
|
|
|
71
72
|
for( let envSpecificFile of envSpecificFiles ) {
|
|
72
73
|
let prodFile = envSpecificFile.replace(/\.ENV__.*__/,"")
|
|
@@ -120,6 +121,8 @@ function _getDefaultServerForEnvironment(environmentName) {
|
|
|
120
121
|
|
|
121
122
|
/* ************************************ */
|
|
122
123
|
function _getServerSSHFQDN(servername) {
|
|
124
|
+
// return IPs as-is
|
|
125
|
+
if (servername.includes(".")) return servername;
|
|
123
126
|
return servername + ".cultofbits.pt";
|
|
124
127
|
}
|
|
125
128
|
|
|
@@ -131,16 +134,19 @@ function _getServerHTTPsFQDN(servername) {
|
|
|
131
134
|
/* ************************************ */
|
|
132
135
|
async function _getLastEnvironmentDeployed(server) {
|
|
133
136
|
try {
|
|
134
|
-
let result = await execa('ssh', [server, "cat " + SERVER_LAST_ENV_FILE ]);
|
|
137
|
+
let result = await execa('ssh', [...getSshArgs(server), "cat " + SERVER_LAST_ENV_FILE ]);
|
|
135
138
|
return result.stdout;
|
|
136
139
|
} catch (error) {
|
|
140
|
+
if (error.exitCode === 255) {
|
|
141
|
+
throw new Error(`SSH connection to '${server}' failed: ${error.shortMessage}`);
|
|
142
|
+
}
|
|
137
143
|
return "prod"
|
|
138
144
|
}
|
|
139
145
|
}
|
|
140
146
|
|
|
141
147
|
/* ************************************ */
|
|
142
148
|
async function _setLastEnvironmentDeployed(server, environmentName) {
|
|
143
|
-
await execa('ssh', [server, "echo '" + environmentName + "' > " + SERVER_LAST_ENV_FILE ]);
|
|
149
|
+
await execa('ssh', [...getSshArgs(server), "echo '" + environmentName + "' > " + SERVER_LAST_ENV_FILE ]);
|
|
144
150
|
}
|
|
145
151
|
|
|
146
152
|
/* ************************************ */
|
|
@@ -5,6 +5,38 @@ const fs = require("fs/promises");
|
|
|
5
5
|
|
|
6
6
|
const SERVER_COB_CLI_DIRECTORY = "/opt/cob-cli/";
|
|
7
7
|
|
|
8
|
+
/* ************************************ */
|
|
9
|
+
function getSshArgs(server) {
|
|
10
|
+
const args = [
|
|
11
|
+
"-o", "StrictHostKeyChecking=no",
|
|
12
|
+
"-o", "PreferredAuthentications=publickey",
|
|
13
|
+
"-o", "BatchMode=yes",
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
if (process.env.COB_SSH_PORT) args.push("-p", process.env.COB_SSH_PORT);
|
|
17
|
+
if (process.env.COB_SSH_IDENTITY) args.push("-i", process.env.COB_SSH_IDENTITY);
|
|
18
|
+
|
|
19
|
+
const target = process.env.COB_SSH_USER ? `${process.env.COB_SSH_USER}@${server}` : server;
|
|
20
|
+
args.push(target);
|
|
21
|
+
|
|
22
|
+
return args;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* ************************************ */
|
|
26
|
+
function getServerAddress(server) {
|
|
27
|
+
return process.env.COB_SSH_USER ? `${process.env.COB_SSH_USER}@${server}` : server;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* ************************************ */
|
|
31
|
+
function getRsyncSsh() {
|
|
32
|
+
let cmd = "ssh -o ConnectTimeout=30 -o ServerAliveInterval=30 -o ServerAliveCountMax=30 -o StrictHostKeyChecking=no";
|
|
33
|
+
|
|
34
|
+
if (process.env.COB_SSH_IDENTITY) cmd += ` -i '${process.env.COB_SSH_IDENTITY}'`;
|
|
35
|
+
if (process.env.COB_SSH_PORT) cmd += ` -p ${process.env.COB_SSH_PORT}`;
|
|
36
|
+
|
|
37
|
+
return cmd;
|
|
38
|
+
}
|
|
39
|
+
|
|
8
40
|
/* **************************************************************************************** */
|
|
9
41
|
async function checkWorkingCopyCleanliness(testNotDetached=true) {
|
|
10
42
|
const git = require('simple-git');
|
|
@@ -37,11 +69,8 @@ async function checkWorkingCopyCleanliness(testNotDetached=true) {
|
|
|
37
69
|
function checkConnectivity(server) {
|
|
38
70
|
const execa = require('execa');
|
|
39
71
|
return execa('ssh', [
|
|
40
|
-
"-o", "StrictHostKeyChecking=no",
|
|
41
|
-
"-o", "PreferredAuthentications=publickey",
|
|
42
|
-
"-o", "BatchMode=yes",
|
|
43
72
|
"-o", "ConnectTimeout=15",
|
|
44
|
-
server,
|
|
73
|
+
...getSshArgs(server),
|
|
45
74
|
"test -w /etc/recordm/services/com.cultofbits.web.integration.properties && exit || exit 1"
|
|
46
75
|
])
|
|
47
76
|
}
|
|
@@ -109,6 +138,9 @@ async function readYamlFile(filename) {
|
|
|
109
138
|
/* ************************************ */
|
|
110
139
|
module.exports = {
|
|
111
140
|
SERVER_COB_CLI_DIRECTORY : SERVER_COB_CLI_DIRECTORY,
|
|
141
|
+
getSshArgs: getSshArgs,
|
|
142
|
+
getServerAddress: getServerAddress,
|
|
143
|
+
getRsyncSsh: getRsyncSsh,
|
|
112
144
|
checkConnectivity: checkConnectivity,
|
|
113
145
|
checkWorkingCopyCleanliness: checkWorkingCopyCleanliness,
|
|
114
146
|
getKeypress: getKeypress,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
const execa = require('execa');
|
|
2
|
-
const fs = require('fs-extra');
|
|
3
2
|
const git = require('simple-git');
|
|
4
3
|
|
|
5
4
|
const SERVER_CHANGELOG = "/opt/cob-cli/DEPLOYLOG.md";
|
|
6
5
|
const LAST_SHA_FILE = "lastDeploySha"
|
|
7
|
-
const { SERVER_COB_CLI_DIRECTORY } = require("./common_helpers");
|
|
6
|
+
const { SERVER_COB_CLI_DIRECTORY, getSshArgs } = require("./common_helpers");
|
|
8
7
|
const SERVER_LAST_SHA_FILE = SERVER_COB_CLI_DIRECTORY + LAST_SHA_FILE;
|
|
9
8
|
|
|
10
9
|
/* ************************************ */
|
|
@@ -44,18 +43,18 @@ async function registerRelease(cmdEnv) {
|
|
|
44
43
|
const dateTimeStr = date.toISOString().slice(0,16).replace(/T/," ")
|
|
45
44
|
const deploySignature = cmdEnv.servername + "_" + dateStr
|
|
46
45
|
const newDeployText = `${dateTimeStr} ${user} [${currentSha}/${cmdEnv.currentBranch}]`
|
|
47
|
-
await execa('ssh', [cmdEnv.server, "echo $'" + newDeployText + "\n" + diffs.replace(/'/g,"\\'") + "' >> " + SERVER_CHANGELOG])
|
|
46
|
+
await execa('ssh', [...getSshArgs(cmdEnv.server), "echo $'" + newDeployText + "\n" + diffs.replace(/'/g,"\\'") + "' >> " + SERVER_CHANGELOG])
|
|
48
47
|
|
|
49
48
|
if (diffs) {
|
|
50
49
|
// Add deploy tags to repo
|
|
51
|
-
git().fetch(["--tags","-f"]) // Apenas para ter certeza que temos todas as tags
|
|
50
|
+
await git().fetch(["--tags","-f"]) // Apenas para ter certeza que temos todas as tags
|
|
52
51
|
try {
|
|
53
52
|
await git().silent(true).tag([deploySignature, "-d"])
|
|
54
53
|
} catch {}
|
|
55
54
|
|
|
56
55
|
await git().addAnnotatedTag(deploySignature, newDeployText )
|
|
57
56
|
await git().push(["-f", "origin", deploySignature])
|
|
58
|
-
git().fetch(["--tags","-f"]) // Apenas para ter certeza que temos todas as tags
|
|
57
|
+
await git().fetch(["--tags","-f"]) // Apenas para ter certeza que temos todas as tags
|
|
59
58
|
}
|
|
60
59
|
_setLastDeployedSha(cmdEnv.server, currentSha);
|
|
61
60
|
}
|
|
@@ -65,9 +64,12 @@ exports.registerRelease = registerRelease;
|
|
|
65
64
|
async function getLastDeployedSha(server) {
|
|
66
65
|
let result
|
|
67
66
|
try {
|
|
68
|
-
result = await execa('ssh', [server, "cat " + SERVER_LAST_SHA_FILE ]);
|
|
67
|
+
result = await execa('ssh', [...getSshArgs(server), "cat " + SERVER_LAST_SHA_FILE ]);
|
|
69
68
|
} catch (error) {
|
|
70
|
-
|
|
69
|
+
if (error.exitCode === 255) {
|
|
70
|
+
throw new Error(`SSH connection to '${server}' failed: ${error.shortMessage}`);
|
|
71
|
+
}
|
|
72
|
+
await execa('ssh', [...getSshArgs(server), "mkdir -p " + SERVER_COB_CLI_DIRECTORY ]);
|
|
71
73
|
return null
|
|
72
74
|
}
|
|
73
75
|
return result.stdout;
|
|
@@ -76,7 +78,7 @@ exports.getLastDeployedSha = getLastDeployedSha;
|
|
|
76
78
|
|
|
77
79
|
/* ************************************ */
|
|
78
80
|
function _setLastDeployedSha(server, lastSha) {
|
|
79
|
-
execa('ssh', [server, "echo '" + lastSha + "' > " + SERVER_LAST_SHA_FILE ]);
|
|
81
|
+
execa('ssh', [...getSshArgs(server), "echo '" + lastSha + "' > " + SERVER_LAST_SHA_FILE ]);
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
/* ************************************ */
|
|
@@ -2,6 +2,7 @@ const execa = require('execa');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const fs = require('fs-extra');
|
|
4
4
|
const { getKeypress } = require("../task_lists/common_helpers");
|
|
5
|
+
const { getRsyncSsh, getServerAddress } = require("./common_helpers");
|
|
5
6
|
|
|
6
7
|
/* ************************************ */
|
|
7
8
|
const COB_PRODUCTS = ["recordm", "integrationm", "recordm-importer", "reportm", "userm", "confm", "others", "authm", "public"];
|
|
@@ -32,7 +33,6 @@ async function _syncFiles(executionType, cmdEnv, from, to, extraOptions = [], ar
|
|
|
32
33
|
return new Promise(async (resolve, reject) => {
|
|
33
34
|
let fromPath = resolveCobPath(cmdEnv.server, from, product);
|
|
34
35
|
let toPath = resolveCobPath(cmdEnv.server, to, product);
|
|
35
|
-
if (toPath.startsWith('.') && !fs.existsSync(toPath)) fs.mkdirSync(toPath)
|
|
36
36
|
let productExtraOptions = extraOptions.map( option => option.replace(/=.*\|/,"="))
|
|
37
37
|
productExtraOptions = productExtraOptions.filter( option => option.indexOf("|") < 0 )
|
|
38
38
|
|
|
@@ -65,7 +65,7 @@ async function _syncFiles(executionType, cmdEnv, from, to, extraOptions = [], ar
|
|
|
65
65
|
}
|
|
66
66
|
await execa('rsync', rsyncArgs, {
|
|
67
67
|
shell: true,
|
|
68
|
-
env: { "RSYNC_RSH":
|
|
68
|
+
env: { "RSYNC_RSH": getRsyncSsh() }
|
|
69
69
|
})
|
|
70
70
|
.then((value) => {
|
|
71
71
|
if (args.verbose > 3)
|
|
@@ -170,7 +170,7 @@ function resolveCobPath(server, type, product) {
|
|
|
170
170
|
return "./" + product + "/";
|
|
171
171
|
|
|
172
172
|
case "serverInitial":
|
|
173
|
-
return server + ":/opt/" + product + "/etc.default/";
|
|
173
|
+
return getServerAddress(server) + ":/opt/" + product + "/etc.default/";
|
|
174
174
|
|
|
175
175
|
case "serverLive":
|
|
176
176
|
switch (product) {
|
|
@@ -178,9 +178,9 @@ function resolveCobPath(server, type, product) {
|
|
|
178
178
|
return server + ":/usr/share/cob/"
|
|
179
179
|
case "recordm-importer":
|
|
180
180
|
case "others":
|
|
181
|
-
return server + ':' + "/opt/" + product + "/";
|
|
181
|
+
return getServerAddress(server) + ':' + "/opt/" + product + "/";
|
|
182
182
|
default:
|
|
183
|
-
return server + ':' + "/etc/" + product + "/";
|
|
183
|
+
return getServerAddress(server) + ':' + "/etc/" + product + "/";
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
case "staging":
|
|
@@ -7,6 +7,7 @@ const { SERVER_COB_CLI_DIRECTORY } = require("./common_helpers");
|
|
|
7
7
|
const { confirmExecutionOfChanges, resolveCobPath } = require("./common_syncFiles");
|
|
8
8
|
const { syncFile } = require("./test_syncFile");
|
|
9
9
|
const { getLastDeployedSha } = require("./common_releaseManager");
|
|
10
|
+
const { getSshArgs } = require("./common_helpers");
|
|
10
11
|
|
|
11
12
|
const IN_PROGRESS_TEST_FILE = "test.in.execution"
|
|
12
13
|
const SERVER_IN_PROGRESS_TEST_FILE = SERVER_COB_CLI_DIRECTORY + IN_PROGRESS_TEST_FILE
|
|
@@ -18,7 +19,7 @@ async function otherFilesContiousReload(cmdEnv) {
|
|
|
18
19
|
let changedFiles = new Set()
|
|
19
20
|
|
|
20
21
|
let currentTestsFilesList = []
|
|
21
|
-
await execa('ssh', [cmdEnv.server, "cat " + SERVER_IN_PROGRESS_TEST_FILE])
|
|
22
|
+
await execa('ssh', [...getSshArgs(cmdEnv.server), "cat " + SERVER_IN_PROGRESS_TEST_FILE])
|
|
22
23
|
.then( value => currentTestsFilesList = value.stdout.split("\n").map(l => l.substring(0,l.indexOf(" "))) )
|
|
23
24
|
.catch( () => { } ) /* grep returns error if no match and execa throws an excepcions when return is error */
|
|
24
25
|
|
|
@@ -56,7 +57,7 @@ async function otherFilesContiousReload(cmdEnv) {
|
|
|
56
57
|
let productDir = resolveCobPath(cmdEnv.server, "serverLive", product).split(":")[1];
|
|
57
58
|
let productScopeFilePath = changedFile.substring(changedFile.indexOf("/") + 1); // remove o directorio inicial do producto
|
|
58
59
|
|
|
59
|
-
let isRemoteFile = () => execa('ssh', [cmdEnv.server, "[[ -f " + productDir + productScopeFilePath + " ]] && echo 'file' || echo '' " ])
|
|
60
|
+
let isRemoteFile = () => execa('ssh', [...getSshArgs(cmdEnv.server), "[[ -f " + productDir + productScopeFilePath + " ]] && echo 'file' || echo '' " ])
|
|
60
61
|
.then( r => {
|
|
61
62
|
return r.stdout == "file"
|
|
62
63
|
}).catch( () => {
|
|
@@ -126,7 +127,7 @@ async function restoreServerFilesToLastDeployed(cmdEnv, changedFiles) {
|
|
|
126
127
|
|
|
127
128
|
await cmdEnv.unApplyLastEnvironmentDeployedToServerChanges();
|
|
128
129
|
|
|
129
|
-
await execa('ssh', [cmdEnv.server, "find " + SERVER_IN_PROGRESS_TEST_FILE + " -size 0 -delete"])
|
|
130
|
+
await execa('ssh', [...getSshArgs(cmdEnv.server), "find " + SERVER_IN_PROGRESS_TEST_FILE + " -size 0 -delete"])
|
|
130
131
|
.catch(() => {});
|
|
131
132
|
|
|
132
133
|
await git().checkout("-");
|
|
@@ -137,7 +138,7 @@ exports.restoreServerFilesToLastDeployed = restoreServerFilesToLastDeployed
|
|
|
137
138
|
/* ************************************ */
|
|
138
139
|
async function addFileToCurrentTest(server, changedFile, changedFiles, changeType, restoreChanges) {
|
|
139
140
|
let inUse = "";
|
|
140
|
-
await execa('ssh', [server, "grep -F '" + changedFile + " ' " + SERVER_IN_PROGRESS_TEST_FILE ])
|
|
141
|
+
await execa('ssh', [...getSshArgs(server), "grep -F '" + changedFile + " ' " + SERVER_IN_PROGRESS_TEST_FILE ])
|
|
141
142
|
.then( value => inUse = value.stdout )
|
|
142
143
|
.catch( () => { } ) /* grep returns error if no match and execa throws an excepcions when return is error */
|
|
143
144
|
.finally( async () => {
|
|
@@ -153,7 +154,7 @@ async function addFileToCurrentTest(server, changedFile, changedFiles, changeTyp
|
|
|
153
154
|
|
|
154
155
|
if(!changedFiles.has(changedFile)) {
|
|
155
156
|
const user = require("os").userInfo().username;
|
|
156
|
-
execa('ssh', [server, "echo '" + changedFile + " by " + user + "' >> " + SERVER_IN_PROGRESS_TEST_FILE]);
|
|
157
|
+
execa('ssh', [...getSshArgs(server), "echo '" + changedFile + " by " + user + "' >> " + SERVER_IN_PROGRESS_TEST_FILE]);
|
|
157
158
|
changedFiles.add(changedFile);
|
|
158
159
|
}
|
|
159
160
|
console.log(" " + changeType.replace(/(e)([^e]*)$/, "ed$2 ") + changedFile);
|
|
@@ -163,14 +164,14 @@ async function addFileToCurrentTest(server, changedFile, changedFiles, changeTyp
|
|
|
163
164
|
/* ************************************ */
|
|
164
165
|
async function removeFileFromCurrentTest(server, changedFile) {
|
|
165
166
|
await syncFile(server, changedFile);
|
|
166
|
-
await execa('ssh', [server, "sed -i '/" + changedFile.split("/").join("\\/") + "/d' " + SERVER_IN_PROGRESS_TEST_FILE]).catch( () => {/* ignore files removed by user */} );
|
|
167
|
+
await execa('ssh', [...getSshArgs(server), "sed -i '/" + changedFile.split("/").join("\\/") + "/d' " + SERVER_IN_PROGRESS_TEST_FILE]).catch( () => {/* ignore files removed by user */} );
|
|
167
168
|
console.log(" reset ".brightGreen + changedFile);
|
|
168
169
|
}
|
|
169
170
|
exports.removeFileFromCurrentTest = removeFileFromCurrentTest
|
|
170
171
|
|
|
171
172
|
/* ************************************ */
|
|
172
173
|
function checkNoTestsRunningOnServer(server) {
|
|
173
|
-
return execa('ssh', [server, "cat " + SERVER_IN_PROGRESS_TEST_FILE])
|
|
174
|
+
return execa('ssh', [...getSshArgs(server), "cat " + SERVER_IN_PROGRESS_TEST_FILE])
|
|
174
175
|
.then(value => {
|
|
175
176
|
throw new Error(
|
|
176
177
|
"Aborted:".red + " there are tests running with files changed on the server:\n "
|
|
@@ -2,6 +2,7 @@ const execa = require('execa');
|
|
|
2
2
|
const fs = require('fs-extra');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const { resolveCobPath } = require("./common_syncFiles");
|
|
5
|
+
const { getSshArgs, getRsyncSsh } = require("./common_helpers");
|
|
5
6
|
|
|
6
7
|
const DEBUG = false;
|
|
7
8
|
const RSYNC_RETRIES = 10;
|
|
@@ -18,7 +19,7 @@ async function syncFile(server, localFile) {
|
|
|
18
19
|
|
|
19
20
|
let count = 0;
|
|
20
21
|
while (count < RSYNC_RETRIES) {
|
|
21
|
-
await execa('ssh', [server, "mkdir -p " + remoteFileDir]).catch({});
|
|
22
|
+
await execa('ssh', [...getSshArgs(server), "mkdir -p " + remoteFileDir]).catch({});
|
|
22
23
|
await execa('rsync', [localFile, remoteProductPath + productScopeFilePath,
|
|
23
24
|
"-acz",
|
|
24
25
|
"--prune-empty-dirs",
|
|
@@ -28,17 +29,17 @@ async function syncFile(server, localFile) {
|
|
|
28
29
|
"--no-t",
|
|
29
30
|
"--filter='merge " + path.resolve(__dirname,"rsyncFilter-pre.txt") + "'",
|
|
30
31
|
"--filter='merge " + path.resolve(__dirname,"rsyncFilter-post.txt") + "'"],
|
|
31
|
-
{ shell: true, env: { "RSYNC_RSH":
|
|
32
|
+
{ shell: true, env: { "RSYNC_RSH": getRsyncSsh() } })
|
|
32
33
|
.then(count = RSYNC_RETRIES)
|
|
33
34
|
.catch(async (err) => {
|
|
34
35
|
// exitCode 23 indicam que o ficheiro não existe na origem. Temod de apagar no destino.
|
|
35
36
|
if (err.exitCode == 23) {
|
|
36
|
-
await execa('ssh', [server, "rm -fd " + remoteProductPath.split(":")[1] + productScopeFilePath]).catch({});
|
|
37
|
+
await execa('ssh', [...getSshArgs(server), "rm -fd " + remoteProductPath.split(":")[1] + productScopeFilePath]).catch({});
|
|
37
38
|
|
|
38
39
|
let localFileDir = localFile.substring(0, localFile.lastIndexOf("/"));
|
|
39
40
|
if (!fs.existsSync(localFileDir)) {
|
|
40
41
|
if (DEBUG) console.log(remoteFileDir + " needs to be removed");
|
|
41
|
-
await execa('ssh', [server, "rm -rf " + remoteFileDir]).catch({});
|
|
42
|
+
await execa('ssh', [...getSshArgs(server), "rm -rf " + remoteFileDir]).catch({});
|
|
42
43
|
}
|
|
43
44
|
count = RSYNC_RETRIES;
|
|
44
45
|
} else if ((count + 1)> RSYNC_RETRIES) {
|
|
@@ -9,6 +9,7 @@ const { checkConnectivity } = require("./common_helpers");
|
|
|
9
9
|
const { getCurrentBranch, getLastDeployedSha } = require("./common_releaseManager");
|
|
10
10
|
const { testEquality } = require("./common_syncFiles");
|
|
11
11
|
const { SERVER_IN_PROGRESS_TEST_FILE } = require("../task_lists/test_otherFilesContiousReload");
|
|
12
|
+
const { getSshArgs } = require("./common_helpers");
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
async function validateTestingConditions(cmdEnv, args) {
|
|
@@ -79,7 +80,7 @@ async function _handleTestEquality(ctx, changes, server) {
|
|
|
79
80
|
let offendingFiles = changes.map(f => f.substring(17)) //17 é a posição onde começa o nome dos ficheiros em cada linha
|
|
80
81
|
let problemFiles = [];
|
|
81
82
|
for(let changedFile of offendingFiles) {
|
|
82
|
-
await execa('ssh', [server, "grep -F " + changedFile + " " + SERVER_IN_PROGRESS_TEST_FILE ])
|
|
83
|
+
await execa('ssh', [...getSshArgs(server), "grep -F " + changedFile + " " + SERVER_IN_PROGRESS_TEST_FILE ])
|
|
83
84
|
.catch( () => {
|
|
84
85
|
try {
|
|
85
86
|
if (fs.lstatSync(changedFile.trim()).isFile()) {
|
|
@@ -94,7 +95,7 @@ async function _handleTestEquality(ctx, changes, server) {
|
|
|
94
95
|
if(problemFiles.length > 0) throw new Error("Aborted:".red + " server was changed since last deploy:\n " + problemFiles.join("\n ") + "\n" );
|
|
95
96
|
|
|
96
97
|
let inTest = "";
|
|
97
|
-
await execa('ssh', [server, "cat " + SERVER_IN_PROGRESS_TEST_FILE])
|
|
98
|
+
await execa('ssh', [...getSshArgs(server), "cat " + SERVER_IN_PROGRESS_TEST_FILE])
|
|
98
99
|
.then( value => inTest = value.stdout )
|
|
99
100
|
.catch( () => { } ) /* grep returns error if no match and execa throws an excepcions when return is error */
|
|
100
101
|
.finally( async () => {
|
package/package.json
CHANGED