@eliware/vyops 1.0.11 → 1.0.12
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/package.json +2 -2
- package/src/deploy.mjs +10 -7
package/package.json
CHANGED
package/src/deploy.mjs
CHANGED
|
@@ -67,19 +67,19 @@ async function installScripts(client, config, log, runId) {
|
|
|
67
67
|
await exec(client, `sudo rm -f -- ${names.map(name => JSON.stringify(`${installDir}/${name}`)).join(' ')}; sudo cp -a ${JSON.stringify(`${backupDir}/.`)} ${JSON.stringify(`${installDir}/`)} 2>/dev/null || true; rm -rf -- ${JSON.stringify(remoteDir)} ${JSON.stringify(backupDir)}`).catch(cleanupError => log(`script rollback failed: ${cleanupError.message}`));
|
|
68
68
|
throw error;
|
|
69
69
|
}
|
|
70
|
-
return async committed => {
|
|
70
|
+
return async (committed, activeClient) => {
|
|
71
71
|
if (committed) {
|
|
72
|
-
await exec(
|
|
72
|
+
await exec(activeClient, `sudo rm -rf -- ${JSON.stringify(backupDir)}; rm -rf -- ${JSON.stringify(remoteDir)}`).catch(error => log(`hook cleanup failed: ${error.message}`));
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
|
-
await exec(
|
|
75
|
+
await exec(activeClient, `sudo rm -f -- ${names.map(name => JSON.stringify(`${installDir}/${name}`)).join(' ')}; sudo cp -a ${JSON.stringify(`${backupDir}/.`)} ${JSON.stringify(`${installDir}/`)} 2>/dev/null || true; rm -rf -- ${JSON.stringify(remoteDir)} ${JSON.stringify(backupDir)}`).catch(error => log(`script rollback failed: ${error.message}`));
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
export async function deploy({ target, config, password }) {
|
|
80
80
|
const debugLog = message => log.debug(`[vyops] ${message}`);
|
|
81
81
|
debugLog(`connecting: ${target}`);
|
|
82
|
-
|
|
82
|
+
let client = password === undefined ? await connect(target) : await connect(target, { password });
|
|
83
83
|
debugLog('SSH connected');
|
|
84
84
|
let finalizeHooks;
|
|
85
85
|
let hooksFinalized = false;
|
|
@@ -91,6 +91,9 @@ export async function deploy({ target, config, password }) {
|
|
|
91
91
|
await upload(client, config, remote);
|
|
92
92
|
debugLog(`upload complete: ${remote}`);
|
|
93
93
|
finalizeHooks = await installScripts(client, config, debugLog, runId);
|
|
94
|
+
debugLog('reconnecting before interactive deployment sequence');
|
|
95
|
+
await close(client);
|
|
96
|
+
client = password === undefined ? await connect(target) : await connect(target, { password });
|
|
94
97
|
debugLog('starting interactive deployment sequence');
|
|
95
98
|
const output = await interactive(client, [
|
|
96
99
|
'configure',
|
|
@@ -99,7 +102,7 @@ export async function deploy({ target, config, password }) {
|
|
|
99
102
|
"printf '%s\\n' '--- compare ---'",
|
|
100
103
|
'compare',
|
|
101
104
|
"printf '%s\\n' '--- end compare ---'",
|
|
102
|
-
{ command: 'commit-confirm 5', reject: /(?:commit failed|commit aborted|cannot commit|configuration (?:commit )?failed|invalid configuration
|
|
105
|
+
{ command: 'commit-confirm 5', reject: /(?:commit failed|commit aborted|cannot commit|configuration (?:commit )?failed|invalid configuration)/i },
|
|
103
106
|
{ command: 'confirm', reject: /(?:confirm failed|error|invalid)/i },
|
|
104
107
|
{ command: 'save', reject: /(?:save failed|error|invalid)/i },
|
|
105
108
|
'exit',
|
|
@@ -113,11 +116,11 @@ export async function deploy({ target, config, password }) {
|
|
|
113
116
|
await download(client, '/config/config.boot', config);
|
|
114
117
|
if (finalizeHooks) {
|
|
115
118
|
hooksFinalized = true;
|
|
116
|
-
await finalizeHooks(true);
|
|
119
|
+
await finalizeHooks(true, client);
|
|
117
120
|
}
|
|
118
121
|
return 0;
|
|
119
122
|
} catch (error) {
|
|
120
|
-
if (finalizeHooks && !hooksFinalized && !deploymentCommitted) await finalizeHooks(false);
|
|
123
|
+
if (finalizeHooks && !hooksFinalized && !deploymentCommitted) await finalizeHooks(false, client);
|
|
121
124
|
throw error;
|
|
122
125
|
} finally {
|
|
123
126
|
debugLog('cleaning up remote file');
|