diff --git a/meteor/.jshintrc b/meteor/.jshintrc index 2f77f05ffa..61e603f116 100755 --- a/meteor/.jshintrc +++ b/meteor/.jshintrc @@ -201,7 +201,7 @@ "restartApp": true, "deleteApp": true, "deleteFolder": true, - "loadKiteVolumes": true, + "copyVolumes": true, "getAppLogs": true, "hasDockerfile": true, "createTarFile": true, diff --git a/meteor/collections/apps.js b/meteor/collections/apps.js index 05006eb8e2..5bbc9ef2a9 100755 --- a/meteor/collections/apps.js +++ b/meteor/collections/apps.js @@ -117,6 +117,29 @@ Apps.helpers({ Apps.attachSchema(schemaApps); +Apps.after.insert(function (userId, app) { + // Give app an unique environment variable + var appId = this._id; + Apps.update(appId, { + $set: { + 'config.APP_ID': appId + } + }); + var image = Images.findOne(app.imageId); + copyVolumes(image.path, app.name); + app = Apps.findOne(appId); + removeBindFolder(app.name, function (err) { + if (err) { + console.error(err); + } + Fiber(function () { + Meteor.call('runApp', app, function (err) { + if (err) { throw err; } + }); + }).run(); + }); +}); + Apps.after.remove(function (userId, app) { deleteApp(app, function (err) { if (err) { console.error(err); } diff --git a/meteor/server/apps.js b/meteor/server/apps.js index 07a51cfa58..a52495810f 100755 --- a/meteor/server/apps.js +++ b/meteor/server/apps.js @@ -58,39 +58,22 @@ Meteor.methods({ throw new Meteor.Error(400, 'Validation Failed.', validationResult.errors); } else { var cleaned = validationResult.cleaned; - var appObj = { - name: cleaned.name, - imageId: cleaned.imageId, - status: 'STARTING', - config: {} - }; - var appId = Apps.insert(appObj); - var appPath = path.join(KITE_PATH, appObj.name); + var appName = cleaned.name; + var appPath = path.join(KITE_PATH, appName); if (!fs.existsSync(appPath)) { - console.log('Created Kite ' + appObj.name + ' directory.'); + console.log('Created Kite ' + appName + ' directory.'); fs.mkdirSync(appPath, function (err) { if (err) { throw err; } }); } - Apps.update(appId, { - $set: { - 'config.APP_ID': appId, - path: appPath - } - }); - var image = Images.findOne(appObj.imageId); - loadKiteVolumes(image.path, appObj.name); - var app = Apps.findOne(appId); - removeBindFolder(app.name, function (err) { - if (err) { - console.error(err); - } - Fiber(function () { - Meteor.call('runApp', app, function (err) { - if (err) { throw err; } - }); - }).run(); - }); + var appObj = { + name: appName, + imageId: cleaned.imageId, + status: 'STARTING', + config: {}, + path: appPath + }; + Apps.insert(appObj); } }, getAppLogs: function (appId) { diff --git a/meteor/server/lib/utilities.js b/meteor/server/lib/utilities.js index 4be5a0edaa..a0446ad702 100755 --- a/meteor/server/lib/utilities.js +++ b/meteor/server/lib/utilities.js @@ -62,7 +62,7 @@ getImageJSON = function (directory) { } }; -loadKiteVolumes = function (directory, appName) { +copyVolumes = function (directory, appName) { var KITE_VOLUMES_PATH = path.join(directory, 'volumes'); if (fs.existsSync(KITE_VOLUMES_PATH)) { var destinationPath = path.join(KITE_PATH, appName);