Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker: Use of alpine, pass in env vars and use pm2-runtime #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 11 additions & 54 deletions Dockerfile 100644 → 100755
@@ -1,61 +1,18 @@
## Dockerfile for eth-net-intelligence-api (build from git).
##
## Build via:
#
# `docker build -t ethnetintel:latest .`
#
## Run via:
#
# `docker run -v <path to app.json>:/home/ethnetintel/eth-net-intelligence-api/app.json ethnetintel:latest`
#
## Make sure, to mount your configured 'app.json' into the container at
## '/home/ethnetintel/eth-net-intelligence-api/app.json', e.g.
## '-v /path/to/app.json:/home/ethnetintel/eth-net-intelligence-api/app.json'
##
## Note: if you actually want to monitor a client, you'll need to make sure it can be reached from this container.
## The best way in my opinion is to start this container with all client '-p' port settings and then
# share its network with the client. This way you can redeploy the client at will and just leave 'ethnetintel' running. E.g. with
## the python client 'pyethapp':
##
#
# `docker run -d --name ethnetintel \
# -v /home/user/app.json:/home/ethnetintel/eth-net-intelligence-api/app.json \
# -p 0.0.0.0:30303:30303 \
# -p 0.0.0.0:30303:30303/udp \
# ethnetintel:latest`
#
# `docker run -d --name pyethapp \
# --net=container:ethnetintel \
# -v /path/to/data:/data \
# pyethapp:latest`
#
## If you now want to deploy a new client version, just redo the second step.
FROM node:11-alpine

RUN apk update && apk add git ca-certificates
RUN adduser -S ethnetintel

FROM debian
WORKDIR /home/ethnetintel/ethstats-client

RUN apt-get update &&\
apt-get install -y curl git-core &&\
curl -sL https://deb.nodesource.com/setup | bash - &&\
apt-get update &&\
apt-get install -y nodejs
ADD package.json .
RUN npm install && npm install -g pm2

RUN apt-get update &&\
apt-get install -y build-essential
ADD . .

RUN adduser ethnetintel

RUN cd /home/ethnetintel &&\
git clone https://github.com/cubedro/eth-net-intelligence-api &&\
cd eth-net-intelligence-api &&\
npm install &&\
npm install -g pm2

RUN echo '#!/bin/bash\nset -e\n\ncd /home/ethnetintel/eth-net-intelligence-api\n/usr/bin/pm2 start ./app.json\ntail -f \
/home/ethnetintel/.pm2/logs/node-app-out-0.log' > /home/ethnetintel/startscript.sh

RUN chmod +x /home/ethnetintel/startscript.sh &&\
chown -R ethnetintel. /home/ethnetintel
RUN chown -R ethnetintel. .

ENV NODE_ENVIRONMENT=production
USER ethnetintel
ENTRYPOINT ["/home/ethnetintel/startscript.sh"]

ENTRYPOINT ["pm2-runtime", "app.json"]
60 changes: 35 additions & 25 deletions README.md 100644 → 100755
Expand Up @@ -4,12 +4,40 @@ Ethereum Network Intelligence API

This is the backend service which runs along with ethereum and tracks the network status, fetches information through JSON-RPC and connects through WebSockets to [eth-netstats](https://github.com/cubedro/eth-netstats) to feed information. For full install instructions please read the [wiki](https://github.com/ethereum/wiki/wiki/Network-Status).


## Prerequisite
* eth, geth or pyethapp
* node
* npm

## Docker

### Configuration (Environment Variables)

To run the docker container against your client, you can pass in env variables

```
docker run \
--net host \
-e RPC_HOST=localhost \
-e RPC_PORT=8545 \
-e LISTENING_PORT=30303 \
-e INSTANCE_NAME=MyLocalMachine \
-e WS_SERVER=wss://rpc.ethstats.net
-e WS_SECRET=<secret>
-it goerli/ethstats-client
```

Alternatively, you can pass in an `--env-file` to Docker with all the above set.

### Configuration (app.json)

You can also overwrite the `app.json` file to pass in configuration, for example:

```
docker run \
-v <path to app.json>:/home/ethnetintel/ethstats-client/app.json \
-it goerli/ethstats-client
```

## Installation on an Ubuntu EC2 Instance

Expand All @@ -18,31 +46,8 @@ Fetch and run the build shell. This will install everything you need: latest eth
```bash
bash <(curl https://raw.githubusercontent.com/cubedro/eth-net-intelligence-api/master/bin/build.sh)
```
## Installation as docker container (optional)

There is a `Dockerfile` in the root directory of the repository. Please read through the header of said file for
instructions on how to build/run/setup. Configuration instructions below still apply.

## Configuration

Configure the app modifying [processes.json](/eth-net-intelligence-api/blob/master/processes.json). Note that you have to modify the backup processes.json file located in `./bin/processes.json` (to allow you to set your env vars without being rewritten when updating).

```json
"env":
{
"NODE_ENV" : "production", // tell the client we're in production environment
"RPC_HOST" : "localhost", // eth JSON-RPC host
"RPC_PORT" : "8545", // eth JSON-RPC port
"LISTENING_PORT" : "30303", // eth listening port (only used for display)
"INSTANCE_NAME" : "", // whatever you wish to name your node
"CONTACT_DETAILS" : "", // add your contact details here if you wish (email/skype)
"WS_SERVER" : "wss://rpc.ethstats.net", // path to eth-netstats WebSockets api server
"WS_SECRET" : "see http://forum.ethereum.org/discussion/2112/how-to-add-yourself-to-the-stats-dashboard-its-not-automatic", // WebSockets api server secret used for login
"VERBOSITY" : 2 // Set the verbosity (0 = silent, 1 = error, warn, 2 = error, warn, info, success, 3 = all logs)
}
```

## Run
## Run Local

Run it using pm2:

Expand All @@ -61,6 +66,11 @@ To update the API client use the following command:

It will stop the current netstats client processes, automatically detect your ethereum implementation and version, update it to the latest develop build, update netstats client and reload the processes.

## Notes

- For the WS_SECRET, see http://forum.ethereum.org/discussion/2112/how-to-add-yourself-to-the-stats-dashboard-its-not-automatic
- Ensure that your container has connectivity to your Ethereum client.

[travis-image]: https://travis-ci.org/cubedro/eth-net-intelligence-api.svg
[travis-url]: https://travis-ci.org/cubedro/eth-net-intelligence-api
[dep-image]: https://david-dm.org/cubedro/eth-net-intelligence-api.svg
Expand Down
14 changes: 1 addition & 13 deletions app.json 100644 → 100755
Expand Up @@ -7,18 +7,6 @@
"watch" : false,
"max_restarts" : 10,
"exec_interpreter" : "node",
"exec_mode" : "fork_mode",
"env":
{
"NODE_ENV" : "production",
"RPC_HOST" : "localhost",
"RPC_PORT" : "8545",
"LISTENING_PORT" : "30303",
"INSTANCE_NAME" : "",
"CONTACT_DETAILS" : "",
"WS_SERVER" : "wss://rpc.ethstats.net",
"WS_SECRET" : "see http://forum.ethereum.org/discussion/2112/how-to-add-yourself-to-the-stats-dashboard-its-not-automatic",
"VERBOSITY" : 2
}
"exec_mode" : "fork_mode"
}
]
9 changes: 4 additions & 5 deletions lib/node.js 100644 → 100755
Expand Up @@ -491,9 +491,7 @@ Node.prototype.getStats = function(forced)
},
hashrate: function (callback)
{
if (web3.eth.mining) {
web3.eth.getHashrate(callback);
}
web3.eth.getHashrate(callback);
},
gasPrice: function (callback)
{
Expand All @@ -519,16 +517,17 @@ Node.prototype.getStats = function(forced)
results.end = _.now();
results.diff = results.end - self._lastFetch;

console.sstats('==>', 'Got getStats results in', chalk.reset.cyan(results.diff, 'ms'));
console.stats('==>', 'Got getStats results in', chalk.reset.cyan(results.diff, 'ms'));

if(results.peers !== null)
{
self.stats.active = true;

self.stats.peers = results.peers;
self.stats.mining = results.mining;
self.stats.hashrate = results.hashrate;
self.stats.gasPrice = results.gasPrice.toString(10);

console.stats('==>', 'Peer count', self.stats.peers);
if(results.syncing !== false) {
var sync = results.syncing;

Expand Down
Empty file modified package.json 100644 → 100755
Empty file.