Skip to content

Commit

Permalink
Merge 11da269 into 1edd623
Browse files Browse the repository at this point in the history
  • Loading branch information
niahmiah committed Sep 28, 2017
2 parents 1edd623 + 11da269 commit 3155438
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 238 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
node_modules
Dockerfile
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM node:8

# update apt-get
RUN apt-get update && apt-get install -y dnsutils

USER root
# Set up non root user
RUN useradd --user-group --create-home --shell /bin/false ows

# Setup environment variables
ENV NODE_ENV=production
ENV HOME_PATH=/home/ows

ENV PKG_NAME=btccore-node
ENV PKG_DIR=$HOME_PATH/$PKG_NAME

ENV APP_NAME=bitcoin-core-services
ENV APP_DIR=$HOME_PATH/$APP_NAME

ENV BITCOIN_DATA=/data

# Set up folder and add install files
RUN mkdir -p $PKG_DIR
RUN mkdir -p $BITCOIN_DATA
COPY package.json $PKG_DIR
WORKDIR $PKG_DIR

RUN chown -R ows:ows $HOME_PATH
RUN chgrp ows /usr/local/lib/node_modules
RUN chgrp ows /usr/local/bin

USER ows
RUN npm install -g owstack/btccore-node

WORKDIR $HOME_PATH
RUN $PKG_NAME create -d $BITCOIN_DATA $APP_NAME
WORKDIR $APP_DIR
RUN $PKG_NAME install https://github.com/owstack/btccore-explorer-api.git
RUN $PKG_NAME install https://github.com/owstack/btccore-wallet-service.git
USER root
CMD ["btccore-node","start"]
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.2'
services:
bitcoin-core-conf:
build: extra/compose
volumes:
- bitcoin-core-data-dir:/data
- btccore-conf-dir:/home/ows/config
bitcoin-core:
image: "owstack/bitcoin-core:0.14.1-ows"
user: root
command: "/usr/local/bin/bitcoind -datadir=/data"
ports:
- "8332:8332"
- "8333:8333"
- "18332:18332"
- "18333:18333"
- "28332:28332"
- "28333:28333"
volumes:
- bitcoin-core-data-dir:/data
depends_on:
- "bitcoin-core-conf"
ows-bitcoin-cash-node:
build: .
ports:
- "3001:3001"
depends_on:
- "bitcoin-core"
volumes:
# - bitcoin-core-data-dir:/data
- btccore-conf-dir:/home/ows/config
command: "btccore-node start -c /home/ows/config"
# command: "cat /home/ows/config/btccore-node.json"
volumes:
bitcoin-core-data-dir:
btccore-conf-dir:
13 changes: 13 additions & 0 deletions extra/compose/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM buildpack-deps:jessie
MAINTAINER Ian Patton (ian.patton@gmail.com)

ENV BITCOIN_DATA=/data
ENV CONFIG_DIR=/home/ows/config

RUN mkdir -p $BITCOIN_DATA
RUN mkdir -p $CONFIG_DIR

COPY default.bitcoin.conf $BITCOIN_DATA/bitcoin.conf
COPY default.btccore-node.json $CONFIG_DIR/btccore-node.json

CMD ["echo","installed config files"]
11 changes: 11 additions & 0 deletions extra/compose/default.bitcoin.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
server=1
txindex=1
addressindex=1
timestampindex=1
spentindex=1
zmqpubrawtx=tcp://0.0.0.0:28332
zmqpubhashblock=tcp://0.0.0.0:28332
rpcallowip=0.0.0.0/0
rpcuser=bitcoin
rpcpassword=local321
uacomment=bcccore
21 changes: 21 additions & 0 deletions extra/compose/default.btccore-node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"network": "livenet",
"port": 3001,
"services": [
"explorer-api",
"bitcoind",
"web"
],
"servicesConfig": {
"bitcoind": {
"spawn": {
"datadir": "/data",
"exec": "/usr/local/lib/node_modules/btccore-node/bin/bitcoind"
}
},
"explorer-api": {
"module": "btccore-explorer-api",
"apiPrefix": "explorer-api"
}
}
}
80 changes: 25 additions & 55 deletions lib/services/bitcoind.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var fs = require('fs');
var path = require('path');
var spawn = require('child_process').spawn;
var util = require('util');
var mkdirp = require('mkdirp');
var btccore = require('btccore-lib');
Expand Down Expand Up @@ -852,70 +851,41 @@ Bitcoin.prototype._spawnChildProcess = function(callback) {
options.push(self._getNetworkOption());
}

self._stopSpawnedBitcoin(function(err) {
if (err) {
return callback(err);
}

log.info('Starting bitcoin process');
self.spawn.process = spawn(self.spawn.exec, options, {stdio: 'inherit'});
var exitShutdown = false;

self.spawn.process.on('error', function(err) {
self.emit('error', err);
});
async.retry({times: 60, interval: self.startRetryInterval}, function(done) {
if (self.node.stopping) {
exitShutdown = true;
return done();
}

self.spawn.process.once('exit', function(code) {
if (!self.node.stopping) {
log.warn('Bitcoin process unexpectedly exited with code:', code);
log.warn('Restarting bitcoin child process in ' + self.spawnRestartTime + 'ms');
setTimeout(function() {
self._spawnChildProcess(function(err) {
if (err) {
return self.emit('error', err);
}
log.warn('Bitcoin process restarted');
});
}, self.spawnRestartTime);
}
node.client = new BitcoinRPC({
protocol: 'http',
host: '127.0.0.1',
port: self.spawn.config.rpcport,
user: self.spawn.config.rpcuser,
pass: self.spawn.config.rpcpassword,
queue: self.spawn.config.rpcqueue
});

var exitShutdown = false;

async.retry({times: 60, interval: self.startRetryInterval}, function(done) {
if (self.node.stopping) {
exitShutdown = true;
return done();
}
self._loadTipFromNode(node, done);

node.client = new BitcoinRPC({
protocol: 'http',
host: '127.0.0.1',
port: self.spawn.config.rpcport,
user: self.spawn.config.rpcuser,
pass: self.spawn.config.rpcpassword,
queue: self.spawn.config.rpcqueue
});
}, function(err) {
if (err) {
return callback(err);
}
if (exitShutdown) {
return callback(new Error('Stopping while trying to spawn bitcoind.'));
}

self._loadTipFromNode(node, done);
self._initZmqSubSocket(node, self.spawn.config.zmqpubrawtx);

}, function(err) {
self._checkReindex(node, function(err) {
if (err) {
return callback(err);
}
if (exitShutdown) {
return callback(new Error('Stopping while trying to spawn bitcoind.'));
}

self._initZmqSubSocket(node, self.spawn.config.zmqpubrawtx);

self._checkReindex(node, function(err) {
if (err) {
return callback(err);
}
self._checkSyncedAndSubscribeZmqEvents(node);
callback(null, node);
});

self._checkSyncedAndSubscribeZmqEvents(node);
callback(null, node);
});

});
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
"url": "https://github.com/owstack/btccore-node/issues"
},
"bin": {
"btccore-node": "./bin/btccore-node",
"bitcoind": "./bin/bitcoind"
"btccore-node": "./bin/btccore-node"
},
"scripts": {
"preinstall": "./scripts/download",
"verify": "./scripts/download --skip-bitcoin-download --verify-bitcoin-download",
"test": "mocha -R spec --recursive",
"regtest": "./scripts/regtest",
"jshint": "jshint --reporter=node_modules/jshint-stylish ./lib",
Expand Down
121 changes: 0 additions & 121 deletions scripts/download

This file was deleted.

Loading

0 comments on commit 3155438

Please sign in to comment.