deploy working

This commit is contained in:
Kasra Bigdeli
2019-01-06 12:27:09 -08:00
parent b85145b162
commit ea3305f72a
16 changed files with 349 additions and 257 deletions
+73 -69
View File
@@ -15,116 +15,120 @@ const ValidationsHandler_1 = require("../utils/ValidationsHandler");
const StorageHelper_1 = require("../utils/StorageHelper");
const CliHelper_1 = require("../utils/CliHelper");
const DeployHelper_1 = require("../utils/DeployHelper");
// async function deployAsStateless(host: string, appName: string, branch: string, pass: string) {
// const isStateless = host && appName && branch && pass;
// if (isStateless) {
// // login first
// StdOutUtil.printMessage(`Trying to login to ${host}\n`);
// const { name } = DeployApi.machineToDeploy;
// const response = await LoginApi.loginMachine(host, pass);
// const data = JSON.parse(response);
// const newToken = data.token;
// // Update the token to the machine that corresponds (if needed)
// MachineHelper.updateMachineAuthToken(name, newToken);
// if (data) {
// StdOutUtil.printMessage(`Starting stateless deploy to\n${host}\n${branch}\n${appName}`);
// deployFromGitProject();
// }
// } else {
// StdOutUtil.printError(
// 'You are missing parameters for deploying on stateless. <host> <password> <app name> <branch>'
// );
// }
// }
// async function deployFromTarFile(tarFile: string) {
// try {
// const isValidAuthentication = await validateAuthentication();
// if (isValidAuthentication) {
// // Send from tar file
// const filePath = tarFile;
// const gitHash = 'sendviatarfile';
// await uploadFile(filePath, gitHash);
// } else {
// StdOutUtil.printError('Incorrect login details', true);
// }
// } catch (e) {
// StdOutUtil.printError(e.message, true);
// }
// }
const CliApiManager_1 = require("../api/CliApiManager");
function deploy(options) {
return __awaiter(this, void 0, void 0, function* () {
const possibleApp = StorageHelper_1.default.get()
.getDeployedDirectories()
.find((dir) => dir.cwd === process.cwd());
if (!options.tarFile) {
StdOutUtil_1.default.printMessage('Preparing deployment to Captain...\n');
let deployParams = { deploySource: {} };
if (options.default) {
deployParams = {
captainMachine: possibleApp ? StorageHelper_1.default.get().findMachine(possibleApp.machineNameToDeploy) : undefined,
deploySource: possibleApp ? possibleApp.deploySource : {},
appName: possibleApp ? possibleApp.appName : undefined
};
}
if (options.appName) {
deployParams.appName = options.appName;
}
if (options.branch) {
deployParams.deploySource.branchToPush = options.branch;
}
if (options.tarFile) {
deployParams.deploySource.tarFilePath = options.tarFile;
}
if (!deployParams.deploySource.tarFilePath) {
if (!ValidationsHandler_1.validateIsGitRepository() || !ValidationsHandler_1.validateDefinitionFile()) {
return;
}
}
StdOutUtil_1.default.printMessage('Preparing deployment to Captain...\n');
let deployParams = possibleApp
? {
captainNameToDeploy: possibleApp.machineNameToDeploy,
branchToPush: possibleApp.branchToPush,
appName: possibleApp.appName
if (options.pass || options.host) {
if (options.pass && options.host) {
deployParams.captainMachine = {
authToken: '',
baseUrl: options.host,
name: ''
};
yield CliApiManager_1.default.get(deployParams.captainMachine).getAuthToken(options.pass);
}
else {
StdOutUtil_1.default.printError('host and pass should be either both defined or both undefined', true);
return;
}
: {};
if (options.default) {
//deployAsDefaultValues();
//}
// else if (options.stateless) {
// deployAsStateless(options.host, options.appName, options.branch, options.pass);
// }
// else if (options.tarFile) {
// deployFromTarFile(options.tarFile);
}
else {
// Show questions for what is being missing in deploy params
let allApps = undefined;
if (deployParams.captainMachine) {
allApps = yield ValidationsHandler_1.ensureAuthentication(deployParams.captainMachine);
}
{
const questions = [
{
type: 'list',
name: 'captainNameToDeploy',
default: possibleApp ? possibleApp.machineNameToDeploy : '',
message: 'Select the Captain Machine you want to deploy to:',
choices: CliHelper_1.default.get().getMachinesAsOptions()
choices: CliHelper_1.default.get().getMachinesAsOptions(),
when: () => !deployParams.captainMachine,
filter: (capName) => __awaiter(this, void 0, void 0, function* () {
deployParams.captainMachine = StorageHelper_1.default.get().findMachine(capName);
if (deployParams.captainMachine)
allApps = yield ValidationsHandler_1.ensureAuthentication(deployParams.captainMachine);
return capName;
})
},
{
type: 'input',
default: possibleApp ? possibleApp.branchToPush : 'master',
default: possibleApp && possibleApp.deploySource.branchToPush
? possibleApp.deploySource.branchToPush
: 'master',
name: 'branchToPush',
message: "Enter the 'git' branch you would like to deploy:",
when: (answers) => !!answers.captainNameToDeploy
filter: (branchToPushEntered) => __awaiter(this, void 0, void 0, function* () {
deployParams.deploySource.branchToPush = branchToPushEntered;
return branchToPushEntered;
}),
when: (answers) => !deployParams.deploySource.branchToPush &&
!deployParams.deploySource.tarFilePath &&
!!deployParams.captainMachine
},
{
type: 'input',
type: 'list',
default: possibleApp ? possibleApp.appName : '',
name: 'appName',
message: 'Enter the Captain app name this directory will be deployed to:',
when: (answers) => !!answers.branchToPush
choices: (answers) => {
return CliHelper_1.default.get().getAppsAsOptions(allApps);
},
filter: (appNameEntered) => __awaiter(this, void 0, void 0, function* () {
deployParams.appName = appNameEntered;
return appNameEntered;
}),
when: (answers) => (!!deployParams.deploySource.branchToPush || !!deployParams.deploySource.tarFilePath) &&
!deployParams.appName
},
{
type: 'confirm',
name: 'confirmedToDeploy',
message: 'Note that uncommitted files and files in gitignore (if any) will not be pushed to server. Please confirm so that deployment process can start.',
default: true,
when: (answers) => !!answers.appName
when: (answers) => !!deployParams.appName &&
!!deployParams.captainMachine &&
(!!deployParams.deploySource.branchToPush || !!deployParams.deploySource.tarFilePath)
}
];
const answers = (yield inquirer.prompt(questions));
if (!answers.confirmedToDeploy) {
const answersToIgnore = (yield inquirer.prompt(questions));
if (!answersToIgnore.confirmedToDeploy) {
StdOutUtil_1.default.printMessage('\nOperation cancelled by the user...\n');
process.exit(0);
return;
}
deployParams = answers;
}
const branchToPush = deployParams.branchToPush;
const appName = deployParams.appName;
const capMachine = StorageHelper_1.default.get()
.getMachines()
.find((machine) => machine.name === deployParams.captainNameToDeploy);
try {
yield new DeployHelper_1.default(capMachine, appName, branchToPush) //
.deployFromGitProject();
yield new DeployHelper_1.default(deployParams) //
.startDeploy();
}
catch (e) {
StdOutUtil_1.default.printError(e.message, true);
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,qCAAqC;AACrC,oDAA6C;AAC7C,oEAAoH;AA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AY,CAAC,wCAAwC,CAAC,CAAC;gBAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBAChB,OAAO;aACP;SACD;QAED,IAAI;YACH,MAAM,IAAI,sBAAY,CAAC,YAAY,CAAC,CAAC,EAAE;iBACrC,WAAW,EAAE,CAAC;SAChB;QAAC,OAAO,CAAC,EAAE;YACX,oBAAU,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;SACvC;IACF,CAAC;CAAA;AAED,kBAAe,MAAM,CAAC"}
+17
View File
@@ -8,6 +8,23 @@ class CliHelper {
CliHelper.instance = new CliHelper();
return CliHelper.instance;
}
getAppsAsOptions(apps) {
const firstItemInOption = [
{
name: '-- CANCEL --',
value: '',
short: ''
}
];
const listOfApps = apps.map((app) => {
return {
name: `${app.appName}`,
value: `${app.appName}`,
short: `${app.appName}`
};
});
return [...firstItemInOption, ...listOfApps];
}
getMachinesAsOptions() {
const machines = StorageHelper_1.default.get().getMachines();
const firstItemInOption = [
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"CliHelper.js","sourceRoot":"","sources":["../../src/utils/CliHelper.ts"],"names":[],"mappings":";;AAAA,mDAA4C;AAE5C,6CAAsC;AAEtC,MAAqB,SAAS;IAG7B,MAAM,CAAC,GAAG;QACT,IAAI,CAAC,SAAS,CAAC,QAAQ;YAAE,SAAS,CAAC,QAAQ,GAAG,IAAI,SAAS,EAAE,CAAC;QAC9D,OAAO,SAAS,CAAC,QAAQ,CAAC;IAC3B,CAAC;IAED,oBAAoB;QACnB,MAAM,QAAQ,GAAG,uBAAa,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAA;QAClD,MAAM,iBAAiB,GAAG;YACzB;gBACC,IAAI,EAAE,cAAc;gBACpB,KAAK,EAAE,EAAE;gBACT,KAAK,EAAE,EAAE;aACT;SACD,CAAC;QACF,MAAM,cAAc,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAA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,EAAE;YAC3D,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE;gBAC3D,KAAK,GAAG,KAAK,CAAC;aACd;QACF,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AAhFD,4BAgFC"}
+47 -34
View File
@@ -15,36 +15,41 @@ const child_process_1 = require("child_process");
const StdOutUtil_1 = require("../utils/StdOutUtil");
const ProgressBar = require('progress');
const commandExistsSync = require('command-exists').sync;
const ValidationsHandler_1 = require("../utils/ValidationsHandler");
const CliApiManager_1 = require("../api/CliApiManager");
const SpinnerHelper_1 = require("../utils/SpinnerHelper");
class DeployHelper {
constructor(machineToDeploy, appName, branchToPush) {
this.machineToDeploy = machineToDeploy;
this.appName = appName;
this.branchToPush = branchToPush;
constructor(deployParams) {
this.deployParams = deployParams;
this.lastLineNumberPrinted = -10000; // we want to show all lines to begin with!
//
}
gitArchiveFile(zipFileFullPath) {
gitArchiveFile(zipFileFullPath, branchToPush) {
const self = this;
return new Promise(function (resolve, reject) {
child_process_1.exec(`git archive --format tar --output "${zipFileFullPath}" ${self.branchToPush}`, (err, stdout, stderr) => {
// Removes the temporary file created
if (fs.pathExistsSync(zipFileFullPath))
fs.removeSync(zipFileFullPath);
if (!commandExistsSync('git')) {
StdOutUtil_1.default.printError("'git' command not found...\nCaptain needs 'git' to create tar file of your source files...", true);
reject("Captain needs 'git' to create tar file of your source files...");
return;
}
child_process_1.exec(`git archive --format tar --output "${zipFileFullPath}" ${branchToPush}`, (err, stdout, stderr) => {
if (err) {
StdOutUtil_1.default.printError(`TAR file failed\n${err}\n`);
fs.removeSync(zipFileFullPath);
reject(new Error('TAR file failed'));
return;
}
child_process_1.exec(`git rev-parse ${self.branchToPush}`, (err, stdout, stderr) => {
child_process_1.exec(`git rev-parse ${branchToPush}`, (err, stdout, stderr) => {
const gitHash = (stdout || '').trim();
if (err || !/^[a-f0-9]{40}$/.test(gitHash)) {
StdOutUtil_1.default.printError(`Cannot find hash of last commit on this branch: ${self.branchToPush}\n${gitHash}\n${err}\n`);
StdOutUtil_1.default.printError(`Cannot find hash of last commit on this branch: ${branchToPush}\n${gitHash}\n${err}\n`);
reject(new Error('rev-parse failed'));
return;
}
StdOutUtil_1.default.printMessage(`Pushing last commit on ${self.branchToPush}: ${gitHash}`);
resolve();
StdOutUtil_1.default.printMessage(`Pushing last commit on ${branchToPush}: ${gitHash}`);
resolve(gitHash);
});
});
});
@@ -63,50 +68,55 @@ class DeployHelper {
});
fileStream.on('end', () => {
StdOutUtil_1.default.printMessage('This might take several minutes. PLEASE BE PATIENT...');
SpinnerHelper_1.default.start('Building your source code...');
SpinnerHelper_1.default.start('Building your source code...\n');
SpinnerHelper_1.default.setColor('yellow');
});
return fileStream;
}
deployFromGitProject() {
startDeploy() {
return __awaiter(this, void 0, void 0, function* () {
const appName = this.appName;
const branchToPush = this.branchToPush;
const machineToDeploy = this.machineToDeploy;
if (!appName || !branchToPush || !machineToDeploy) {
StdOutUtil_1.default.printError('Default deploy failed. Missing appName or branchToPush or machineToDeploy.', true);
const appName = this.deployParams.appName;
const branchToPush = this.deployParams.deploySource.branchToPush;
const tarFilePath = this.deployParams.deploySource.tarFilePath;
const machineToDeploy = this.deployParams.captainMachine;
if (!appName || (!branchToPush && !tarFilePath) || !machineToDeploy) {
StdOutUtil_1.default.printError('Default deploy failed. Missing appName or branchToPush/tarFilePath or machineToDeploy.', true);
return;
}
if (!commandExistsSync('git')) {
StdOutUtil_1.default.printError("'git' command not found...");
StdOutUtil_1.default.printError("Captain needs 'git' to create tar file of your source files...", true);
if (branchToPush && tarFilePath) {
StdOutUtil_1.default.printError('Default deploy failed. branchToPush/tarFilePath cannot both be present.', true);
return;
}
let tarFileCreatedByCli = false;
const tarFileNameToDeploy = tarFilePath ? tarFilePath : 'temporary-captain-to-deploy.tar';
const tarFileFullPath = tarFileNameToDeploy.startsWith('/')
? tarFileNameToDeploy // absolute path
: path.join(process.cwd(), tarFileNameToDeploy); // relative path
let gitHash = '';
if (branchToPush) {
tarFileCreatedByCli = true;
StdOutUtil_1.default.printMessage(`Saving tar file to:\n${tarFileFullPath}\n`);
gitHash = yield this.gitArchiveFile(tarFileFullPath, branchToPush);
}
StdOutUtil_1.default.printMessage(`Deploying ${appName} to ${machineToDeploy.name}`);
yield ValidationsHandler_1.ensureAuthentication(machineToDeploy);
const zipFileNameToDeploy = 'temporary-captain-to-deploy.tar';
const zipFileFullPath = path.join(process.cwd(), zipFileNameToDeploy);
StdOutUtil_1.default.printMessage(`Saving tar file to:\n${zipFileFullPath}\n`);
// Removes the temporary file created
if (fs.pathExistsSync(zipFileFullPath))
fs.removeSync(zipFileFullPath);
yield this.gitArchiveFile(zipFileFullPath);
try {
StdOutUtil_1.default.printMessage(`Uploading the file to ${machineToDeploy.baseUrl}`);
yield CliApiManager_1.default.get(machineToDeploy).uploadAppData(appName, this.getFileStream(zipFileFullPath));
yield CliApiManager_1.default.get(machineToDeploy).uploadAppData(appName, this.getFileStream(tarFileFullPath));
StdOutUtil_1.default.printMessage(`Upload done.`);
fs.removeSync(zipFileFullPath);
if (tarFileCreatedByCli && fs.pathExistsSync(tarFileFullPath))
fs.removeSync(tarFileFullPath);
this.startFetchingBuildLogs(machineToDeploy, appName);
}
catch (e) {
if (fs.pathExistsSync(zipFileFullPath))
fs.removeSync(zipFileFullPath);
if (tarFileCreatedByCli && fs.pathExistsSync(tarFileFullPath))
fs.removeSync(tarFileFullPath);
throw e;
}
});
}
onLogRetrieved(data, machineToDeploy, appName) {
return __awaiter(this, void 0, void 0, function* () {
const self = this;
if (data) {
const lines = data.logs.lines;
const firstLineNumberOfLogs = data.logs.firstLineNumber;
@@ -130,8 +140,11 @@ class DeployHelper {
}
if (data && !data.isAppBuilding) {
if (!data.isBuildFailed) {
const appUrl = self.deployParams.captainMachine.baseUrl
.replace('https://', 'http://')
.replace('//captain.', '//' + appName + '.');
StdOutUtil_1.default.printGreenMessage(`Deployed successfully: ${appName}`);
StdOutUtil_1.default.printMagentaMessage(`App is available`, true); // TODO add url
StdOutUtil_1.default.printMagentaMessage(`App is available at ${appUrl}`, true);
}
else {
StdOutUtil_1.default.printError(`\nSomething bad happened. Cannot deploy "${appName}"\n`, true);
File diff suppressed because one or more lines are too long
+3
View File
@@ -17,6 +17,9 @@ class StorageHelper {
getMachines() {
return Utils_1.default.copyObject(this.data.get(CAP_MACHINES) || []);
}
findMachine(machineName) {
return this.getMachines().find((m) => m.name === machineName);
}
removeMachine(machineName) {
const machines = this.getMachines();
const removedMachine = machines.filter((machine) => machine.name === machineName)[0];
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"StorageHelper.js","sourceRoot":"","sources":["../../src/utils/StorageHelper.ts"],"names":[],"mappings":";;AACA,2CAA2C;AAC3C,mCAA4B;AAE5B,MAAM,YAAY,GAAG,aAAa,CAAC;AACnC,MAAM,aAAa,GAAG,cAAc,CAAC;AAErC,MAAqB,aAAa;IAGjC,MAAM,CAAC,GAAG;QACT,IAAI,CAAC,aAAa,CAAC,QAAQ;YAAE,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QAC1E,OAAO,aAAa,CAAC,QAAQ,CAAC;IAC/B,CAAC;IAID;QACC,IAAI,CAAC,IAAI,GAAG,IAAI,WAAW,CAAC,qBAAqB,CAAC,CAAC;QACnD,qBAAqB;IACtB,CAAC;IAED,WAAW;QACV,OAAO,eAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,aAAa,CAAC,WAAmB;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACpC,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QACrF,MAAM,WAAW,GAA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CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YACrD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;YAChC,IAAI,OAAO,CAAC,GAAG,KAAK,uBAAuB,CAAC,GAAG,EAAE;gBAChD,UAAU,GAAG,IAAI,CAAC;gBAClB,QAAQ,CAAC,KAAK,CAAC,GAAG,uBAAuB,CAAC;gBAC1C,MAAM;aACN;SACD;QAED,IAAI,CAAC,UAAU,EAAE;YAChB,QAAQ,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;SACvC;QAED,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC;CACD;AAzED,gCAyEC"}
+5 -3
View File
@@ -62,16 +62,18 @@ exports.isIpAddress = isIpAddress;
function ensureAuthentication(machine) {
return __awaiter(this, void 0, void 0, function* () {
let isAuthenticated = false;
let allApps = undefined;
try {
let ignoreVal = yield CliApiManager_1.default.get(machine).getAllApps();
isAuthenticated = true;
allApps = yield CliApiManager_1.default.get(machine).getAllApps();
}
catch (e) {
// ignore
}
if (!isAuthenticated) {
if (!allApps) {
const loggedInStatus = yield requestLogin_1.default(machine);
allApps = yield CliApiManager_1.default.get(machine).getAllApps();
}
return allApps;
});
}
exports.ensureAuthentication = ensureAuthentication;
@@ -1 +1 @@
{"version":3,"file":"ValidationsHandler.js","sourceRoot":"","sources":["../../src/utils/ValidationsHandler.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,6CAAsC;AAEtC,wDAAiD;AACjD,2DAAoD;AAEpD,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAE/B,SAAgB,uBAAuB;IACtC,MAAM,eAAe,GAAG,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAEpD,IAAI,CAAC,eAAe,EAAE;QACrB,oBAAU,CAAC,UAAU,CACpB,gHAAgH,EAChH,IAAI,CACJ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;IACf,CAAC;CAAA;AAfD,oDAeC"}
+84 -81
View File
@@ -3,108 +3,115 @@
import * as inquirer from 'inquirer';
import StdOutUtil from '../utils/StdOutUtil';
import { validateIsGitRepository, validateDefinitionFile, ensureAuthentication } from '../utils/ValidationsHandler';
import { IMachine, IDeployedDirectory } from '../models/storage/StoredObjects';
import { IMachine, IDeployedDirectory, IDeploySource, IDeployParams } from '../models/storage/StoredObjects';
import StorageHelper from '../utils/StorageHelper';
import CliHelper from '../utils/CliHelper';
import { IHashMapGeneric } from '../models/IHashMapGeneric';
import DeployHelper from '../utils/DeployHelper';
// async function deployAsStateless(host: string, appName: string, branch: string, pass: string) {
// const isStateless = host && appName && branch && pass;
// if (isStateless) {
// // login first
// StdOutUtil.printMessage(`Trying to login to ${host}\n`);
// const { name } = DeployApi.machineToDeploy;
// const response = await LoginApi.loginMachine(host, pass);
// const data = JSON.parse(response);
// const newToken = data.token;
// // Update the token to the machine that corresponds (if needed)
// MachineHelper.updateMachineAuthToken(name, newToken);
// if (data) {
// StdOutUtil.printMessage(`Starting stateless deploy to\n${host}\n${branch}\n${appName}`);
// deployFromGitProject();
// }
// } else {
// StdOutUtil.printError(
// 'You are missing parameters for deploying on stateless. <host> <password> <app name> <branch>'
// );
// }
// }
// async function deployFromTarFile(tarFile: string) {
// try {
// const isValidAuthentication = await validateAuthentication();
// if (isValidAuthentication) {
// // Send from tar file
// const filePath = tarFile;
// const gitHash = 'sendviatarfile';
// await uploadFile(filePath, gitHash);
// } else {
// StdOutUtil.printError('Incorrect login details', true);
// }
// } catch (e) {
// StdOutUtil.printError(e.message, true);
// }
// }
import CliApiManager from '../api/CliApiManager';
async function deploy(options: any) {
const possibleApp = StorageHelper.get()
.getDeployedDirectories()
.find((dir: IDeployedDirectory) => dir.cwd === process.cwd());
if (!options.tarFile) {
StdOutUtil.printMessage('Preparing deployment to Captain...\n');
let deployParams: IDeployParams = { deploySource: {} };
if (options.default) {
deployParams = {
captainMachine: possibleApp ? StorageHelper.get().findMachine(possibleApp.machineNameToDeploy) : undefined,
deploySource: possibleApp ? possibleApp.deploySource : {},
appName: possibleApp ? possibleApp.appName : undefined
};
}
if (options.appName) {
deployParams.appName = options.appName;
}
if (options.branch) {
deployParams.deploySource.branchToPush = options.branch;
}
if (options.tarFile) {
deployParams.deploySource.tarFilePath = options.tarFile;
}
if (!deployParams.deploySource.tarFilePath) {
if (!validateIsGitRepository() || !validateDefinitionFile()) {
return;
}
}
StdOutUtil.printMessage('Preparing deployment to Captain...\n');
if (options.pass || options.host) {
if (options.pass && options.host) {
deployParams.captainMachine = {
authToken: '',
baseUrl: options.host,
name: ''
};
await CliApiManager.get(deployParams.captainMachine).getAuthToken(options.pass);
} else {
StdOutUtil.printError('host and pass should be either both defined or both undefined', true);
return;
}
}
let deployParams: IHashMapGeneric<string> = possibleApp
? {
captainNameToDeploy: possibleApp.machineNameToDeploy,
branchToPush: possibleApp.branchToPush,
appName: possibleApp.appName
}
: {};
// Show questions for what is being missing in deploy params
let allApps: any = undefined;
if (deployParams.captainMachine) {
allApps = await ensureAuthentication(deployParams.captainMachine);
}
if (options.default) { // TODO
//deployAsDefaultValues();
//}
// else if (options.stateless) {
// deployAsStateless(options.host, options.appName, options.branch, options.pass);
// }
// else if (options.tarFile) {
// deployFromTarFile(options.tarFile);
} else {
{
const questions = [
{
type: 'list',
name: 'captainNameToDeploy',
default: possibleApp ? possibleApp.machineNameToDeploy : '',
message: 'Select the Captain Machine you want to deploy to:',
choices: CliHelper.get().getMachinesAsOptions()
choices: CliHelper.get().getMachinesAsOptions(),
when: () => !deployParams.captainMachine,
filter: async (capName: string) => {
deployParams.captainMachine = StorageHelper.get().findMachine(capName);
if (deployParams.captainMachine) allApps = await ensureAuthentication(deployParams.captainMachine);
return capName;
}
},
{
type: 'input',
default: possibleApp ? possibleApp.branchToPush : 'master',
default:
possibleApp && possibleApp.deploySource.branchToPush
? possibleApp.deploySource.branchToPush
: 'master',
name: 'branchToPush',
message: "Enter the 'git' branch you would like to deploy:",
when: (answers: IHashMapGeneric<string>) => !!answers.captainNameToDeploy
filter: async (branchToPushEntered: string) => {
deployParams.deploySource.branchToPush = branchToPushEntered;
return branchToPushEntered;
},
when: (answers: IHashMapGeneric<string>) =>
!deployParams.deploySource.branchToPush &&
!deployParams.deploySource.tarFilePath &&
!!deployParams.captainMachine
},
{
type: 'input',
type: 'list',
default: possibleApp ? possibleApp.appName : '',
name: 'appName',
message: 'Enter the Captain app name this directory will be deployed to:',
when: (answers: IHashMapGeneric<string>) => !!answers.branchToPush
choices: (answers: IHashMapGeneric<string>) => {
return CliHelper.get().getAppsAsOptions(allApps);
},
filter: async (appNameEntered: string) => {
deployParams.appName = appNameEntered;
return appNameEntered;
},
when: (answers: IHashMapGeneric<string>) =>
(!!deployParams.deploySource.branchToPush || !!deployParams.deploySource.tarFilePath) &&
!deployParams.appName
},
{
type: 'confirm',
@@ -112,28 +119,24 @@ async function deploy(options: any) {
message:
'Note that uncommitted files and files in gitignore (if any) will not be pushed to server. Please confirm so that deployment process can start.',
default: true,
when: (answers: IHashMapGeneric<string>) => !!answers.appName
when: (answers: IHashMapGeneric<string>) =>
!!deployParams.appName &&
!!deployParams.captainMachine &&
(!!deployParams.deploySource.branchToPush || !!deployParams.deploySource.tarFilePath)
}
];
const answers = (await inquirer.prompt(questions)) as IHashMapGeneric<string>;
const answersToIgnore = (await inquirer.prompt(questions)) as IHashMapGeneric<string>;
if (!answers.confirmedToDeploy) {
if (!answersToIgnore.confirmedToDeploy) {
StdOutUtil.printMessage('\nOperation cancelled by the user...\n');
process.exit(0);
return;
}
deployParams = answers;
}
const branchToPush = deployParams.branchToPush;
const appName = deployParams.appName;
const capMachine = StorageHelper.get()
.getMachines()
.find((machine) => machine.name === deployParams.captainNameToDeploy)!;
try {
await new DeployHelper(capMachine, appName, branchToPush) //
.deployFromGitProject();
await new DeployHelper(deployParams) //
.startDeploy();
} catch (e) {
StdOutUtil.printError(e.message, true);
}
+12 -1
View File
@@ -11,9 +11,20 @@ export interface IOldSavedApp {
machineToDeploy: IMachine;
}
export interface IDeploySource {
branchToPush?: string;
tarFilePath?: string;
}
export interface IDeployedDirectory {
cwd: string;
appName: string;
branchToPush: string;
deploySource: IDeploySource;
machineNameToDeploy: string;
}
export interface IDeployParams {
deploySource: IDeploySource;
captainMachine?: IMachine;
appName?: string;
}
+22 -4
View File
@@ -10,8 +10,27 @@ export default class CliHelper {
return CliHelper.instance;
}
getAppsAsOptions(apps: any[]) {
const firstItemInOption = [
{
name: '-- CANCEL --',
value: '',
short: ''
}
];
const listOfApps = apps.map((app) => {
return {
name: `${app.appName}`,
value: `${app.appName}`,
short: `${app.appName}`
};
});
return [ ...firstItemInOption, ...listOfApps ];
}
getMachinesAsOptions() {
const machines = StorageHelper.get().getMachines()
const machines = StorageHelper.get().getMachines();
const firstItemInOption = [
{
name: '-- CANCEL --',
@@ -31,11 +50,10 @@ export default class CliHelper {
}
logoutMachine(machineName: string) {
const removedMachine = StorageHelper.get().removeMachine(machineName);
StdOutUtil. printMessage(`You are now logged out from ${removedMachine.name} at ${removedMachine.baseUrl}...\n`);
const removedMachine = StorageHelper.get().removeMachine(machineName);
StdOutUtil.printMessage(`You are now logged out from ${removedMachine.name} at ${removedMachine.baseUrl}...\n`);
}
findDefaultCaptainName() {
let currentSuffix = StorageHelper.get().getMachines().length + 1;
const self = this;
+71 -57
View File
@@ -1,14 +1,12 @@
#!/usr/bin/env node
import * as inquirer from 'inquirer';
import * as fs from 'fs-extra';
import * as path from 'path';
import { exec } from 'child_process';
import StdOutUtil from '../utils/StdOutUtil';
const ProgressBar = require('progress');
const commandExistsSync = require('command-exists').sync;
import { validateIsGitRepository, validateDefinitionFile, ensureAuthentication } from '../utils/ValidationsHandler';
import { IMachine, IDeployedDirectory } from '../models/storage/StoredObjects';
import { IMachine, IDeployParams } from '../models/storage/StoredObjects';
import CliApiManager from '../api/CliApiManager';
import SpinnerHelper from '../utils/SpinnerHelper';
import IBuildLogs from '../models/IBuildLogs';
@@ -16,42 +14,51 @@ import IBuildLogs from '../models/IBuildLogs';
export default class DeployHelper {
private lastLineNumberPrinted = -10000; // we want to show all lines to begin with!
constructor(private machineToDeploy: IMachine, private appName: string, private branchToPush: string) {
constructor(private deployParams: IDeployParams) {
//
}
private gitArchiveFile(zipFileFullPath: string) {
private gitArchiveFile(zipFileFullPath: string, branchToPush: string) {
const self = this;
return new Promise(function(resolve, reject) {
exec(
`git archive --format tar --output "${zipFileFullPath}" ${self.branchToPush}`,
(err, stdout, stderr) => {
if (err) {
StdOutUtil.printError(`TAR file failed\n${err}\n`);
return new Promise<string>(function(resolve, reject) {
// Removes the temporary file created
if (fs.pathExistsSync(zipFileFullPath)) fs.removeSync(zipFileFullPath);
fs.removeSync(zipFileFullPath);
if (!commandExistsSync('git')) {
StdOutUtil.printError(
"'git' command not found...\nCaptain needs 'git' to create tar file of your source files...",
true
);
reject("Captain needs 'git' to create tar file of your source files...");
return;
}
exec(`git archive --format tar --output "${zipFileFullPath}" ${branchToPush}`, (err, stdout, stderr) => {
if (err) {
StdOutUtil.printError(`TAR file failed\n${err}\n`);
fs.removeSync(zipFileFullPath);
reject(new Error('TAR file failed'));
return;
}
exec(`git rev-parse ${branchToPush}`, (err, stdout, stderr) => {
const gitHash = (stdout || '').trim();
if (err || !/^[a-f0-9]{40}$/.test(gitHash)) {
StdOutUtil.printError(
`Cannot find hash of last commit on this branch: ${branchToPush}\n${gitHash}\n${err}\n`
);
reject(new Error('rev-parse failed'));
reject(new Error('TAR file failed'));
return;
}
exec(`git rev-parse ${self.branchToPush}`, (err, stdout, stderr) => {
const gitHash = (stdout || '').trim();
if (err || !/^[a-f0-9]{40}$/.test(gitHash)) {
StdOutUtil.printError(
`Cannot find hash of last commit on this branch: ${self.branchToPush}\n${gitHash}\n${err}\n`
);
reject(new Error('rev-parse failed'));
return;
}
StdOutUtil.printMessage(`Pushing last commit on ${self.branchToPush}: ${gitHash}`);
resolve();
});
}
);
StdOutUtil.printMessage(`Pushing last commit on ${branchToPush}: ${gitHash}`);
resolve(gitHash);
});
});
});
}
@@ -72,7 +79,7 @@ export default class DeployHelper {
fileStream.on('end', () => {
StdOutUtil.printMessage('This might take several minutes. PLEASE BE PATIENT...');
SpinnerHelper.start('Building your source code...');
SpinnerHelper.start('Building your source code...\n');
SpinnerHelper.setColor('yellow');
});
@@ -80,49 +87,56 @@ export default class DeployHelper {
return fileStream;
}
async deployFromGitProject() {
const appName = this.appName;
const branchToPush = this.branchToPush;
const machineToDeploy = this.machineToDeploy;
async startDeploy() {
const appName = this.deployParams.appName;
const branchToPush = this.deployParams.deploySource.branchToPush;
const tarFilePath = this.deployParams.deploySource.tarFilePath;
const machineToDeploy = this.deployParams.captainMachine;
if (!appName || !branchToPush || !machineToDeploy) {
StdOutUtil.printError('Default deploy failed. Missing appName or branchToPush or machineToDeploy.', true);
if (!appName || (!branchToPush && !tarFilePath) || !machineToDeploy) {
StdOutUtil.printError(
'Default deploy failed. Missing appName or branchToPush/tarFilePath or machineToDeploy.',
true
);
return;
}
if (!commandExistsSync('git')) {
StdOutUtil.printError("'git' command not found...");
StdOutUtil.printError("Captain needs 'git' to create tar file of your source files...", true);
if (branchToPush && tarFilePath) {
StdOutUtil.printError('Default deploy failed. branchToPush/tarFilePath cannot both be present.', true);
return;
}
let tarFileCreatedByCli = false;
const tarFileNameToDeploy = tarFilePath ? tarFilePath : 'temporary-captain-to-deploy.tar';
const tarFileFullPath = tarFileNameToDeploy.startsWith('/')
? tarFileNameToDeploy // absolute path
: path.join(process.cwd(), tarFileNameToDeploy); // relative path
let gitHash = '';
if (branchToPush) {
tarFileCreatedByCli = true;
StdOutUtil.printMessage(`Saving tar file to:\n${tarFileFullPath}\n`);
gitHash = await this.gitArchiveFile(tarFileFullPath, branchToPush);
}
StdOutUtil.printMessage(`Deploying ${appName} to ${machineToDeploy.name}`);
await ensureAuthentication(machineToDeploy);
const zipFileNameToDeploy = 'temporary-captain-to-deploy.tar';
const zipFileFullPath = path.join(process.cwd(), zipFileNameToDeploy);
StdOutUtil.printMessage(`Saving tar file to:\n${zipFileFullPath}\n`);
// Removes the temporary file created
if (fs.pathExistsSync(zipFileFullPath)) fs.removeSync(zipFileFullPath);
await this.gitArchiveFile(zipFileFullPath);
try {
StdOutUtil.printMessage(`Uploading the file to ${machineToDeploy.baseUrl}`);
await CliApiManager.get(machineToDeploy).uploadAppData(appName, this.getFileStream(zipFileFullPath));
await CliApiManager.get(machineToDeploy).uploadAppData(appName, this.getFileStream(tarFileFullPath));
StdOutUtil.printMessage(`Upload done.`);
fs.removeSync(zipFileFullPath);
if (tarFileCreatedByCli && fs.pathExistsSync(tarFileFullPath)) fs.removeSync(tarFileFullPath);
this.startFetchingBuildLogs(machineToDeploy, appName);
} catch (e) {
if (fs.pathExistsSync(zipFileFullPath)) fs.removeSync(zipFileFullPath);
if (tarFileCreatedByCli && fs.pathExistsSync(tarFileFullPath)) fs.removeSync(tarFileFullPath);
throw e;
}
@@ -155,7 +169,7 @@ export default class DeployHelper {
if (data && !data.isAppBuilding) {
if (!data.isBuildFailed) {
const appUrl = self.machineToDeploy.baseUrl
const appUrl = self.deployParams.captainMachine!.baseUrl
.replace('https://', 'http://')
.replace('//captain.', '//' + appName + '.');
StdOutUtil.printGreenMessage(`Deployed successfully: ${appName}`);
+4
View File
@@ -24,6 +24,10 @@ export default class StorageHelper {
return Utils.copyObject(this.data.get(CAP_MACHINES) || []);
}
findMachine(machineName: string) {
return this.getMachines().find((m) => m.name === machineName);
}
removeMachine(machineName: string) {
const machines = this.getMachines();
const removedMachine = machines.filter((machine) => machine.name === machineName)[0];
+6 -3
View File
@@ -71,14 +71,17 @@ export function isIpAddress(ipaddress: string) {
}
export async function ensureAuthentication(machine: IMachine) {
let isAuthenticated = false;
let allApps = undefined;
try {
let ignoreVal = await CliApiManager.get(machine).getAllApps();
isAuthenticated = true;
allApps = await CliApiManager.get(machine).getAllApps();
} catch (e) {
// ignore
}
if (!isAuthenticated) {
if (!allApps) {
const loggedInStatus = await requestLogin(machine);
allApps = await CliApiManager.get(machine).getAllApps();
}
return allApps
}