Skip to content

Commit

Permalink
Docker (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Lelicanin authored and simonovic86 committed Jul 20, 2018
1 parent 69cba8c commit d9d7fd4
Show file tree
Hide file tree
Showing 16 changed files with 430 additions and 58 deletions.
10 changes: 7 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ TRUFFLE_MNEMONIC=
RINKEBY_ACCESS_KEY=

# GENERAL SETTINGS
IMPORT_WHITELIST=127.0.0.1
IMPORT_WHITELIST=54.93.223.161,127.0.0.1


# test feature, it is not yet reliable
TRAVERSE_NAT_ENABLED=0
Expand All @@ -43,8 +44,11 @@ TRAVERSE_NAT_ENABLED=0
TEST_NETWORK_ENABLED=1

# Bootstrap node to connect
BOOTSTRAP_NODE=http://ou66zqo3r7nxmmnuvnvdoqjm662aem3nef4zsyxekdzjv3ngwue7hqyd.onion:443/#fd0fb28ecedf298f70218abf3947c81b50064d41
BOOTSTRAP_NODE=http://l7j34pimur6qllxr2uyhuujpsmx4ga4olve5em4igbjnmfokllj4bead.onion:443/#694085c1f0379dad80b917ab747ed80cd2c2ed04,http://bev4uwc77b7ag66pkwijry5hfgxmpnehiw63mhgjv4qquxedsnrxoeid.onion:443/#a3405151e3adaff757e3bef2e928143e2b3d3f97

# Is this a bootstrap node
IS_BOOTSTRAP_NODE=0

# Sent logs to OriginTrail - TestNet
# Sent logs to OriginTrail - TestNet
SEND_LOGS=1
LOGS_LEVEL_DEBUG=1
2 changes: 1 addition & 1 deletion .env.travis
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TRAVERSE_NAT_ENABLED=0
TEST_NETWORK_ENABLED=1

# Bootstrap node to connect
BOOTSTRAP_NODE=http://ou66zqo3r7nxmmnuvnvdoqjm662aem3nef4zsyxekdzjv3ngwue7hqyd.onion:443/#fd0fb28ecedf298f70218abf3947c81b50064d41
BOOTSTRAP_NODE=http://l7j34pimur6qllxr2uyhuujpsmx4ga4olve5em4igbjnmfokllj4bead.onion:443/#694085c1f0379dad80b917ab747ed80cd2c2ed04,http://bev4uwc77b7ag66pkwijry5hfgxmpnehiw63mhgjv4qquxedsnrxoeid.onion:443/#a3405151e3adaff757e3bef2e928143e2b3d3f97

# Sent logs to OriginTrail - TestNet
SEND_LOGS=1
Expand Down
23 changes: 15 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MAINTAINER OriginTrail

RUN apt-get -qq update && apt-get -qq -y install curl
RUN curl -sL https://deb.nodesource.com/setup_9.x | bash -
RUN apt-get -qq update && apt-get -qq -y install wget apt-transport-https software-properties-common build-essential git nodejs sqlite unzip
RUN apt-get -qq update && apt-get -qq -y install wget apt-transport-https software-properties-common build-essential git nodejs sqlite unzip nano
RUN add-apt-repository -y ppa:ethereum/ethereum && apt-get -qq update && apt-get install -y -qq ethereum geth
#ArangoDB
ADD testnet/install-arango.sh /install-arango.sh
Expand All @@ -17,17 +17,24 @@ RUN apt-get update && apt install -y -qq supervisor
RUN mkdir -p /var/log/supervisor
COPY testnet/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

#Clone the project
RUN wget https://codeload.github.com/OriginTrail/ot-node/zip/docker && echo " "
RUN unzip docker -d . && rm docker && mv ot-node-docker ot-node
COPY package.json /tmp/package.json
RUN cd /tmp && npm install

RUN wget https://github.com/papertrail/remote_syslog2/releases/download/v0.20/remote_syslog_linux_amd64.tar.gz

RUN tar xzf ./remote_syslog_linux_amd64.tar.gz && cd remote_syslog && cp ./remote_syslog /usr/local/bin
ADD testnet/papertrail.yml /etc/log_files.yml
#Clone the project
RUN wget https://codeload.github.com/OriginTrail/ot-node/zip/develop
RUN unzip develop -d . && rm develop && mv ot-node-develop ot-node

RUN cp -a /tmp/node_modules /ot-node

WORKDIR /ot-node
RUN mkdir keys data &> /dev/null
RUN cp .env.example .env && npm install

RUN cp .env.example .env
COPY testnet/start.sh /ot-node/testnet/start.sh
RUN chmod 400 testnet/start.sh

EXPOSE 4043 8900 3000 3010
CMD ["/usr/bin/supervisord"]
EXPOSE 5278 8900 3000 4043 3010
CMD ["sh", "/ot-node/testnet/start.sh"]
127 changes: 127 additions & 0 deletions check-updates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
const AutoUpdater = require('auto-updater');
const rimraf = require('rimraf');
const npm = require('npm-cmd');
const Utilities = require('./modules/Utilities');

const log = Utilities.getLogger();

const Umzug = require('umzug');

const Models = require('./models');

const umzug_migrations = new Umzug({

storage: 'sequelize',

storageOptions: {
sequelize: Models.sequelize,
},

migrations: {
params: [Models.sequelize.getQueryInterface(), Models.sequelize.constructor, () => {
throw new Error('Migration tried to use old style "done" callback. Please upgrade to "umzug" and return a promise instead.');
}],
path: './migrations',
pattern: /\.js$/,
},

});

class AutoUpdate {
static update() {
return new Promise(async (resolve, reject) => {
var autoupdater = new AutoUpdater({
pathToJson: '',
autoupdate: false,
checkgit: true,
jsonhost: 'raw.githubusercontent.com',
contenthost: 'codeload.github.com',
progressDebounce: 0,
devmode: false,
});

// State the events
autoupdater.on('git-clone', () => {
log.warn("You have a clone of the repository. Use 'git pull' to be up-to-date");
resolve(true);
});
autoupdater.on('check.up-to-date', (v) => {
log.info(`You have the latest version: ${v}`);
resolve(true);
});
autoupdater.on('check.out-dated', (v_old, v) => {
log.warn(`Your version is outdated. ${v_old} of ${v}`);
autoupdater.fire('download-update'); // If autoupdate: false, you'll have to do this manually.
// Maybe ask if the'd like to download the update.
});
autoupdater.on('update.downloaded', () => {
log.warn('Update downloaded and ready for install');
autoupdater.fire('extract'); // If autoupdate: false, you'll have to do this manually.
});
autoupdater.on('update.not-installed', () => {
log.warn("The Update was already in your folder! It's ready for install");
autoupdater.fire('extract'); // If autoupdate: false, you'll have to do this manually.
});
autoupdater.on('update.extracted', () => {
log.warn('Update extracted successfully!');
npm.install([], {
cwd: '/ot-node',
save: true,
}, (err) => {
if (err) {
console.log(err);
log.error('Installation failed.');
} else {
log.info('Installation succeeded!');
log.warn('RESTARTING THE APP!');
umzug_migrations.up().then((migrations) => {
log.warn('Database migrated.');
rimraf.sync('./data/*');
rimraf.sync('./keys/*');
this.restartNode();
});
}
});
});
autoupdater.on('download.start', (name) => {
log.warn(`Starting downloading: ${name}`);
});
autoupdater.on('download.progress', (name, perc) => {
process.stdout.write(`Downloading ${perc}% \x1B[0G`);
});
autoupdater.on('download.end', (name) => {
log.warn(`Downloaded ${name}`);
});
autoupdater.on('download.error', (err) => {
log.error(`Error when downloading: ${err}`);
resolve(true);
});
autoupdater.on('end', () => {
log.warn('The app is ready to function');
resolve(true);
});
autoupdater.on('error', (name, e) => {
log.error(name, e);
resolve(true);
});

// Start checking
autoupdater.fire('check');
});
}
restartNode() {
setTimeout(() => {
process.on('exit', () => {
/* eslint-disable-next-line */
require('child_process').spawn(process.argv.shift(), process.argv, {
cwd: process.cwd(),
detached: true,
stdio: 'inherit',
});
});
process.exit(0);
}, 5000);
}
}

module.exports = AutoUpdate;
5 changes: 3 additions & 2 deletions modules/RemoteControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class RemoteControl {
this.node = this.network.kademlia();
app.listen(config.remote_control_port);
await remote.on('connection', (socket) => {
this.log.important('This is Houston. Roger. Out.');
this.socket.initialize(socket);
this.getProtocolInfo().then((res) => {
socket.emit('system', { info: res });
Expand Down Expand Up @@ -295,8 +296,8 @@ class RemoteControl {
stdio: 'inherit',
});
});
process.exit(2);
}, 5000);
process.exit(1);
}, 2000);
}

/**
Expand Down
63 changes: 63 additions & 0 deletions modules/Update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const Utilities = require('./Utilities');

class Update {
/**
* Check for updates
*/
checkForUpdates(autoupdater) {
this.autoupdater = autoupdater;
this.registerEvents();
// Start checking
this.autoupdater.fire('check');
}

/**
* Register update events
*/
registerEvents() {
this.log = Utilities.getLogger();
// State the events
this.autoupdater.on('git-clone', () => {
this.log.warn("You have a clone of the repository. Use 'git pull' to be up-to-date");
});
this.autoupdater.on('check.up-to-date', (v) => {
this.log.info(`You have the latest version of OTNode: ${v}`);
});
this.autoupdater.on('check.out-dated', (v_old, v) => {
this.log.warn(`Your OTNode version is outdated. ${v_old} of ${v}`);
this.autoupdater.fire('download-update'); // If autoupdate: false, you'll have to do this manually.
// Maybe ask if the'd like to download the update.
});
this.autoupdater.on('update.downloaded', () => {
this.log.log('Update downloaded and ready for install');
this.autoupdater.fire('extract'); // If autoupdate: false, you'll have to do this manually.
});
this.autoupdater.on('update.not-installed', () => {
this.log.log("The Update was already in your folder! It's ready for install");
this.autoupdater.fire('extract'); // If autoupdate: false, you'll have to do this manually.
});
this.autoupdater.on('update.extracted', () => {
this.log.log('Update extracted successfully!');
console.warn('RESTART THE APP!');
});
this.autoupdater.on('download.start', (name) => {
this.log.log(`Starting downloading: ${name}`);
});
this.autoupdater.on('download.progress', (name, perc) => {
process.stdout.write(`Downloading ${perc}% \x1B[0G`);
});
this.autoupdater.on('download.end', (name) => {
this.log.log(`Downloaded ${name}`);
});
this.autoupdater.on('download.error', (err) => {
this.log.error(`Error when downloading: ${err}`);
});
this.autoupdater.on('end', () => {
this.log.log('The app is ready to function');
});
this.autoupdater.on('error', (name, e) => {
this.log.error(name, e);
});
}
}
module.exports = new Update();
16 changes: 16 additions & 0 deletions modules/Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ class Utilities {
}


/**
* Check if there is a new version of ot-node
* @returns {Promise<any>}
*/

static checkForUpdates() {
return new Promise(async (resolve, reject) => {
// eslint-disable-next-line
const Update = require('../check-updates');
const res = await Update.update();
if (res) {
resolve(res);
}
});
}

/**
* Returns winston logger
* @returns {*} - log function
Expand Down
53 changes: 53 additions & 0 deletions newrelic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict'
/**
* New Relic agent configuration.
*
* See lib/config/default.js in the agent distribution for a more complete
* description of configuration variables and their potential values.
*/
exports.config = {
/**
* Array of application names.
*/
app_name: ['OtNode'],
/**
* Your New Relic license key.
*/
license_key: '667969272b632a620fb549b26c4655b8f24a1991',
logging: {
/**
* Level at which to log. 'trace' is most useful to New Relic when diagnosing
* issues with the agent, 'info' and higher will impose the least overhead on
* production applications.
*/
level: 'info'
},
/**
* When true, all request headers except for those listed in attributes.exclude
* will be captured for all traces, unless otherwise specified in a destination's
* attributes include/exclude lists.
*/
allow_all_headers: true,
attributes: {
/**
* Prefix of attributes to exclude from all destinations. Allows * as wildcard
* at end.
*
* NOTE: If excluding headers, they must be in camelCase form to be filtered.
*
* @env NEW_RELIC_ATTRIBUTES_EXCLUDE
*/
exclude: [
'request.headers.cookie',
'request.headers.authorization',
'request.headers.proxyAuthorization',
'request.headers.setCookie*',
'request.headers.x*',
'response.headers.cookie',
'response.headers.authorization',
'response.headers.proxyAuthorization',
'response.headers.setCookie*',
'response.headers.x*'
]
}
}
13 changes: 12 additions & 1 deletion ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const pjson = require('./package.json');
const log = Utilities.getLogger();
const Web3 = require('web3');

global.__basedir = __dirname;

process.on('unhandledRejection', (reason, p) => {
if (reason.message.startsWith('Invalid JSON RPC response')) {
return;
Expand Down Expand Up @@ -114,6 +116,15 @@ class OTNode {
process.exit(1);
}

// check for Updates
try {
log.info('Checking for updates');
await Utilities.checkForUpdates();
} catch (err) {
console.log(err);
process.exit(1);
}

if (Utilities.isBootstrapNode()) {
await this.startBootstrapNode();
this.startRPC();
Expand Down Expand Up @@ -510,7 +521,7 @@ class OTNode {
Utilities.validateNumberParameter(req.body.total_escrow_time_in_minutes) &&
Utilities.validateStringParameter(req.body.max_token_amount_per_dh) &&
Utilities.validateStringParameter(req.body.dh_min_stake_amount) &&
Utilities.validateNumberParameter(req.body.dh_min_reputation)) {
Utilities.validateNumberParameterAllowZero(req.body.dh_min_reputation)) {
const queryObject = {
import_id: req.body.import_id,
total_escrow_time: req.body.total_escrow_time_in_minutes * 60000,
Expand Down
Loading

0 comments on commit d9d7fd4

Please sign in to comment.