Skip to content

Commit

Permalink
Merge pull request #331 from MitocGroup/task_330
Browse files Browse the repository at this point in the history
#330 Integrate deepify update command into deepify deploy command
  • Loading branch information
mgoria committed Mar 21, 2017
2 parents a9d1a95 + 7674097 commit 8064620
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 19 deletions.
85 changes: 84 additions & 1 deletion src/bin/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = function(mainPath) {
let Exec = require('../../lib.compiled/Helpers/Exec').Exec;
let Bin = require('../../lib.compiled/NodeJS/Bin').Bin;
let Prompt = require('../../lib.compiled/Terminal/Prompt').Prompt;
let LambdasExtractor = require('../../lib.compiled/Helpers/LambdasExtractor').LambdasExtractor;
let Property = require('deep-package-manager').Property_Instance;
let SharedAwsConfig = require('deep-package-manager').Helpers_SharedAwsConfig;
let Config = require('deep-package-manager').Property_Config;
Expand All @@ -25,6 +26,7 @@ module.exports = function(mainPath) {
let DeployConfig = require('deep-package-manager').Property_DeployConfig;
let Listing = require('deep-package-manager').Provisioning_Listing;

let resourcesToUpdate = this.opts.locate('action').value;
let isProd = this.opts.locate('prod').exists;
let localOnly = this.opts.locate('dry-run').exists;
let invalidateCache = this.opts.locate('invalidate-cache').exists;
Expand All @@ -34,6 +36,7 @@ module.exports = function(mainPath) {
let microservicesToDeploy = this.opts.locate('partial').value;
let frontendOnly = this.opts.locate('frontend').exists ? Property.DEPLOY_FRONTEND : 0;
let backendOnly = this.opts.locate('backend').exists ? Property.DEPLOY_BACKEND : 0;
let debugBuild = this.opts.locate('debug-build').exists;
let validateNodeVersion = require('./helper/validate-node-version');
let undeployRunning = false;

Expand Down Expand Up @@ -273,6 +276,16 @@ module.exports = function(mainPath) {
return typeof msIdentifiers === 'string' ? [msIdentifiers] : msIdentifiers;
};

let getResourcesToUpdate = () => {
if (!resourcesToUpdate) {
return null;
}

let msIdentifiers = arrayUnique(resourcesToUpdate.split(',').map(id => id.trim()));

return typeof msIdentifiers === 'string' ? [msIdentifiers] : msIdentifiers;
};

let doDeploy = () => {
propertyInstance.localDeploy = localOnly;

Expand Down Expand Up @@ -365,8 +378,14 @@ module.exports = function(mainPath) {
propertyPath
);

let resourcesToCompile = microservicesToDeploy || resourcesToUpdate;

invalidateCache && cmd.addArg('--invalidate-cache');
microservicesToDeploy && cmd.addArg('--partial ' + microservicesToDeploy);
resourcesToCompile && cmd.addArg(`--partial="${resourcesToCompile}"`);

if (debugBuild) {
cmd.addArg('--debug-build');
}

cmd.run((result) => {
if (result.failed) {
Expand Down Expand Up @@ -434,6 +453,70 @@ module.exports = function(mainPath) {
}
};

let askForProductionPrepare = (cb) => {
if (debugBuild) {
// if --debug-build is present,
// run 'compile prod' with --debug-build flag, without asking
return cb(true);
}

let prompt = new Prompt(`Prepare for production "${resourcesToUpdate}"?`);

prompt.readConfirm(cb);
};

let updateResources = (resourcesIdentifiers) => {
propertyInstance.configObj.tryLoadConfig(() => {
if (!propertyInstance.configObj.configExists) {
throw new Error('Action deploy is available only on application update');
}

let prepareResources = (path, cb) => {
console.debug(`Skipping "${resourcesToUpdate}" production preparation...`);

cb();
};

askForProductionPrepare((result) => {
if (result) {
prepareResources = doCompileProd.bind(this);
}

prepareResources(propertyInstance.path, () => {
Promise.all(
resourcesIdentifiers.map(resource => {
return new Promise((resolve, reject) => {
try {
propertyInstance.deployAction('@' + resource, () => {
console.info(`"${resource}" has been updated.`);
resolve();
});
} catch(e) {
reject(e);
}
});
})
).then(() => {
console.info('All resources have been updated.');
}).catch(e => {
setImmediate(() => {
throw e;
});
});
});
});
});
};

if (resourcesToUpdate) {
let resourcesIdentifiers = Object.keys(
new LambdasExtractor(propertyInstance, getResourcesToUpdate())
.extract(LambdasExtractor.NPM_PACKAGE_FILTER, LambdasExtractor.EXTRACT_OBJECT)
);

return updateResources(resourcesIdentifiers);
}

process.on('exit', () => {
new Exec('rm', '-rf', path.join(propertyInstance.path, '_public'))
.avoidBufferOverflow()
Expand Down
27 changes: 9 additions & 18 deletions src/bin/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,6 @@ module.exports = {
},
},
},
'update': {
example: 'deepify update path/to/web_app -m deep-todomvc:task:create',
description: 'Update resource',
section: 'Run in the cloud',
opts: {
'debug-build': {
alias: 'd',
required: false,
description: 'Skip installing/optimizing node_modules and keep existing ones in lambda directory',
},
partial: {
alias: 'm',
description: 'Partial deploy (one or several comma separated microservices identifiers)',
required: true,
},
},
args: {},
},
'install': {
example: 'deepify install github://MitocGroup/deep-microservices-todo-app',
description: 'Install any DEEP microservice or microapplication from DEEP registry or GitHub repository',
Expand Down Expand Up @@ -155,6 +137,11 @@ module.exports = {
description: 'Partial deploy (one or several comma separated microservices identifiers)',
required: false,
},
action: {
alias: 'a',
description: 'Update one or more backend action. Works only on application update',
required: false,
},
'invalidate-cache': {
description: 'Invalidate deep dependencies cache',
required: false,
Expand All @@ -167,6 +154,10 @@ module.exports = {
description: 'Deploy only backend resource',
required: false,
},
'debug-build': {
description: 'Use existing node_modules in lambdas, instead of (re)installing them',
required: false,
}
},
args: {
path: {
Expand Down

0 comments on commit 8064620

Please sign in to comment.