diff --git a/app-cli/built/commands/deploy.js b/app-cli/built/commands/deploy.js index 255f596..e364537 100755 --- a/app-cli/built/commands/deploy.js +++ b/app-cli/built/commands/deploy.js @@ -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. ' -// ); -// } -// } -// 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); diff --git a/app-cli/built/commands/deploy.js.map b/app-cli/built/commands/deploy.js.map index 868a463..653f173 100755 --- a/app-cli/built/commands/deploy.js.map +++ b/app-cli/built/commands/deploy.js.map @@ -1 +1 @@ -{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names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AA4B,CAAC;YAEtF,IAAI,CAAC,eAAe,CAAC,iBAAiB,EAAE;gBACvC,oBAAU,CAAC,YAAY,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"} \ No newline at end of file diff --git a/app-cli/built/utils/CliHelper.js b/app-cli/built/utils/CliHelper.js index 0ba307a..f31c5a8 100755 --- a/app-cli/built/utils/CliHelper.js +++ b/app-cli/built/utils/CliHelper.js @@ -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 = [ diff --git a/app-cli/built/utils/CliHelper.js.map b/app-cli/built/utils/CliHelper.js.map index ed55c3d..b968ed8 100755 --- a/app-cli/built/utils/CliHelper.js.map +++ b/app-cli/built/utils/CliHelper.js.map @@ -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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Ac;QAChC,MAAM,YAAY,GAAG,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;QAEzD,OAAO,WAAW,YAAY,EAAE,CAAC;IAClC,CAAC;IAED,aAAa,CAAC,YAAoB;QACjC,MAAM,IAAI,GAAG,IAAI,CAAC;QAClB,IAAI,KAAK,GAAG,IAAI,CAAC;QACjB,uBAAa,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC,OAAiB,EAAE,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"} \ No newline at end of file diff --git a/app-cli/built/utils/DeployHelper.js b/app-cli/built/utils/DeployHelper.js index 610858e..280bb9d 100755 --- a/app-cli/built/utils/DeployHelper.js +++ b/app-cli/built/utils/DeployHelper.js @@ -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); diff --git a/app-cli/built/utils/DeployHelper.js.map b/app-cli/built/utils/DeployHelper.js.map index 233f620..c368780 100755 --- a/app-cli/built/utils/DeployHelper.js.map +++ b/app-cli/built/utils/DeployHelper.js.map @@ -1 +1 @@ -{"version":3,"file":"DeployHelper.js","sourceRoot":"","sources":["../../src/utils/DeployHelper.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,+BAA+B;AAC/B,6BAA6B;AAC7B,iDAAqC;AACrC,oDAA6C;AAC7C,MAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACxC,MAAM,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC;AACzD,oEAAoH;AAEpH,wDAAiD;AACjD,0DAAmD;AAGnD,MAAqB,YAAY;IAGhC,YAAoB,eAAyB,EAAU,OAAe,EAAU,YAAoB;QAAhF,oBAAe,GAAf,eAAe,CAAU;QAAU,YAAO,GAAP,OAAO,CAAQ;QAAU,iBAAY,GAAZ,YAAY,CAAQ;QAF5F,0BAAqB,GA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U,CAAC,mBAAmB,CAAC,uBAAuB,MAAM,EAAE,EAAE,IAAI,CAAC,CAAC;iBACtE;qBAAM;oBACN,oBAAU,CAAC,UAAU,CAAC,4CAA4C,OAAO,KAAK,EAAE,IAAI,CAAC,CAAC;iBACtF;aACD;iBAAM;gBACN,UAAU,CAAC,GAAG,EAAE;oBACf,IAAI,CAAC,sBAAsB,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;gBACvD,CAAC,EAAE,IAAI,CAAC,CAAC;aACT;QACF,CAAC;KAAA;IAEa,sBAAsB,CAAC,eAAyB,EAAE,OAAe;;YAC9E,MAAM,IAAI,GAAG,IAAI,CAAC;YAClB,IAAI;gBACH,MAAM,IAAI,GAAG,MAAM,uBAAa,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;gBAC9E,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC;aACpD;YAAC,OAAO,KAAK,EAAE;gBACf,oBAAU,CAAC,UAAU,CAAC,iDAAiD,KAAK,IAAI,CAAC,CAAC;gBAClF,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC;aACzD;QACF,CAAC;KAAA;CACD;AAxLD,+BAwLC"} \ No newline at end of file diff --git a/app-cli/built/utils/StorageHelper.js b/app-cli/built/utils/StorageHelper.js index 5c5ce1b..64e3a47 100755 --- a/app-cli/built/utils/StorageHelper.js +++ b/app-cli/built/utils/StorageHelper.js @@ -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]; diff --git a/app-cli/built/utils/StorageHelper.js.map b/app-cli/built/utils/StorageHelper.js.map index 725cbaf..69096c2 100755 --- a/app-cli/built/utils/StorageHelper.js.map +++ b/app-cli/built/utils/StorageHelper.js.map @@ -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,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;QAC/E,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;QAEzC,OAAO,cAAc,CAAC;IACvB,CAAC;IAED,WAAW,CAAC,qBAA+B;QAC1C,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACxC,IAAI,cAAc,GAAG,KAAK,CAAC;QAC3B,KAAK,IAAI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,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;SACvC;QAED,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC;CACD;AAzED,gCAyEC"} \ No newline at end of file diff --git a/app-cli/built/utils/ValidationsHandler.js b/app-cli/built/utils/ValidationsHandler.js index 6cb5850..2186cec 100755 --- a/app-cli/built/utils/ValidationsHandler.js +++ b/app-cli/built/utils/ValidationsHandler.js @@ -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; diff --git a/app-cli/built/utils/ValidationsHandler.js.map b/app-cli/built/utils/ValidationsHandler.js.map index 342f56f..1f736af 100755 --- a/app-cli/built/utils/ValidationsHandler.js.map +++ b/app-cli/built/utils/ValidationsHandler.js.map @@ -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,CAAC;KACF;IAED,OAAO,CAAC,CAAC,eAAe,CAAC;AAC1B,CAAC;AAXD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Ae,GAAG,KAAK,CAAC;QAC5B,IAAI;YACH,IAAI,SAAS,GAAG,MAAM,uBAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;YAC9D,eAAe,GAAG,IAAI,CAAC;SACvB;QAAC,OAAO,CAAC,EAAE;YACX,SAAS;SACT;QAED,IAAI,CAAC,eAAe,EAAE;YACrB,MAAM,cAAc,GAAG,MAAM,sBAAY,CAAC,OAAO,CAAC,CAAC;SACnD;IACF,CAAC;CAAA;AAZD,oDAYC"} \ No newline at end of file +{"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,CAAC;KACF;IAED,OAAO,CAAC,CAAC,eAAe,CAAC;AAC1B,CAAC;AAXD,0DAWC;AAED,SAAgB,sBAAsB;IACrC,MAAM,uBAAuB,GAAG,EAAE,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAC;IAE1E,IAAI,CAAC,uBAAuB,EAAE;QAC7B,oBAAU,CAAC,UAAU,CAAC,gFAAgF,EAAE,IAAI,CAAC,CAAC;KAC9G;SAAM;QACN,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;QACjE,IAAI,YAAY,GAAG,IAAI,CAAC;QAExB,IAAI;YACH,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SACpC;QAAC,OAAO,CAAC,EAAE;YACX,oBAAU,CAAC,UAAU,CAA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/src/commands/deploy.ts b/app-cli/src/commands/deploy.ts index ed92266..5b16719 100644 --- a/app-cli/src/commands/deploy.ts +++ b/app-cli/src/commands/deploy.ts @@ -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. ' -// ); -// } -// } - -// 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 = 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) => !!answers.captainNameToDeploy + filter: async (branchToPushEntered: string) => { + deployParams.deploySource.branchToPush = branchToPushEntered; + return branchToPushEntered; + }, + when: (answers: IHashMapGeneric) => + !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) => !!answers.branchToPush + choices: (answers: IHashMapGeneric) => { + return CliHelper.get().getAppsAsOptions(allApps); + }, + filter: async (appNameEntered: string) => { + deployParams.appName = appNameEntered; + return appNameEntered; + }, + when: (answers: IHashMapGeneric) => + (!!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) => !!answers.appName + when: (answers: IHashMapGeneric) => + !!deployParams.appName && + !!deployParams.captainMachine && + (!!deployParams.deploySource.branchToPush || !!deployParams.deploySource.tarFilePath) } ]; - const answers = (await inquirer.prompt(questions)) as IHashMapGeneric; + const answersToIgnore = (await inquirer.prompt(questions)) as IHashMapGeneric; - 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); } diff --git a/app-cli/src/models/storage/StoredObjects.ts b/app-cli/src/models/storage/StoredObjects.ts index 8e48527..4916c55 100644 --- a/app-cli/src/models/storage/StoredObjects.ts +++ b/app-cli/src/models/storage/StoredObjects.ts @@ -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; +} diff --git a/app-cli/src/utils/CliHelper.ts b/app-cli/src/utils/CliHelper.ts index 9fa0cae..ad1a868 100644 --- a/app-cli/src/utils/CliHelper.ts +++ b/app-cli/src/utils/CliHelper.ts @@ -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; diff --git a/app-cli/src/utils/DeployHelper.ts b/app-cli/src/utils/DeployHelper.ts index 61115e5..c07d4ff 100644 --- a/app-cli/src/utils/DeployHelper.ts +++ b/app-cli/src/utils/DeployHelper.ts @@ -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(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}`); diff --git a/app-cli/src/utils/StorageHelper.ts b/app-cli/src/utils/StorageHelper.ts index 6810dde..8cbae2b 100644 --- a/app-cli/src/utils/StorageHelper.ts +++ b/app-cli/src/utils/StorageHelper.ts @@ -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]; diff --git a/app-cli/src/utils/ValidationsHandler.ts b/app-cli/src/utils/ValidationsHandler.ts index 7d5043d..d71b6df 100644 --- a/app-cli/src/utils/ValidationsHandler.ts +++ b/app-cli/src/utils/ValidationsHandler.ts @@ -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 }