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