diff --git a/src/apps.js b/src/apps.js index 1ec80dbff..81144a151 100644 --- a/src/apps.js +++ b/src/apps.js @@ -74,8 +74,6 @@ var BACKUP_APP_CMD = path.join(__dirname, 'scripts/backupapp.sh'), RESTORE_APP_CMD = path.join(__dirname, 'scripts/restoreapp.sh'), BACKUP_SWAP_CMD = path.join(__dirname, 'scripts/backupswap.sh'); -var DEFAULT_MEMORY_LIMIT = (256 * 1024 * 1024); - function debugApp(app, args) { assert(!app || typeof app === 'object'); @@ -218,7 +216,7 @@ function validateMemoryLimit(manifest, memoryLimit) { assert.strictEqual(typeof manifest, 'object'); assert.strictEqual(typeof memoryLimit, 'number'); - var min = manifest.memoryLimit || DEFAULT_MEMORY_LIMIT; + var min = manifest.memoryLimit || constants.DEFAULT_MEMORY_LIMIT; var max = (4096 * 1024 * 1024); // allow 0, which indicates that it is not set, the one from the manifest will be choosen but we don't commit any user value @@ -380,7 +378,7 @@ function install(appId, appStoreId, manifest, location, portBindings, accessRest if (error) return callback(new AppsError(AppsError.BAD_FIELD, error.message)); // memoryLimit might come in as 0 if not specified - memoryLimit = memoryLimit || manifest.memoryLimit || DEFAULT_MEMORY_LIMIT; + memoryLimit = memoryLimit || manifest.memoryLimit || constants.DEFAULT_MEMORY_LIMIT; // singleUser mode requires accessRestriction to contain exactly one user if (manifest.singleUser && accessRestriction === null) return callback(new AppsError(AppsError.USER_REQUIRED)); @@ -450,7 +448,7 @@ function configure(appId, location, portBindings, accessRestriction, oauthProxy, if (error) return callback(new AppsError(AppsError.BAD_FIELD, error.message)); // memoryLimit might come in as 0 if not specified - memoryLimit = memoryLimit || app.memoryLimit || app.manifest.memoryLimit || DEFAULT_MEMORY_LIMIT; + memoryLimit = memoryLimit || app.memoryLimit || app.manifest.memoryLimit || constants.DEFAULT_MEMORY_LIMIT; // save cert to data/box/certs if (cert && key) { diff --git a/src/constants.js b/src/constants.js index 23476ceb7..6b68a9bfd 100644 --- a/src/constants.js +++ b/src/constants.js @@ -7,6 +7,8 @@ exports = module.exports = { ADMIN_NAME: 'Settings', ADMIN_CLIENT_ID: 'webadmin', // oauth client id - ADMIN_APPID: 'admin' // admin appid (settingsdb) + ADMIN_APPID: 'admin', // admin appid (settingsdb) + + DEFAULT_MEMORY_LIMIT: (256 * 1024 * 1024) }; diff --git a/src/docker.js b/src/docker.js index 7b36f4cc1..03dafba52 100644 --- a/src/docker.js +++ b/src/docker.js @@ -4,6 +4,7 @@ var addons = require('./addons.js'), async = require('async'), assert = require('assert'), config = require('./config.js'), + constants = require('./constants.js'), debug = require('debug')('box:src/docker.js'), Docker = require('dockerode'), safe = require('safetydance'), @@ -160,7 +161,7 @@ function createSubcontainer(app, name, cmd, options, callback) { var memoryLimit = app.memoryLimit || manifest.memoryLimit; // ensure we never go below minimum - memoryLimit = memoryLimit < (1024 * 1024 * 256) ? (1024 * 1024 * 256) : memoryLimit; // 256mb by default + memoryLimit = memoryLimit < constants.DEFAULT_MEMORY_LIMIT ? constants.DEFAULT_MEMORY_LIMIT : memoryLimit; // 256mb by default // developerMode does not restrict memory usage memoryLimit = developmentMode ? 0 : memoryLimit;