diff --git a/migrations/20171116203507-apps-rename-newConfigJson-to-updateConfigJson.js b/migrations/20171116203507-apps-rename-newConfigJson-to-updateConfigJson.js new file mode 100644 index 000000000..af6de3807 --- /dev/null +++ b/migrations/20171116203507-apps-rename-newConfigJson-to-updateConfigJson.js @@ -0,0 +1,15 @@ +'use strict'; + +exports.up = function(db, callback) { + db.runSql('ALTER TABLE apps CHANGE newConfigJson updateConfigJson VARCHAR(2048)', [], function (error) { + if (error) console.error(error); + callback(error); + }); +}; + +exports.down = function(db, callback) { + db.runSql('ALTER TABLE apps CHANGE newConfigJson updateConfigJson VARCHAR(2048)', [], function (error) { + if (error) console.error(error); + callback(error); + }); +}; diff --git a/migrations/schema.sql b/migrations/schema.sql index 7b8e405e3..e6a96f74a 100644 --- a/migrations/schema.sql +++ b/migrations/schema.sql @@ -74,7 +74,7 @@ CREATE TABLE IF NOT EXISTS apps( // the following fields do not belong here, they can be removed when we use a queue for apptask lastBackupId VARCHAR(128), // used to pass backupId to restore from to apptask oldConfigJson TEXT, // used to pass old config for apptask (configure, restore) - newConfigJson TEXT, // used to pass new config for apptask (update) + updateConfigJson TEXT, // used to pass new config for apptask (update) PRIMARY KEY(id)); diff --git a/src/appdb.js b/src/appdb.js index 2df4e1d15..64643e58b 100644 --- a/src/appdb.js +++ b/src/appdb.js @@ -60,7 +60,7 @@ var assert = require('assert'), var APPS_FIELDS_PREFIXED = [ 'apps.id', 'apps.appStoreId', 'apps.installationState', 'apps.installationProgress', 'apps.runState', 'apps.health', 'apps.containerId', 'apps.manifestJson', 'apps.httpPort', 'apps.location', 'apps.dnsRecordId', - 'apps.accessRestrictionJson', 'apps.lastBackupId', 'apps.oldConfigJson', 'apps.newConfigJson', 'apps.memoryLimit', 'apps.altDomain', + 'apps.accessRestrictionJson', 'apps.lastBackupId', 'apps.oldConfigJson', 'apps.updateConfigJson', 'apps.memoryLimit', 'apps.altDomain', 'apps.xFrameOptions', 'apps.sso', 'apps.debugModeJson', 'apps.robotsTxt', 'apps.enableBackup' ].join(','); var PORT_BINDINGS_FIELDS = [ 'hostPort', 'environmentVariable', 'appId' ].join(','); @@ -76,9 +76,9 @@ function postProcess(result) { result.oldConfig = safe.JSON.parse(result.oldConfigJson); delete result.oldConfigJson; - assert(result.newConfigJson === null || typeof result.newConfigJson === 'string'); - result.newConfig = safe.JSON.parse(result.newConfigJson); - delete result.newConfigJson; + assert(result.updateConfigJson === null || typeof result.updateConfigJson === 'string'); + result.updateConfig = safe.JSON.parse(result.updateConfigJson); + delete result.updateConfigJson; assert(result.hostPorts === null || typeof result.hostPorts === 'string'); assert(result.environmentVariables === null || typeof result.environmentVariables === 'string'); @@ -322,7 +322,7 @@ function updateWithConstraints(id, app, constraints, callback) { var fields = [ ], values = [ ]; for (var p in app) { - if (p === 'manifest' || p === 'oldConfig' || p === 'newConfig' || p === 'accessRestriction' || p === 'debugMode') { + if (p === 'manifest' || p === 'oldConfig' || p === 'updateConfig' || p === 'accessRestriction' || p === 'debugMode') { fields.push(`${p}Json = ?`); values.push(JSON.stringify(app[p])); } else if (p !== 'portBindings') { diff --git a/src/apps.js b/src/apps.js index 3367f5122..64f4da20d 100644 --- a/src/apps.js +++ b/src/apps.js @@ -636,7 +636,7 @@ function update(appId, data, auditSource, callback) { downloadManifest(data.appStoreId, data.manifest, function (error, appStoreId, manifest) { if (error) return callback(error); - var newConfig = { }; + var updateConfig = { }; error = manifestFormat.parse(manifest); if (error) return callback(new AppsError(AppsError.BAD_FIELD, 'Manifest error:' + error.message)); @@ -644,7 +644,7 @@ function update(appId, data, auditSource, callback) { error = checkManifestConstraints(manifest); if (error) return callback(error); - newConfig.manifest = manifest; + updateConfig.manifest = manifest; if ('icon' in data) { if (data.icon) { @@ -664,22 +664,22 @@ function update(appId, data, auditSource, callback) { // prevent user from installing a app with different manifest id over an existing app // this allows cloudron install -f --app for an app installed from the appStore - if (app.manifest.id !== newConfig.manifest.id) { + if (app.manifest.id !== updateConfig.manifest.id) { if (!data.force) return callback(new AppsError(AppsError.BAD_FIELD, 'manifest id does not match. force to override')); // clear appStoreId so that this app does not get updates anymore - newConfig.appStoreId = ''; + updateConfig.appStoreId = ''; } // do not update apps in debug mode if (app.debugMode && !data.force) return callback(new AppsError(AppsError.BAD_STATE, 'debug mode enabled. force to override')); // Ensure we update the memory limit in case the new app requires more memory as a minimum - // 0 and -1 are special newConfig for memory limit indicating unset and unlimited - if (app.memoryLimit > 0 && newConfig.manifest.memoryLimit && app.memoryLimit < newConfig.manifest.memoryLimit) { - newConfig.memoryLimit = newConfig.manifest.memoryLimit; + // 0 and -1 are special updateConfig for memory limit indicating unset and unlimited + if (app.memoryLimit > 0 && updateConfig.manifest.memoryLimit && app.memoryLimit < updateConfig.manifest.memoryLimit) { + updateConfig.memoryLimit = updateConfig.manifest.memoryLimit; } - appdb.setInstallationCommand(appId, data.force ? appdb.ISTATE_PENDING_FORCE_UPDATE : appdb.ISTATE_PENDING_UPDATE, { newConfig: newConfig }, function (error) { + appdb.setInstallationCommand(appId, data.force ? appdb.ISTATE_PENDING_FORCE_UPDATE : appdb.ISTATE_PENDING_UPDATE, { updateConfig: updateConfig }, function (error) { if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.BAD_STATE)); // might be a bad guess if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); diff --git a/src/apptask.js b/src/apptask.js index 4a0b4969f..520d10bc6 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -575,17 +575,17 @@ function update(app, callback) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof callback, 'function'); - debugApp(app, `Updating to ${app.newConfig.manifest.version}`); + debugApp(app, `Updating to ${app.updateConfig.manifest.version}`); // app does not want these addons anymore // FIXME: this does not handle option changes (like multipleDatabases) - var unusedAddons = _.omit(app.manifest.addons, Object.keys(app.newConfig.manifest.addons)); + var unusedAddons = _.omit(app.manifest.addons, Object.keys(app.updateConfig.manifest.addons)); async.series([ // this protects against the theoretical possibility of an app being marked for update from // a previous version of box code updateApp.bind(null, app, { installationProgress: '0, Verify manifest' }), - verifyManifest.bind(null, app.newConfig.manifest), + verifyManifest.bind(null, app.updateConfig.manifest), function (next) { if (app.installationState === appdb.ISTATE_PENDING_FORCE_UPDATE) return next(null); @@ -599,7 +599,7 @@ function update(app, callback) { // download new image before app is stopped. this is so we can reduce downtime // and also not remove the 'common' layers when the old image is deleted updateApp.bind(null, app, { installationProgress: '25, Downloading image' }), - docker.downloadImage.bind(null, app.newConfig.manifest), + docker.downloadImage.bind(null, app.updateConfig.manifest), // note: we cleanup first and then backup. this is done so that the app is not running should backup fail // we cannot easily 'recover' from backup failures because we have to revert manfest and portBindings @@ -609,7 +609,7 @@ function update(app, callback) { stopApp.bind(null, app), deleteContainers.bind(null, app), function deleteImageIfChanged(done) { - if (app.manifest.dockerImage === app.newConfig.manifest.dockerImage) return done(); + if (app.manifest.dockerImage === app.updateConfig.manifest.dockerImage) return done(); docker.deleteImage(app.manifest, done); }, @@ -621,7 +621,7 @@ function update(app, callback) { function (next) { // make sure we always have objects var currentPorts = app.portBindings || {}; - var newPorts = app.newConfig.manifest.tcpPorts || {}; + var newPorts = app.updateConfig.manifest.tcpPorts || {}; async.each(Object.keys(currentPorts), function (portName, callback) { if (newPorts[portName]) return callback(); // port still in use @@ -639,7 +639,7 @@ function update(app, callback) { }, // switch over to the new config. manifest, memoryLimit, portBindings, appstoreId are updated here - updateApp.bind(null, app, app.newConfig), + updateApp.bind(null, app, app.updateConfig), updateApp.bind(null, app, { installationProgress: '45, Downloading icon' }), downloadIcon.bind(null, app), @@ -661,7 +661,7 @@ function update(app, callback) { // done! function (callback) { debugApp(app, 'updated'); - updateApp(app, { installationState: appdb.ISTATE_INSTALLED, installationProgress: '', health: null, newConfig: null }, callback); + updateApp(app, { installationState: appdb.ISTATE_INSTALLED, installationProgress: '', health: null, updateConfig: null }, callback); } ], function seriesDone(error) { if (error) { diff --git a/src/test/database-test.js b/src/test/database-test.js index 05c068f0f..6bfb41559 100644 --- a/src/test/database-test.js +++ b/src/test/database-test.js @@ -538,7 +538,7 @@ describe('database', function () { accessRestriction: null, lastBackupId: null, oldConfig: null, - newConfig: null, + updateConfig: null, memoryLimit: 4294967296, altDomain: null, xFrameOptions: 'DENY', @@ -563,7 +563,7 @@ describe('database', function () { accessRestriction: { users: [ 'foobar' ] }, lastBackupId: null, oldConfig: null, - newConfig: null, + updateConfig: null, memoryLimit: 0, altDomain: null, xFrameOptions: 'SAMEORIGIN',