Skip to content

Commit

Permalink
Fix upgrade command
Browse files Browse the repository at this point in the history
  • Loading branch information
j3k0 committed Dec 13, 2015
1 parent a1ed3c0 commit ada13b3
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/command/upgrade.js
Expand Up @@ -14,30 +14,30 @@ cmd.register = function(program) {
cmd.registerFull = function(program) {
return program
.arguments('<deploy-id>')
.option('--upgrade-version [VERSION]',
'Version number (default=' + mods.package.version + ')');
.option('--force', 'Force to perform the upgrade')
.option('--no-pull', 'Do not pull docker images');
};

cmd.action = function(options, cb) {
var id = options.args[0];
var version = options.upgradeVersion || cmd.defaults.version;
var conf = deploys.safeLoad(id);
var version = mods.package.version;
var conf = mods.deploys.safeLoad(id);

// Check if upgrade is possible and necessary
if (conf.version == version)
if (!options.force && conf.version == version)
return mods.utils.error(cb, "Already using the given version");

var needUpgradeTo = mods.utils.minVersion(conf.version);
if (!needUpgradeTo(version))
if (!options.force && !needUpgradeTo(version))
return mods.utils.error(cb, "Already using a newer version");

if (version !== mods.package.version)
if (!options.force && version !== mods.package.version)
return mods.utils.error(cb, "You're not running shasoco " + version + ". Please update with 'shasoco version'");

if (conf.upgradeInProgress)
if (!options.force && conf.upgradeInProgress)
return mods.utils.error(cb, "An upgrade is already in progress (or was interrupted). Please check what happened. You can bypass this by editing the project's config.yml file located in ~/.shasoco/deploys");

if (conf.status !== 'UP')
if (!options.force && conf.status !== 'UP')
return mods.utils.error(cb, "Make sure the deploy is UP and running before doing the upgrade");

// All good, let's go
Expand All @@ -49,17 +49,18 @@ cmd.action = function(options, cb) {
mods.utils.callForAll(mods.services, 'preUpgrade', conf);

// Turn all services down
var compose = deploys.compose(conf);
var compose = mods.deploys.compose(conf);
mods.utils.callForAll(mods.services, 'down', conf);

// Let's get really sure all are stopped
compose('stop');

// Update compose files
mods.deploys.upgrade(conf);
mods.deploys.upgrade(conf, mods.services);

// Pull updated images
compose('pull');
if (options.pull)
compose('pull');

// Upgrade all services
mods.utils.callForAll(mods.services, 'upgrade', conf);
Expand Down

0 comments on commit ada13b3

Please sign in to comment.