From 8a5e89ef7f2f6aca9011ef54396ce2f1ffd5b9d8 Mon Sep 17 00:00:00 2001 From: Thomas L Date: Thu, 15 Mar 2018 15:31:34 +0000 Subject: [PATCH 1/3] Updated Dockerfile to install vertcore from vertcoin-project properly instead of using run.sh (which unnecessarily clones each repository). Also includes some other changes to the image: * The vertcore user now has a fixed UID (9000). * Data is now stored in /data directory. * Insight is now installed to /app directory. * Install now uses --production flag. --- Dockerfile | 19 +++++---- run.sh | 113 ----------------------------------------------------- 2 files changed, 11 insertions(+), 121 deletions(-) delete mode 100755 run.sh diff --git a/Dockerfile b/Dockerfile index 607235a..b60aec5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,18 @@ FROM node:8-slim -MAINTAINER James Lovejoy +LABEL maintainer James Lovejoy RUN apt update && apt install -y git build-essential python - -RUN adduser vertcore +RUN adduser vertcore -u 9000 +RUN mkdir /data && chown vertcore:vertcore -R /data +RUN mkdir /app && chown vertcore:vertcore -R /app +COPY vertcore-node.json /data/vertcore-node.json USER vertcore -WORKDIR /home/vertcore -ADD run.sh /home/vertcore/run.sh -RUN /home/vertcore/run.sh clone -RUN /home/vertcore/run.sh install +# install vertcore +RUN npm config set prefix /app +RUN npm install --production -g vertcoin-project/vertcore -CMD ["/home/vertcore/vertcore/bin/vertcored"] +# run vertcore node +EXPOSE 3001 +CMD ["/app/bin/vertcored", "-c", "/data"] \ No newline at end of file diff --git a/run.sh b/run.sh deleted file mode 100755 index 6cc8065..0000000 --- a/run.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/bin/bash -# -# Simple script to perform operations against the various vertcore repos in one go and transform package.json for local development. -# -# usage: repos [] -# -# The action to run against the repositories. Possible values: -# check Shows the current status of the repo(s). [Default] -# clone Clones the repo(s). Also updates package.json dependencies to point to local folders. -# install Installs the repo(s) via 'npm install'. -# reinstall Uninstalls the repo(s), deleting node_modules and package-lock.json, and then installs them again. -# reset Performs a hard reset of the repo(s). -# test Runs test on the repo(s). -# update Fetches and pulls the latest commits for the repo(s). Also updates package.json dependencies to point to local folders. -# -# The name of the repo to run the command against, or omit to run against all. -# - -# list of repos -repos="vertcore-build vcoin vertcore-lib vertcore-message vertcore-p2p vertcore-node insight-vtc-api insight-vtc-ui vertcore" -gitcollection="Cubey2019" - -# update package.json dependencies to point to local folders -function updatepackagejson() { - for repo in $repos - do - local pattern1="\"$repo\":\\s\"[0-9a-zA-Z=^\\.\\-]\\+\"" - local pattern2="\"$repo\":\\s\"$gitcollection/$repo\"" - local replacewith="\"$repo\": \"file:../$repo\"" - sed -i -e "s#$pattern1#$replacewith#g" ./package.json - sed -i -e "s#$pattern2#$replacewith#g" ./package.json - done - echo "updated package.json dependencies" -} -# display git status -function checkrepo() { - cd $1 - git status - cd .. -} -# hard reset -function resetrepo() { - cd $1 - git reset --hard - cd .. -} -# fetch & pull changes (also update package.json) -function updaterepo() { - cd $1 - git fetch - git pull - updatepackagejson - cd .. -} -# install (or reinstall) -function installrepo() { - cd $1 - if [ "$2" == "Y" ]; then - npm uninstall - rm -rf node_modules - rm package-lock.json - fi - npm install - cd .. -} -# clone (Also update package.json) -function clonerepo() { - git clone "https://github.com/$gitcollection/$1.git" - cd $1 - if [ "$1" == "insight-vtc-api" ] || [ "$1" == "vertcore-lib" ] || [ "$1" == "vertcore-node" ] || [ "$1" == "vertcore-p2p" ]; then - git checkout vcoin - fi - updatepackagejson - cd .. -} -# run tests -function testrepo() { - cd $1 - npm test - cd .. -} - -for repo in $repos -do - if [ "$2" != "" ] && [ "$2" != $repo ]; then - continue - elif [ "$1" == "clone" ]; then - echo "cloning $repo..." - clonerepo $repo - elif [ "$1" == "test" ]; then - echo "testing $repo..." - testrepo $repo - elif [ "$1" == "reset" ]; then - echo "resetting $repo..." - resetrepo $repo - elif [ "$1" == "update" ]; then - echo "updating $repo..." - updaterepo $repo - elif [ "$1" == "install" ]; then - echo "installing $repo..." - installrepo $repo - elif [ "$1" == "reinstall" ]; then - echo "reinstalling $repo..." - installrepo $repo Y - elif [ "$1" == "check" ] || [ "$1" == "" ]; then - echo "$repo:" - checkrepo $repo - else - echo "unrecognised command: $1" - fi - echo "" -done - From b0998527468121517411f1592a42b1cdfdf4bece Mon Sep 17 00:00:00 2001 From: Thomas L Date: Thu, 15 Mar 2018 15:45:03 +0000 Subject: [PATCH 2/3] Added docker compose files for hosting the insight docker image. Included 3 variants (6 if including testnet versions of each): * docker-compose.yml * A simple standalone insight instance. * docker-compose-vcoin.yml * Runs multiple insight nodes and uses traefik to load balance. * docker-compose-vertcoind.yml * Similar to docker-compose-vcoin, but configures insight nodes to sync against a single vertcoind node to avoid repeated downloads of the blockchain. Each variant automatically creates a volume for the /data directory, and mounts the vertcore-node.json file from the current directory. --- docker-compose-testnet.yml | 20 +++++++++ docker-compose-vcoin-testnet.yml | 44 ++++++++++++++++++++ docker-compose-vcoin.yml | 44 ++++++++++++++++++++ docker-compose-vertcoind-testnet.yml | 62 ++++++++++++++++++++++++++++ docker-compose-vertcoind.yml | 62 ++++++++++++++++++++++++++++ docker-compose.yml | 20 +++++++++ vertcore-node-testnet.json | 30 ++++++++++++++ vertcore-node-vertcoind-testnet.json | 35 ++++++++++++++++ vertcore-node-vertcoind.json | 35 ++++++++++++++++ vertcore-node.json | 30 ++++++++++++++ 10 files changed, 382 insertions(+) create mode 100644 docker-compose-testnet.yml create mode 100644 docker-compose-vcoin-testnet.yml create mode 100644 docker-compose-vcoin.yml create mode 100644 docker-compose-vertcoind-testnet.yml create mode 100644 docker-compose-vertcoind.yml create mode 100644 docker-compose.yml create mode 100644 vertcore-node-testnet.json create mode 100644 vertcore-node-vertcoind-testnet.json create mode 100644 vertcore-node-vertcoind.json create mode 100644 vertcore-node.json diff --git a/docker-compose-testnet.yml b/docker-compose-testnet.yml new file mode 100644 index 0000000..2a0f23d --- /dev/null +++ b/docker-compose-testnet.yml @@ -0,0 +1,20 @@ +# docker compose file for vertcore/insight +# this variant runs a single self-contained node +# - health checking (note: may cause problems during initial sync) +# - data persisted to docker volume +# - its own vcoin instance to sync to network +# - no scaling / load balancing +version: "3.4" +services: + insight: + image: jamesl22/insight-vtc + ports: + - "3001:80" + healthcheck: + test: curl -f http://localhost:3001/insight-vtc-api/status + start_period: 300s + volumes: + - vertcore:/data + - ${PWD}/vertcore-node-testnet.json:/data/vertcore-node.json +volumes: + vertcore: \ No newline at end of file diff --git a/docker-compose-vcoin-testnet.yml b/docker-compose-vcoin-testnet.yml new file mode 100644 index 0000000..8bc6332 --- /dev/null +++ b/docker-compose-vcoin-testnet.yml @@ -0,0 +1,44 @@ +# docker compose file for vertcore/insight +# this variant runs multiple nodes that sync from self-contained vcoin nodes +# - health checking (note: may cause problems during initial sync) +# - data persisted to docker volume +# - each node runs its own vcoin instance to sync to network +# - supports scaling (default: 5 nodes) +# - load balances using traefik (sticky sessions required for socket.io) +version: "3.4" +services: + insight: + image: jamesl22/insight-vtc + deploy: + replicas: 5 + labels: + traefik.port: "3001" + traefik.frontend.rule: "PathPrefix:/;" + traefik.backend.loadbalancer.sticky: "true" + networks: + - insight + healthcheck: + test: curl -f http://localhost:3001/insight-vtc-api/status + start_period: 300s + volumes: + - vertcore:/data + - ${PWD}/vertcore-node-testnet.json:/data/vertcore-node.json + loadbalancer: + image: traefik + command: --docker --docker.swarmmode --docker.watch --web --loglevel=DEBUG + ports: + - "80:80" + - "9090:8080" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + deploy: + placement: + constraints: + - node.role == manager + networks: + - insight +networks: + insight: +volumes: + vertcore: + name: '{{.Service.Name}}.{{.Task.Slot}}' diff --git a/docker-compose-vcoin.yml b/docker-compose-vcoin.yml new file mode 100644 index 0000000..12717de --- /dev/null +++ b/docker-compose-vcoin.yml @@ -0,0 +1,44 @@ +# docker compose file for vertcore/insight +# this variant runs multiple nodes that sync from self-contained vcoin nodes +# - health checking (note: may cause problems during initial sync) +# - data persisted to docker volume +# - each node runs its own vcoin instance to sync to network +# - supports scaling (default: 5 nodes) +# - load balances using traefik (sticky sessions required for socket.io) +version: "3.4" +services: + insight: + image: jamesl22/insight-vtc + deploy: + replicas: 5 + labels: + traefik.port: "3001" + traefik.frontend.rule: "PathPrefix:/;" + traefik.backend.loadbalancer.sticky: "true" + networks: + - insight + healthcheck: + test: curl -f http://localhost:3001/insight-vtc-api/status + start_period: 300s + volumes: + - vertcore:/data + - ${PWD}/vertcore-node.json:/data/vertcore-node.json + loadbalancer: + image: traefik + command: --docker --docker.swarmmode --docker.watch --web --loglevel=DEBUG + ports: + - "80:80" + - "9090:8080" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + deploy: + placement: + constraints: + - node.role == manager + networks: + - insight +networks: + insight: +volumes: + vertcore: + name: '{{.Service.Name}}.{{.Task.Slot}}' diff --git a/docker-compose-vertcoind-testnet.yml b/docker-compose-vertcoind-testnet.yml new file mode 100644 index 0000000..833ad7d --- /dev/null +++ b/docker-compose-vertcoind-testnet.yml @@ -0,0 +1,62 @@ +# docker compose file for vertcore/insight +# this variant runs multiple nodes that sync from a shared vertcoind instance +# - health checking +# - data persisted to docker volume +# - each node connects to a shared vertcoind service to sync to network +# - supports scaling (default: 5 nodes) +# - load balances using traefik (sticky sessions required for socket.io) +version: "3.4" +services: + insight: + image: jamesl22/insight-vtc + deploy: + replicas: 5 + labels: + traefik.port: "3001" + traefik.frontend.rule: "PathPrefix:/;" + traefik.backend.loadbalancer.sticky: "true" + networks: + - insight + depends_on: + - vertcoind + healthcheck: + test: curl -f http://localhost:3001/insight-vtc-api/status + start_period: 300s + volumes: + - vertcore:/data + - ${PWD}/vertcore-node-vertcoind-testnet.json:/data/vertcore-node.json + vertcoind: + image: lukechilds/vertcoind + deploy: + placement: + constraints: + - node.role == manager + ports: + - "5888:5888" + - "5889:5889" + - "8332:8332" + volumes: + - vertcoind:/data + command: -rpcuser=middleware -rpcpassword=middleware -rpcallowip=0.0.0.0/0 -rpcbind=0.0.0.0 -rpcport=8332 --testnet + networks: + - insight + loadbalancer: + image: traefik + command: --docker --docker.swarmmode --docker.watch --web --loglevel=DEBUG + ports: + - "80:80" + - "9090:8080" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + deploy: + placement: + constraints: + - node.role == manager + networks: + - insight +networks: + insight: +volumes: + vertcore: + name: '{{.Service.Name}}.{{.Task.Slot}}' + vertcoind: diff --git a/docker-compose-vertcoind.yml b/docker-compose-vertcoind.yml new file mode 100644 index 0000000..983d62b --- /dev/null +++ b/docker-compose-vertcoind.yml @@ -0,0 +1,62 @@ +# docker compose file for vertcore/insight +# this variant runs multiple nodes that sync from a shared vertcoind instance +# - health checking +# - data persisted to docker volume +# - each node connects to a shared vertcoind service to sync to network +# - supports scaling (default: 5 nodes) +# - load balances using traefik (sticky sessions required for socket.io) +version: "3.4" +services: + insight: + image: jamesl22/insight-vtc + deploy: + replicas: 5 + labels: + traefik.port: "3001" + traefik.frontend.rule: "PathPrefix:/;" + traefik.backend.loadbalancer.sticky: "true" + networks: + - insight + depends_on: + - vertcoind + healthcheck: + test: curl -f http://localhost:3001/insight-vtc-api/status + start_period: 300s + volumes: + - vertcore:/data + - ${PWD}/vertcore-node-vertcoind.json:/data/vertcore-node.json + vertcoind: + image: lukechilds/vertcoind + deploy: + placement: + constraints: + - node.role == manager + ports: + - "5888:5888" + - "5889:5889" + - "8332:8332" + volumes: + - vertcoind:/data + command: -rpcuser=middleware -rpcpassword=middleware -rpcallowip=0.0.0.0/0 -rpcbind=0.0.0.0 -rpcport=8332 + networks: + - insight + loadbalancer: + image: traefik + command: --docker --docker.swarmmode --docker.watch --web --loglevel=DEBUG + ports: + - "80:80" + - "9090:8080" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + deploy: + placement: + constraints: + - node.role == manager + networks: + - insight +networks: + insight: +volumes: + vertcore: + name: '{{.Service.Name}}.{{.Task.Slot}}' + vertcoind: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4796c8d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +# docker compose file for vertcore/insight +# this variant runs a single self-contained node +# - health checking (note: may cause problems during initial sync) +# - data persisted to docker volume +# - its own vcoin instance to sync to network +# - no scaling / load balancing +version: "3.4" +services: + insight: + image: jamesl22/insight-vtc + ports: + - "3001:80" + healthcheck: + test: curl -f http://localhost:3001/insight-vtc-api/status + start_period: 300s + volumes: + - vertcore:/data + - ${PWD}/vertcore-node.json:/data/vertcore-node.json +volumes: + vertcore: \ No newline at end of file diff --git a/vertcore-node-testnet.json b/vertcore-node-testnet.json new file mode 100644 index 0000000..2ea0490 --- /dev/null +++ b/vertcore-node-testnet.json @@ -0,0 +1,30 @@ +{ + "version": "5.0.0-beta.44", + "network": "testnet", + "port": 3001, + "services": [ + "address", + "block", + "db", + "fee", + "header", + "mempool", + "p2p", + "timestamp", + "transaction", + "web", + "insight-vtc-api", + "insight-vtc-ui" + ], + "datadir": "/data", + "servicesConfig": { + "insight-vtc-api": { + "cwdRequirePath": "node_modules/insight-vtc-api", + "queryTimeout": 300 + }, + "insight-vtc-ui": { + "cwdRequirePath": "node_modules/insight-vtc-ui" + } + } + } + \ No newline at end of file diff --git a/vertcore-node-vertcoind-testnet.json b/vertcore-node-vertcoind-testnet.json new file mode 100644 index 0000000..7c17be7 --- /dev/null +++ b/vertcore-node-vertcoind-testnet.json @@ -0,0 +1,35 @@ +{ + "version": "5.0.0-beta.44", + "network": "testnet", + "port": 3001, + "services": [ + "address", + "block", + "db", + "fee", + "header", + "mempool", + "p2p", + "timestamp", + "transaction", + "web", + "insight-vtc-api", + "insight-vtc-ui" + ], + "datadir": "/data", + "servicesConfig": { + "insight-vtc-api": { + "cwdRequirePath": "node_modules/insight-vtc-api", + "queryTimeout": 300 + }, + "insight-vtc-ui": { + "cwdRequirePath": "node_modules/insight-vtc-ui" + }, + "p2p": { + "peers": [ + { "ip": { "v4": "vertcoind" }, "port": 5889 } + ] + } + } + } + \ No newline at end of file diff --git a/vertcore-node-vertcoind.json b/vertcore-node-vertcoind.json new file mode 100644 index 0000000..dab954d --- /dev/null +++ b/vertcore-node-vertcoind.json @@ -0,0 +1,35 @@ +{ + "version": "5.0.0-beta.44", + "network": "livenet", + "port": 3001, + "services": [ + "address", + "block", + "db", + "fee", + "header", + "mempool", + "p2p", + "timestamp", + "transaction", + "web", + "insight-vtc-api", + "insight-vtc-ui" + ], + "datadir": "/data", + "servicesConfig": { + "insight-vtc-api": { + "cwdRequirePath": "node_modules/insight-vtc-api", + "queryTimeout": 300 + }, + "insight-vtc-ui": { + "cwdRequirePath": "node_modules/insight-vtc-ui" + }, + "p2p": { + "peers": [ + { "ip": { "v4": "vertcoind" }, "port": 5889 } + ] + } + } + } + \ No newline at end of file diff --git a/vertcore-node.json b/vertcore-node.json new file mode 100644 index 0000000..e8b3d19 --- /dev/null +++ b/vertcore-node.json @@ -0,0 +1,30 @@ +{ + "version": "5.0.0-beta.44", + "network": "livenet", + "port": 3001, + "services": [ + "address", + "block", + "db", + "fee", + "header", + "mempool", + "p2p", + "timestamp", + "transaction", + "web", + "insight-vtc-api", + "insight-vtc-ui" + ], + "datadir": "/data", + "servicesConfig": { + "insight-vtc-api": { + "cwdRequirePath": "node_modules/insight-vtc-api", + "queryTimeout": 300 + }, + "insight-vtc-ui": { + "cwdRequirePath": "node_modules/insight-vtc-ui" + } + } + } + \ No newline at end of file From cd02b415a41d22cf894650db00080b18612d9aa7 Mon Sep 17 00:00:00 2001 From: Thomas L Date: Thu, 15 Mar 2018 15:57:39 +0000 Subject: [PATCH 3/3] Added README.md file. --- README.md | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..45d206d --- /dev/null +++ b/README.md @@ -0,0 +1,61 @@ +# Docker Image for Vertcoin Insight +[![Docker Pulls](https://img.shields.io/docker/pulls/jamesl22/insight-vtc.svg)](https://hub.docker.com/r/jamesl22/insight-vtc/) + +## Quickstart +You can run the image directly using the ```docker run``` command. + +The vertcore node will download the full blockchain which can take several hours, so you may want to mount the image's ```/data``` directory to a volume so that the data can be persisted when the node is restarted. + +The following commands will persist data into ```~/.vertcore``` on the host machine: + +```bash +$ docker run -v "~/.vertcore:/data" jamesl22/insight-vtc +``` + +### Configuration +The image will automatically create a default configuration file in the mounted ```/data``` directory. To make it easier to configure the node yourself you may want to directly mount the included ```vertcore-node.json``` file: +```bash +$ docker run -v "~/.vertcore:/data" -v "$(pwd)/vertcore-node.json:/data/vertcore-node.json" jamesl22/insight-vtc +``` + +If you want to run a testnet node you can mount the provided testnet configuration file instead: +```bash +$ docker run -v "~/.vertcore:/data" -v "$(pwd)/vertcore-node-testnet.json:/data/vertcore-node.json" jamesl22/insight-vtc +``` + +If you choose note to mount the ```vertcore-node.json``` file then you will have to manually edit the file from your mounted ```/data``` directory. + +## Swarm Mode +The provided ```docker-compose-*``` files can be used to run a Vertcoin Insight node in swarm mode. There are three different variants: + +| variant | compose file names | description | +|-|-|-| +| basic | ```docker-compose.yml```
```docker-compose-testnet.yml``` | A basic Insight node. | +| vcoin | ```docker-compose-vcoin.yml```
```docker-compose-vcoin-testnet.yml``` | Enables support for scaling to multiple Insight node instances, using [traefik](https://traefik.io/) as the loader balancer. | +| vertcoin | ```docker-compose-vertcoind.yml```
```docker-compose-vertcoind-testnet.yml``` | Enables support for scaling to multiple Insight node instances, using [traefik](https://traefik.io/) as the loader balancer. Also uses a shared ```vertcoind``` node to reduce the resources needed for each Insight node. | + +Select the configuration you want to use and deploy using the following commands: +```bash +$ docker swarm init +$ docker stack deploy -c docker-compose-vertcoind.yml insight +``` + +Each variant includes a ```*-testnet.yml``` file. Deploy this configuration if you want your node to run against the test network. + +## Building +This image has been published under the name ```jamesl22/insight-vtc```. You can build your own image using the ```docker build``` command: + +```bash +$ docker build -t insight-vtc . +``` + +## Known Issues +### "Network mismatch" error after switching network +When switching a running node between live and test network you may need to delete the ```chain.ldb``` directory in the mounted ```/data``` volume. You may also wish to delete ```vertcorenode.db``` to reclaim disk space. + +### Permission error writing to ```/data``` volume +When using ```docker run``` to run Insight you may need to ensure that the ```vertcore``` user has permission to write to the directory you have mounted to ```/data```. The ```vertcore``` user has a fixed UID of 9000 so you can use the following commands to prepare a suitable ```~/.vertcore``` directory: +```bash +$ mkdir ~/.vertcore +$ chown 9000 ~/.vertcore +```