2016-06-23 11:57:16 +00:00
|
|
|
/*
|
|
|
|
* This tests a flow for cloudron owner creating a selfhosted cloudron on ec2
|
|
|
|
* Owner creates a cloudron, activates it, installs and app and deletes the cloudron eventually
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var AppStore = require('../appstore.js'),
|
|
|
|
assert = require('assert'),
|
2016-06-23 19:46:02 +00:00
|
|
|
AWS = require('aws-sdk'),
|
2016-06-23 11:57:16 +00:00
|
|
|
child_process = require('child_process'),
|
|
|
|
Cloudron = require('../cloudron.js'),
|
|
|
|
common = require('../common.js'),
|
|
|
|
mailer = require('../mailer.js'),
|
2016-08-08 08:05:04 +00:00
|
|
|
semver = require('semver'),
|
2016-08-13 08:18:11 +00:00
|
|
|
sleep = require('../shell.js').sleep,
|
2016-08-08 08:05:04 +00:00
|
|
|
request = require('superagent-sync'),
|
2016-06-23 11:57:16 +00:00
|
|
|
util = require('util');
|
|
|
|
|
|
|
|
require('colors');
|
|
|
|
|
|
|
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
2016-06-23 13:38:05 +00:00
|
|
|
const BOX_VERSION = process.env.BOX_VERSION;
|
2016-06-29 12:38:55 +00:00
|
|
|
const SELFHOST_DOMAIN = process.env.SELFHOST_DOMAIN;
|
2016-06-29 13:28:00 +00:00
|
|
|
const EC2_TYPE = 't2.small';
|
2016-08-04 09:02:16 +00:00
|
|
|
const EC2_SIZE = 30;
|
2016-06-23 13:38:05 +00:00
|
|
|
const EC2_REGION = 'eu-central-1';
|
2016-07-29 19:13:29 +00:00
|
|
|
const EC2_SSH_KEY = 'id_rsa_e2e_selfhost';
|
2016-06-23 13:38:05 +00:00
|
|
|
const EC2_SUBNET = 'subnet-801402e9';
|
|
|
|
const EC2_SECURITY_GROUP = 'sg-b9a473d1';
|
|
|
|
const BACKUP_KEY = 'somesecret';
|
|
|
|
const BACKUP_BUCKET = 'selfhost-test';
|
2016-06-30 11:53:50 +00:00
|
|
|
const AWS_ACCESS_KEY = process.env.AWS_STAGING_ACCESS_KEY;
|
|
|
|
const AWS_ACCESS_SECRET = process.env.AWS_STAGING_SECRET_KEY;
|
2016-06-23 13:38:05 +00:00
|
|
|
|
2016-06-23 11:57:16 +00:00
|
|
|
function machine(args, options) {
|
|
|
|
// https://github.com/nodejs/node-v0.x-archive/issues/9265
|
|
|
|
options = options || { };
|
|
|
|
args = util.isArray(args) ? args : args.match(/[^\s"]+|"([^"]+)"/g);
|
|
|
|
args = args.map(function (e) { return e[0] === '"' ? e.slice(1, -1) : e; }); // remove the quotes
|
|
|
|
|
2016-06-29 12:02:47 +00:00
|
|
|
console.log('cloudron machine ' + args.join(' '));
|
2016-06-23 11:57:16 +00:00
|
|
|
|
|
|
|
try {
|
2016-06-29 12:02:47 +00:00
|
|
|
var cp = child_process.spawnSync('cloudron', ['machine'].concat(args), { stdio: [ options.stdin || 'pipe', options.stdout || 'pipe', 'pipe' ], encoding: options.encoding || 'utf8' });
|
2016-06-23 11:57:16 +00:00
|
|
|
return cp;
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Selfhost EC2 Cloudron creation', function () {
|
|
|
|
this.timeout(0);
|
|
|
|
|
|
|
|
var appStore = new AppStore('https://api.staging.cloudron.io');
|
2016-06-28 12:43:09 +00:00
|
|
|
var ec2 = new AWS.EC2({ accessKeyId: AWS_ACCESS_KEY, secretAccessKey: AWS_ACCESS_SECRET, region: EC2_REGION });
|
2016-06-23 11:57:16 +00:00
|
|
|
|
|
|
|
var owner = common.getOwner();
|
2016-08-13 17:45:07 +00:00
|
|
|
var cloudron, appId, backupInfo, instanceId, restoreInstanceId, migrateInstanceId;
|
2016-08-08 08:05:04 +00:00
|
|
|
var fromVersion, toVersion, nextVersion;
|
|
|
|
|
|
|
|
it('can query versions', function () {
|
|
|
|
var res = request.get('https://s3.amazonaws.com/staging-cloudron-releases/versions.json').end();
|
|
|
|
common.verifyResponse2xx(res);
|
|
|
|
var boxVersions = Object.keys(common.stripUnreachable(res.body)).sort(semver.rcompare);
|
|
|
|
fromVersion = boxVersions[2]; // we released a new version in before.js
|
|
|
|
toVersion = boxVersions[1];
|
|
|
|
assert.strictEqual(toVersion, BOX_VERSION);
|
|
|
|
nextVersion = boxVersions[0];
|
|
|
|
|
|
|
|
console.log('Will test update from %s to %s and then %s', fromVersion.yellow, toVersion.yellow, nextVersion.yellow);
|
|
|
|
});
|
2016-06-23 11:57:16 +00:00
|
|
|
|
|
|
|
it('can create a cloudron', function () {
|
2016-06-28 09:33:28 +00:00
|
|
|
var params = [
|
2016-06-29 12:38:55 +00:00
|
|
|
'--fqdn ' + SELFHOST_DOMAIN,
|
2016-06-28 09:33:28 +00:00
|
|
|
'--type ' + EC2_TYPE,
|
2016-08-04 09:02:16 +00:00
|
|
|
'--disk-size ' + EC2_SIZE,
|
2016-06-28 09:33:28 +00:00
|
|
|
'--region ' + EC2_REGION,
|
|
|
|
'--ssh-key ' + EC2_SSH_KEY,
|
|
|
|
'--access-key-id ' + AWS_ACCESS_KEY,
|
|
|
|
'--secret-access-key ' + AWS_ACCESS_SECRET,
|
|
|
|
'--subnet ' + EC2_SUBNET,
|
|
|
|
'--security-group ' + EC2_SECURITY_GROUP,
|
|
|
|
'--backup-key ' + BACKUP_KEY,
|
|
|
|
'--backup-bucket ' + BACKUP_BUCKET,
|
2016-08-08 08:05:04 +00:00
|
|
|
'--release ' + toVersion
|
2016-06-28 09:33:28 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
var out = machine('create ec2 ' + params.join(' '));
|
2016-08-04 09:43:53 +00:00
|
|
|
console.log(out.stdout, out.stderr);
|
2016-06-23 19:46:02 +00:00
|
|
|
|
2016-07-29 15:04:57 +00:00
|
|
|
if (out.stdout.indexOf('You can now setup your Cloudron at') === -1) {
|
2016-06-23 19:46:02 +00:00
|
|
|
assert(false, 'Creation failed');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wohooo strings!
|
|
|
|
instanceId = out.stdout.split('\n').filter(function (l) { return l.indexOf('ID: ') !== -1; })[0].split(':')[1].trim();
|
|
|
|
|
|
|
|
console.log('New instance created with ID', instanceId);
|
2016-06-23 13:38:05 +00:00
|
|
|
|
|
|
|
cloudron = new Cloudron({
|
2016-06-29 12:38:55 +00:00
|
|
|
domain: SELFHOST_DOMAIN,
|
2016-06-23 13:38:05 +00:00
|
|
|
setupToken: null,
|
2016-08-08 08:05:04 +00:00
|
|
|
version: toVersion,
|
2016-06-23 13:38:05 +00:00
|
|
|
ip: null
|
|
|
|
});
|
2016-06-23 11:57:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can activate the box', function () {
|
|
|
|
cloudron.activate(owner);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can login to the box', function () {
|
|
|
|
var token = cloudron.getOauthToken(owner);
|
|
|
|
cloudron.setCredentials(owner.password, token);
|
|
|
|
});
|
|
|
|
|
2016-08-13 17:42:19 +00:00
|
|
|
it('can take a breather', function () {
|
|
|
|
// ec2 can be really slow to come up. the addon containers take their own sweet time (they are "async" with the box startup)
|
|
|
|
// we end up sending email even before the mail container is ready
|
|
|
|
sleep(120);
|
|
|
|
});
|
|
|
|
|
2016-09-01 16:03:27 +00:00
|
|
|
it('can enable email', function () {
|
|
|
|
cloudron.setEmailEnabled(true);
|
|
|
|
sleep(20); // sometime for the mail container to come up
|
|
|
|
});
|
|
|
|
|
2016-06-23 11:57:16 +00:00
|
|
|
it('send mail to cloudron user', function (done) {
|
2016-06-29 12:38:55 +00:00
|
|
|
mailer.sendMailToCloudronUser(owner.username + '@' + SELFHOST_DOMAIN, done);
|
2016-06-23 11:57:16 +00:00
|
|
|
});
|
|
|
|
|
2016-07-01 17:26:19 +00:00
|
|
|
it('did receive mail', function (done) {
|
|
|
|
cloudron.checkMail(owner, done);
|
|
|
|
});
|
|
|
|
|
2016-06-23 11:57:16 +00:00
|
|
|
var location = 'test' + (Math.random() * 10000).toFixed();
|
|
|
|
it('can install app', function () {
|
|
|
|
var manifest = appStore.getManifest(common.TESTAPP_ID, common.TESTAPP_VERSION);
|
|
|
|
appId = cloudron.installApp(location, manifest);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can populate the addons', function () {
|
|
|
|
cloudron.populateAddons(cloudron.appFqdn(location));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can check the addons', function () {
|
|
|
|
cloudron.checkAddons(cloudron.appFqdn(location), owner);
|
|
|
|
});
|
|
|
|
|
2016-08-08 08:05:04 +00:00
|
|
|
it('can update the box', function () {
|
|
|
|
cloudron.checkForUpdates();
|
2016-06-23 11:57:16 +00:00
|
|
|
|
2016-06-28 09:46:06 +00:00
|
|
|
var params = [
|
2016-08-08 08:05:04 +00:00
|
|
|
SELFHOST_DOMAIN,
|
|
|
|
'--yes',
|
2016-06-28 09:46:06 +00:00
|
|
|
'--ssh-key ' + EC2_SSH_KEY,
|
2016-08-08 08:05:04 +00:00
|
|
|
'--username ' + owner.username,
|
|
|
|
'--password ' + owner.password
|
2016-06-28 09:46:06 +00:00
|
|
|
];
|
|
|
|
|
2016-08-08 08:05:04 +00:00
|
|
|
var out = machine('update ' + params.join(' '));
|
2016-08-04 09:43:53 +00:00
|
|
|
console.log(out.stdout, out.stderr);
|
2016-06-23 19:46:02 +00:00
|
|
|
|
|
|
|
if (out.stdout.indexOf('You can now use your Cloudron at') === -1) {
|
2016-08-08 08:05:04 +00:00
|
|
|
assert(false, 'Update failed');
|
2016-06-23 19:46:02 +00:00
|
|
|
}
|
2016-06-23 11:57:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('wait for app to be ready', function () {
|
|
|
|
cloudron.waitForApp(appId);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can configure app', function () {
|
|
|
|
location = location + 'x';
|
|
|
|
cloudron.configureApp(appId, location);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can check the addons', function () {
|
|
|
|
cloudron.checkAddons(cloudron.appFqdn(location), owner);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can reboot the cloudron', function () {
|
|
|
|
cloudron.reboot();
|
|
|
|
});
|
|
|
|
|
2016-06-28 12:43:09 +00:00
|
|
|
it('runs the app', function () {
|
|
|
|
cloudron.waitForApp(appId);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can check the addons', function () {
|
|
|
|
cloudron.checkAddons(cloudron.appFqdn(location), owner);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can check mail', function (done) {
|
|
|
|
cloudron.checkMail(owner, done);
|
|
|
|
});
|
|
|
|
|
2016-08-08 08:05:04 +00:00
|
|
|
it('can backup the box', function () {
|
|
|
|
backupInfo = cloudron.backup();
|
|
|
|
assert.strictEqual(backupInfo.dependsOn.length, 1);
|
|
|
|
});
|
2016-06-28 12:43:09 +00:00
|
|
|
|
2016-08-08 08:05:04 +00:00
|
|
|
it('can restore the box', function () {
|
2016-06-28 12:43:09 +00:00
|
|
|
var params = [
|
2016-08-08 08:05:04 +00:00
|
|
|
'--fqdn ' + SELFHOST_DOMAIN,
|
|
|
|
'--type ' + EC2_TYPE,
|
|
|
|
'--disk-size ' + EC2_SIZE,
|
|
|
|
'--region ' + EC2_REGION,
|
2016-06-30 10:45:15 +00:00
|
|
|
'--ssh-key ' + EC2_SSH_KEY,
|
2016-08-08 08:05:04 +00:00
|
|
|
'--access-key-id ' + AWS_ACCESS_KEY,
|
|
|
|
'--secret-access-key ' + AWS_ACCESS_SECRET,
|
|
|
|
'--subnet ' + EC2_SUBNET,
|
|
|
|
'--security-group ' + EC2_SECURITY_GROUP,
|
|
|
|
'--backup-key ' + BACKUP_KEY,
|
|
|
|
'--backup-bucket ' + BACKUP_BUCKET,
|
|
|
|
'--backup ' + backupInfo.id,
|
2016-06-28 12:43:09 +00:00
|
|
|
];
|
|
|
|
|
2016-08-08 08:05:04 +00:00
|
|
|
var out = machine('restore ec2 ' + params.join(' '));
|
2016-08-04 09:43:53 +00:00
|
|
|
console.log(out.stdout, out.stderr);
|
2016-06-28 12:43:09 +00:00
|
|
|
|
|
|
|
if (out.stdout.indexOf('You can now use your Cloudron at') === -1) {
|
2016-08-08 08:05:04 +00:00
|
|
|
assert(false, 'Restore failed');
|
2016-06-28 12:43:09 +00:00
|
|
|
}
|
2016-08-08 08:05:04 +00:00
|
|
|
|
2016-08-13 17:45:07 +00:00
|
|
|
restoreInstanceId = out.stdout.split('\n').filter(function (l) { return l.indexOf('ID: ') !== -1; })[0].split(':')[1].trim();
|
2016-08-08 08:05:04 +00:00
|
|
|
|
2016-08-13 17:45:07 +00:00
|
|
|
console.log('New instance created with ID', restoreInstanceId);
|
2016-06-28 12:43:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('runs the app', function () {
|
|
|
|
cloudron.waitForApp(appId);
|
|
|
|
});
|
|
|
|
|
2016-07-01 10:15:53 +00:00
|
|
|
// Only works so far with upgrades, as the app needs to be restarted for the test to suceed
|
|
|
|
xit('can check the addons', function () {
|
2016-06-23 11:57:16 +00:00
|
|
|
cloudron.checkAddons(cloudron.appFqdn(location), owner);
|
|
|
|
});
|
|
|
|
|
2016-07-29 14:17:49 +00:00
|
|
|
it('can migrate cloudron', function () {
|
|
|
|
var params = [
|
|
|
|
'--fqdn ' + SELFHOST_DOMAIN,
|
|
|
|
'--ssh-key ' + EC2_SSH_KEY,
|
|
|
|
'--access-key-id ' + AWS_ACCESS_KEY,
|
|
|
|
'--secret-access-key ' + AWS_ACCESS_SECRET,
|
|
|
|
];
|
|
|
|
|
2016-07-29 18:06:03 +00:00
|
|
|
var out = machine('migrate ec2 ' + params.join(' '));
|
2016-08-04 09:43:53 +00:00
|
|
|
console.log(out.stdout, out.stderr);
|
2016-07-29 14:17:49 +00:00
|
|
|
|
|
|
|
if (out.stdout.indexOf('You can now use your Cloudron at') === -1) {
|
2016-07-29 18:06:03 +00:00
|
|
|
assert(false, 'Migrate failed');
|
2016-07-29 14:17:49 +00:00
|
|
|
}
|
2016-08-13 17:45:07 +00:00
|
|
|
|
|
|
|
migrateInstanceId = out.stdout.split('\n').filter(function (l) { return l.indexOf('ID: ') !== -1; })[0].split(':')[1].trim();
|
|
|
|
|
|
|
|
console.log('New instance created with ID', restoreInstanceId);
|
2016-07-29 14:17:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('runs the app', function () {
|
|
|
|
cloudron.waitForApp(appId);
|
|
|
|
});
|
|
|
|
|
2016-06-23 11:57:16 +00:00
|
|
|
it('can uninstall app', function () {
|
|
|
|
cloudron.uninstallApp(appId);
|
|
|
|
});
|
|
|
|
|
2016-08-13 08:08:38 +00:00
|
|
|
it('can delete the cloudron', function (done) {
|
2016-07-01 14:04:44 +00:00
|
|
|
console.log('Cleanup EC2 instances');
|
|
|
|
|
2016-06-23 19:46:02 +00:00
|
|
|
var params = {
|
2016-08-13 17:45:07 +00:00
|
|
|
InstanceIds: [ instanceId, restoreInstanceId, migrateInstanceId ]
|
2016-06-23 19:46:02 +00:00
|
|
|
};
|
|
|
|
|
2016-07-01 14:04:44 +00:00
|
|
|
ec2.terminateInstances(params, function (error) {
|
|
|
|
if (error) console.log(error);
|
|
|
|
done();
|
|
|
|
});
|
2016-06-23 11:57:16 +00:00
|
|
|
});
|
|
|
|
});
|