Skip to content

Commit

Permalink
Merge pull request #196 from PhyrexTsai/master
Browse files Browse the repository at this point in the history
Add instances for kaizen
  • Loading branch information
PhyrexTsai authored Nov 5, 2019
2 parents 90a96e7 + 6bc4345 commit 8bdb97e
Show file tree
Hide file tree
Showing 30 changed files with 758 additions and 45 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ kaizen upload btfs ./build
- [`kaizen install`](commands/install.md) - Install a KAIZEN project from GitHub
- [`kaizen upload`](commands/upload.md) - Upload a KAIZEN project
- [`kaizen plugins`](commands/plugins.md) - Plugin management for KAIZEN
- [`kaizen instances`](commands/instances.md) - Instances management for KAIZEN
- [`kaizen contracts`](commands/contracts.md) - Contract management for KAIZEN
- [`kaizen blockchains`](commands/blockchains.md) - Blockchain management for KAIZEN

Expand Down Expand Up @@ -107,7 +108,7 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for how to help out.
*Quick Start*: Check out [help wanted](https://github.com/PortalNetwork/kaizen-cli/labels/help%20wanted) or [good first issue](https://github.com/PortalNetwork/kaizen-cli/labels/good%20first%20issue) labels to find issues we want to move forward on with your help.

## <a name="contact"></a>📧 Contact
For any questions, please contact [email protected] or join telegram: [http://bit.ly/2XjhQV2](http://bit.ly/2XjhQV2)
For any questions, please contact **[email protected]** or join telegram: [http://bit.ly/2XjhQV2](http://bit.ly/2XjhQV2)

## <a name="licence"></a>🗒 Licence
See [LICENSE](./LICENSE) for details.
3 changes: 2 additions & 1 deletion README_KR.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ kaizen upload btfs ./build
- [`kaizen install`](commands/install.md) - Install a KAIZEN project from GitHub
- [`kaizen upload`](commands/upload.md) - Upload a KAIZEN project
- [`kaizen plugins`](commands/plugins.md) - Plugin management for KAIZEN
- [`kaizen instances`](commands/instances.md) - Instances management for KAIZEN
- [`kaizen contracts`](commands/contracts.md) - Contract management for KAIZEN
- [`kaizen blockchains`](commands/blockchains.md) - Blockchain management for KAIZEN

Expand Down Expand Up @@ -107,7 +108,7 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for how to help out.
*Quick Start*: Check out [help wanted](https://github.com/PortalNetwork/kaizen-cli/labels/help%20wanted) or [good first issue](https://github.com/PortalNetwork/kaizen-cli/labels/good%20first%20issue) labels to find issues we want to move forward on with your help.

## <a name="contact"></a>📧 Contact
For any questions, please contact [email protected] or join telegram: [http://bit.ly/2XjhQV2](http://bit.ly/2XjhQV2)
For any questions, please contact **[email protected]** or join telegram: [http://bit.ly/2XjhQV2](http://bit.ly/2XjhQV2)

## <a name="licence"></a>🗒 라이센스
[LICENSE](./LICENSE) 참조하기
3 changes: 2 additions & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ kaizen upload btfs ./build
- [`kaizen install`](commands/install.md) - 從 GitHub 安裝已經存在的 KAIZEN
- [`kaizen upload`](commands/upload.md) - 上傳 KAIZEN 專案
- [`kaizen plugins`](commands/plugins.md) - KAIZEN 插件管理功能
- [`kaizen instances`](commands/instances.md) - KAIZEN 運行實例管理功能
- [`kaizen contracts`](commands/contracts.md) - KAIZEN 智能合約管理功能
- [`kaizen blockchains`](commands/blockchains.md) - KAIZEN 區塊鏈管理功能

Expand Down Expand Up @@ -107,7 +108,7 @@ KAIZEN Faucet 支援下列區塊鏈測試網路的代幣
*快速開始:您可以透過 [help wanted](https://github.com/PortalNetwork/kaizen-cli/labels/help%20wanted) 或者 [good first issue](https://github.com/PortalNetwork/kaizen-cli/labels/good%20first%20issue) 標籤找到可以參與貢獻的任務。

## <a name="contact"></a>📧 聯絡
如果您有任何問題請聯繫 [email protected] 或者加入我們的 Telegram: [http://bit.ly/2XjhQV2](http://bit.ly/2XjhQV2)
如果您有任何問題請聯繫 **[email protected]** 或者加入我們的 Telegram: [http://bit.ly/2XjhQV2](http://bit.ly/2XjhQV2)

## <a name="licence"></a>🗒 許可證
詳細內容請參考 [LICENSE](./LICENSE)
15 changes: 11 additions & 4 deletions build/components/Config/Get/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function builder(yargs) {
alias: 'k',
type: 'string',
describe: 'Configuration key',
choices: ['privateKey', 'provider', 'networkId']
}).example('kaizen config get --key provider').demandOption(['key'], '');
choices: ['privateKey', 'provider', 'networkId', 'accessKey', 'secretKey', 'region']
}).example('kaizen config get --key provider'); //.demandOption(['key'], '');
}

function handler(_x) {
Expand All @@ -43,9 +43,16 @@ function _handler() {
Spinner.stop();

if (kaizenrc[key]) {
Log.NormalLog('Configuration:\n'.underline.yellow + key + ': ' + kaizenrc[key].yellow);
Log.NormalLog('Kaizen Configuration:\n'.underline.yellow + key + ': ' + kaizenrc[key].yellow);
} else {
Log.NormalLog("Can not find ".concat(key));
//Log.NormalLog(`Can not find ${key}`);
Log.NormalLog('Kaizen Configuration:'.underline.yellow);
kaizenrc['privateKey'] ? Log.NormalLog('privateKey' + ': ' + kaizenrc['privateKey'].yellow) : null;
kaizenrc['provider'] ? Log.NormalLog('provider' + ': ' + kaizenrc['provider'].yellow) : null;
kaizenrc['networkId'] ? Log.NormalLog('networkId' + ': ' + kaizenrc['networkId'].yellow) : null;
kaizenrc['accessKey'] ? Log.NormalLog('accessKey' + ': ' + kaizenrc['accessKey'].yellow) : null;
kaizenrc['secretKey'] ? Log.NormalLog('secretKey' + ': ' + kaizenrc['secretKey'].yellow) : null;
kaizenrc['region'] ? Log.NormalLog('region' + ': ' + kaizenrc['region'].yellow) : null;
}
} catch (error) {
Spinner.stop();
Expand Down
2 changes: 1 addition & 1 deletion build/components/Config/Set/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function builder(yargs) {
alias: 'k',
type: 'string',
describe: 'Configuration key',
choices: ['privateKey', 'provider', 'networkId']
choices: ['privateKey', 'provider', 'networkId', 'accessKey', 'secretKey', 'region']
}).option('value', {
alias: 'v',
type: 'string',
Expand Down
2 changes: 1 addition & 1 deletion build/components/Config/Unset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function builder(yargs) {
alias: 'k',
type: 'string',
describe: 'Configuration key',
choices: ['privateKey', 'provider', 'networkId']
choices: ['privateKey', 'provider', 'networkId', 'accessKey', 'secretKey', 'region']
}).example('kaizen config unset --key provider').demandOption(['key'], '');
}

Expand Down
56 changes: 56 additions & 0 deletions build/components/Instances/List/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"use strict";

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var Log = require('../../../lib/Log');

var path = require('path');

var fsx = require('fs-extra');

require('colors');

function builder(yargs) {}

function handler(_x) {
return _handler.apply(this, arguments);
}

function _handler() {
_handler = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee(argv) {
var kaizenrc, i, instance;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
Log.NormalLog('AWS Instance list:'.underline.yellow);
kaizenrc = fsx.readJsonSync(path.resolve(__dirname, '../../../../.kaizenrc'));

if (kaizenrc['instances']) {
for (i = 0; i < kaizenrc['instances'].length; i++) {
instance = kaizenrc['instances'][i];
Log.NormalLog('Template: '.yellow + instance.template + ', InstanceId: '.yellow + instance.instanceId); // TODO load instance status
}
} else {
Log.NormalLog("There's no instance running on AWS");
}

case 3:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
return _handler.apply(this, arguments);
}

module.exports = function (yargs) {
var command = 'list';
var commandDescription = 'List instances of instance name';
yargs.command(command, commandDescription, builder, handler);
};
90 changes: 90 additions & 0 deletions build/components/Instances/Run/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"use strict";

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var Log = require('../../../lib/Log');

var Spinner = require('../../../lib/Spinner');

var nymLoopixMixnodeHandler = require('./nym-loopix-mixnode.js');

function builder(yargs) {
return yargs.positional('instance', {
alias: 'i',
type: 'string',
describe: 'instance name',
require: true
}).example('kaizen instances run nym-loopix-mixnode').demandOption(['instance'], '');
}

function handler(_x) {
return _handler.apply(this, arguments);
}

function _handler() {
_handler = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee(argv) {
var instance;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
instance = argv.instance;

if (instance) {
_context.next = 5;
break;
}

Log.NormalLog('Missing instance name.\nPlease using \'kaizen instances run [instance]\'');
return _context.abrupt("return");

case 5:
_context.t0 = instance;
_context.next = _context.t0 === 'nym-loopix-mixnode' ? 8 : 15;
break;

case 8:
Log.NormalLog("Starting ".concat(instance, " instance, please wait a second..."));
Spinner.start();
_context.next = 12;
return nymLoopixMixnodeHandler();

case 12:
Spinner.stop();
Log.SuccessLog("Start instance ".concat(instance, " Successfully"));
return _context.abrupt("break", 16);

case 15:
Log.NormalLog('Instance not support yet');

case 16:
_context.next = 23;
break;

case 18:
_context.prev = 18;
_context.t1 = _context["catch"](0);
Spinner.stop();
Log.ErrorLog('something went wrong!');
console.error(_context.t1);

case 23:
case "end":
return _context.stop();
}
}
}, _callee, this, [[0, 18]]);
}));
return _handler.apply(this, arguments);
}

module.exports = function (yargs) {
var command = 'run [instance]';
var commandDescription = 'Run an instance on AWS';
yargs.command(command, commandDescription, builder, handler);
};
98 changes: 98 additions & 0 deletions build/components/Instances/Run/nym-loopix-mixnode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"use strict";

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var Log = require('../../../lib/Log');

var AWSService = require('../../../lib/aws/AWSService');

var path = require('path');

var fsx = require('fs-extra');

module.exports =
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee() {
var kaizenrc, region, awsService, isExists, keyPair, instance, instances, configuration;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
kaizenrc = fsx.readJsonSync(path.resolve(__dirname, '../../../../.kaizenrc'));
region = 'us-east-1';

if (!kaizenrc['accessKey']) {
Log.NormalLog("Please set AWS access key by 'kaizen config set --key accessKey --value [Access Key Value]'");
}

if (!kaizenrc['secretKey']) {
Log.NormalLog("Please set AWS secret key by 'kaizen config set --key secretKey --value [Secret Key Value]'");
}

if (kaizenrc['region']) {
region = kaizenrc['region'];
}

awsService = new AWSService(kaizenrc['accessKey'], kaizenrc['secretKey'], region);
_context.next = 9;
return awsService.isKeyPairsExists('kaizen-cli');

case 9:
isExists = _context.sent;
keyPair = 'kaizen-cli';

if (isExists) {
_context.next = 16;
break;
}

Log.NormalLog('Creating Key Pair:\n'.underline.yellow + 'kaizen-cli.pem'.yellow);
_context.next = 15;
return awsService.createKeyPair();

case 15:
keyPair = _context.sent;

case 16:
_context.next = 18;
return awsService.runInstance('nym-loopix-mixnode');

case 18:
instance = _context.sent;
instances = [];

if (kaizenrc['instances']) {
instances = kaizenrc['instances'];
}

instances.push(instance);
configuration = _objectSpread({}, kaizenrc, {
"keyPair": keyPair,
"instances": instances
});
fsx.writeJsonSync(path.resolve(__dirname, '../../../../.kaizenrc'), configuration);
_context.next = 30;
break;

case 26:
_context.prev = 26;
_context.t0 = _context["catch"](0);
Log.ErrorLog('something went wrong!');
console.error(_context.t0);

case 30:
case "end":
return _context.stop();
}
}
}, _callee, this, [[0, 26]]);
}));
Loading

0 comments on commit 8bdb97e

Please sign in to comment.