dce-dev-wizard
Version:
Wizard for managing development apps at Harvard DCE.
191 lines • 7.6 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const clear_1 = __importDefault(require("clear"));
// Import helpers
const showChooser_1 = __importDefault(require("../helpers/showChooser"));
const getDeploymentConfig_1 = __importDefault(require("../operations/getDeploymentConfig"));
const print_1 = __importDefault(require("../helpers/print"));
const exec_1 = __importDefault(require("../helpers/exec"));
const getPackageJSON_1 = __importDefault(require("../helpers/getPackageJSON"));
const validateNodeVersion_1 = __importDefault(require("../helpers/validateNodeVersion"));
const deployCustomNow_1 = __importDefault(require("./deployCustomNow"));
const config_1 = __importDefault(require("../helpers/config"));
// Import constants
const APP_DIRECTORY_1 = __importDefault(require("../constants/APP_DIRECTORY"));
/**
* Perform a deploy now
* @author Gabe Abrams
* @param deployment the currently selected deployment
*/
const deployNow = (deployment) => __awaiter(void 0, void 0, void 0, function* () {
// Check for custom deployment process
let doingCustomDeployment = false;
if (deployment.customStackInfo && config_1.default.customStackDeploymentProcess) {
// Ask the user if they want to do the custom deployment process
const { tag } = (0, showChooser_1.default)({
title: 'Multiple Deployment Processes',
question: 'Which deployment process do you want to run?',
options: [
{
description: 'App (Main Deployment Process)',
tag: 'A',
},
{
description: `Custom (${config_1.default.customStackDeploymentProcess.description})`,
tag: 'C',
},
],
});
doingCustomDeployment = (tag === 'C');
}
if (doingCustomDeployment) {
// Run custom deployment process
yield (0, deployCustomNow_1.default)(deployment);
return;
}
// Normal app deployment process
// Choose an operation
const { tag } = (0, showChooser_1.default)({
question: 'Have you changed the deploy config?',
options: [
{
description: 'Yes, I changed env vars, branch, and/or version',
tag: 'Y',
},
{
description: 'No, I just want to deploy with same config',
tag: 'N',
},
],
title: 'Ready to Deploy',
});
// Show loading indicator
(0, clear_1.default)();
console.log('Loading current info...\n');
const deployConfig = (0, getDeploymentConfig_1.default)(deployment);
// Get last part of the app image
const parts = deployConfig.appImage.split(':');
const branchOrVersion = parts[parts.length - 1];
// Check type
const isVersion = branchOrVersion.includes('.');
// Process branch name
const processedBranchName = branchOrVersion.replace('-', '/');
// Information
(0, clear_1.default)();
print_1.default.title('About to Deploy');
console.log('');
console.log('Information:');
console.log(`Deploying to: ${deployment.name}`);
console.log(`Branch: ${isVersion ? 'main branch' : processedBranchName}`);
console.log(`Version: ${isVersion ? branchOrVersion : '[Most Recent Build]'}`);
if (tag === 'Y') {
console.log('Operation: update deploy config then restart');
}
else {
console.log('Operation: restart with unmodified config');
}
console.log('');
// Ask for confirmation
const confirmOption = (0, showChooser_1.default)({
question: 'Ready to continue?',
options: [
{
description: 'Yes',
tag: 'Y',
},
{
description: 'No',
tag: 'N',
},
],
dontClear: true,
});
if (confirmOption.tag === 'N') {
// Cancel
(0, clear_1.default)();
print_1.default.title('Cancelled!');
console.log('');
print_1.default.enterToContinue();
return;
}
// Validate Node version
yield (0, validateNodeVersion_1.default)();
// Ask user if they waited for the action to build
const packageJSON = (0, getPackageJSON_1.default)(path_1.default.join(APP_DIRECTORY_1.default, 'package.json'));
if (packageJSON.repository && packageJSON.repository.url) {
const actionsPanelURL = (packageJSON.repository.url
.replace('git+http', 'http')
.replace('.git', '/actions'));
// Print warning
(0, clear_1.default)();
print_1.default.title('Did you wait for the action to finish?');
console.log('');
console.log('Actions panel:');
console.log(actionsPanelURL);
console.log('');
print_1.default.enterToContinue();
}
// Redeploy
if (tag === 'Y') {
(0, clear_1.default)();
console.log('Loading diff...\n');
// Confirm diff
const diff = (0, exec_1.default)(`./node_modules/.bin/caccl-deploy stack --profile ${deployment.profile} --app ${deployment.app} diff`);
console.log('');
print_1.default.title('Confirm Deploy Config Diff:');
console.log('');
console.log(diff);
// Ask user to confirm
const secondaryConfirmOption = (0, showChooser_1.default)({
question: 'Ready to continue?',
options: [
{
description: 'Yes',
tag: 'Y',
},
{
description: 'No',
tag: 'N',
},
],
dontClear: true,
});
if (secondaryConfirmOption.tag === 'N') {
// Cancel
(0, clear_1.default)();
print_1.default.title('Cancelled!');
console.log('');
print_1.default.enterToContinue();
return;
}
// Deploy (update config)
(0, exec_1.default)(`./node_modules/.bin/caccl-deploy stack --profile ${deployment.profile} --app ${deployment.app} deploy -y`, true);
}
else {
// Restart
(0, clear_1.default)();
console.log('Restarting service...');
console.log('');
(0, exec_1.default)(`./node_modules/.bin/caccl-deploy restart --profile ${deployment.profile} --app ${deployment.app} -y`, true);
}
// Confirmation
(0, clear_1.default)();
print_1.default.title('Deploy Successful');
console.log('');
print_1.default.enterToContinue();
});
exports.default = deployNow;
//# sourceMappingURL=deployNow.js.map