From 91aab75e39e520e9578efac68f7326cd6257c440 Mon Sep 17 00:00:00 2001 From: jash Date: Sat, 6 Oct 2018 14:40:27 +0200 Subject: [PATCH] switched configuration process to yeoman generator inside a minimal docker image --- install/.dockerignore | 3 + install/Dockerfile | 28 +++-- install/bitcoind/script/configure.sh | 7 -- install/bitcoind/script/trace.sh | 15 --- install/bitcoind/templates/bitcoin.conf | 11 -- install/data/.gitkeep | 0 install/generator-cyphernode/.gitignore | 2 + .../generators/app/index.js | 113 ++++++++++++++++++ .../generators/app/templates/splash.txt | 27 +++++ install/generator-cyphernode/package.json | 29 +++++ install/insight-yo.json | 3 + install/script/cyphernodeconf.sh | 14 +-- install/script/install.sh | 35 +++--- 13 files changed, 222 insertions(+), 65 deletions(-) delete mode 100755 install/bitcoind/script/configure.sh delete mode 100644 install/bitcoind/script/trace.sh delete mode 100644 install/bitcoind/templates/bitcoin.conf create mode 100644 install/data/.gitkeep create mode 100644 install/generator-cyphernode/.gitignore create mode 100644 install/generator-cyphernode/generators/app/index.js create mode 100644 install/generator-cyphernode/generators/app/templates/splash.txt create mode 100644 install/generator-cyphernode/package.json create mode 100644 install/insight-yo.json diff --git a/install/.dockerignore b/install/.dockerignore index 3e95f18..aad322e 100644 --- a/install/.dockerignore +++ b/install/.dockerignore @@ -1,3 +1,6 @@ SatoshiPortal data script +generator-cyphernode/node_modules +generator-cyphernode/package-lock +generator-cyphernode/__tests__ diff --git a/install/Dockerfile b/install/Dockerfile index 8f5c30b..91c3685 100644 --- a/install/Dockerfile +++ b/install/Dockerfile @@ -1,13 +1,25 @@ -FROM alpine +FROM node:alpine -RUN apk add --update --no-cache \ - curl \ - dialog +RUN apk add --update bash && rm -rf /var/cache/apk/* +RUN adduser -D -h /yo yo yo +RUN chown -R yo:yo /usr/local/lib/node_modules /usr/local/bin -RUN mkdir /volume /script /data +USER yo +RUN npm install -g yo +COPY generator-cyphernode /yo +WORKDIR /yo/generator-cyphernode +RUN npm link -WORKDIR /script +USER root +RUN mkdir -p /yo/.config/insight-nodejs -ENV TRACING=1 +# prevent "do you want to send stats"-questions for temporary yo installation +COPY insight-yo.json /yo/.config/insight-nodejs/insight-yo.json +RUN chown -R yo:yo /yo/.config + +# run in user space +USER yo +WORKDIR /yo + +CMD ["yo","cyphernode"] -CMD ["./configure.sh"] diff --git a/install/bitcoind/script/configure.sh b/install/bitcoind/script/configure.sh deleted file mode 100755 index c2f9930..0000000 --- a/install/bitcoind/script/configure.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -# TODO: config entry for persistent volume of bitcoind - -dialog --colors --textbox trace.sh 40 80 - - diff --git a/install/bitcoind/script/trace.sh b/install/bitcoind/script/trace.sh deleted file mode 100644 index 34a18df..0000000 --- a/install/bitcoind/script/trace.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -trace() -{ - if [ -n "${TRACING}" ]; then - echo "[$(date +%Y-%m-%dT%H:%M:%S%z)] ${1}" > /dev/stderr - fi -} - -trace_rc() -{ - if [ -n "${TRACING}" ]; then - echo "[$(date +%Y-%m-%dT%H:%M:%S%z)] Last return code: ${1}" > /dev/stderr - fi -} diff --git a/install/bitcoind/templates/bitcoin.conf b/install/bitcoind/templates/bitcoin.conf deleted file mode 100644 index ca7e8ec..0000000 --- a/install/bitcoind/templates/bitcoin.conf +++ /dev/null @@ -1,11 +0,0 @@ -# testnet -testnet=1 - -#lnd opts -txindex=1 -zmqpubrawblock=tcp://0.0.0.0:18501 -zmqpubrawtx=tcp://0.0.0.0:18502 - -# general opts -rpcuser=%RPCUSER% -rpcpassword=%RPCPASSWORD% diff --git a/install/data/.gitkeep b/install/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/install/generator-cyphernode/.gitignore b/install/generator-cyphernode/.gitignore new file mode 100644 index 0000000..ba2a97b --- /dev/null +++ b/install/generator-cyphernode/.gitignore @@ -0,0 +1,2 @@ +node_modules +coverage diff --git a/install/generator-cyphernode/generators/app/index.js b/install/generator-cyphernode/generators/app/index.js new file mode 100644 index 0000000..1fd4e83 --- /dev/null +++ b/install/generator-cyphernode/generators/app/index.js @@ -0,0 +1,113 @@ +'use strict'; +const Generator = require('yeoman-generator'); +const chalk = require('chalk'); +const fs = require('fs'); +const wrap = require('wordwrap')(86); + +module.exports = class extends Generator { + + constructor(args, opts) { + super(args, opts); + + this.props = { + name: 'supercollider-project', + type: 'simple', + description: '' + }; + } + + /* + prompting() { + + const prompts = [ + { + type: 'confirm', + name: 'someAnswer', + message: 'Would you like to enable this option?', + default: true + } + ]; + + return this.prompt(prompts).then(props => { + // To access props later use this.props.someAnswer; + this.props = props; + }); + } + */ + +// fountainPrompting() { + prompting() { + const splash = fs.readFileSync(this.templatePath('splash.txt')); + this.log(splash.toString()); + + var prompts = [ + { + // https://github.com/SBoudrias/Inquirer.js#question + // input, confirm, list, rawlist, expand, checkbox, password, editor + type: 'checkbox', + name: 'features', + message: wrap('What features do you want to add to your cyphernode?')+'\n', + choices: [ + { + name: 'Bitcoin full node', + value: 'bitcoin' + }, + { + name: 'Lightning node', + value: 'lightning' + }, + { + name: 'Open timestamps server', + value: 'ots' + } + + ] + }, + { + when: function(answers) { + return answers.features && + answers.features.indexOf( 'bitcoin' ) != -1; + }, + type: 'confirm', + default: false, + name: 'lightning_implementation', + message: wrap('Run bitcoin node in prune mode?')+'\n', + }, + { + when: function(answers) { + return answers.features && + answers.features.indexOf( 'lightning' ) != -1; + }, + type: 'list', + name: 'lightning_implementation', + message: wrap('What lightning implementation do you want to use?')+'\n', + choices: [ + { + name: 'C-lightning', + value: 'c-lightning' + }, + { + name: 'LND', + value: 'lnd' + } + ] + } + ]; + + return this.prompt(prompts).then(props => { + this.props = Object.assign(this.props, props); + }); + } + + writing() { + /* + this.fs.copy( + this.templatePath('dummyfile.txt'), + this.destinationPath('dummyfile.txt') + ); + */ + } + + install() { + } +}; diff --git a/install/generator-cyphernode/generators/app/templates/splash.txt b/install/generator-cyphernode/generators/app/templates/splash.txt new file mode 100644 index 0000000..4250a2e --- /dev/null +++ b/install/generator-cyphernode/generators/app/templates/splash.txt @@ -0,0 +1,27 @@ +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            +                                            diff --git a/install/generator-cyphernode/package.json b/install/generator-cyphernode/package.json new file mode 100644 index 0000000..851db5e --- /dev/null +++ b/install/generator-cyphernode/package.json @@ -0,0 +1,29 @@ +{ + "name": "generator-cyphernode", + "version": "0.0.0", + "description": "", + "homepage": "", + "author": { + "name": "jash", + "email": "jash@schulterklopfer-productions.de", + "url": "" + }, + "files": [ + "generators" + ], + "main": "generators/index.js", + "keywords": [ + "cyphernode", + "yeoman-generator" + ], + "engines": { + "npm": ">= 4.0.0" + }, + "dependencies": { + "chalk": "^2.1.0", + "wordwrap": "^1.0.0", + "yeoman-generator": "^2.0.1" + }, + "repository": "git@github.com:schulterklopfer/cyphernode.git", + "license": "MIT" +} diff --git a/install/insight-yo.json b/install/insight-yo.json new file mode 100644 index 0000000..3f79169 --- /dev/null +++ b/install/insight-yo.json @@ -0,0 +1,3 @@ +{ + "optOut": true +} \ No newline at end of file diff --git a/install/script/cyphernodeconf.sh b/install/script/cyphernodeconf.sh index 99dad8b..7868522 100755 --- a/install/script/cyphernodeconf.sh +++ b/install/script/cyphernodeconf.sh @@ -8,13 +8,11 @@ # commands not needed for runtime cyphernodeconf_configure() { - PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" - DATA_PATH=$PWD/../data - SCRIPT_PATH=$PWD/../$1/script - VOLUME_PATH=/tmp - docker run -v $VOLUME_PATH:/volume \ - -v $DATA_PATH:/data \ - -v $SCRIPT_PATH:/script\ + local current_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" + local data_path=$current_path/../data + local docker_image="cyphernodeconf:latest" + + docker run -v $data_path:/data \ --log-driver=none\ - --rm -it cyphernodeconf:latest + --rm -it $docker_image } \ No newline at end of file diff --git a/install/script/install.sh b/install/script/install.sh index b7f86fe..1d4e8cb 100755 --- a/install/script/install.sh +++ b/install/script/install.sh @@ -3,22 +3,25 @@ . ./trace.sh . ./docker.sh . ./cyphernodeconf.sh +. ./config.sh + +config_file=$1 trace "Updating SatoshiPortal dockers" -git submodule update --recursive --remote +#git submodule update --recursive --remote +# +## build SatoshiPortal images +#local arch=x86_64 +#build_docker_image ../SatoshiPortal/dockers/$arch/bitcoin-core btcnode +#build_docker_image ../SatoshiPortal/dockers/$arch/LN/c-lightning clnimg +# +## build cyphernode images +#build_docker_image ../../cron_docker/ proxycronimg +#build_docker_image ../../proxy_docker/ btcproxyimg +#build_docker_image ../../pycoin_docker/ pycoinimg +# +## build setup docker image +build_docker_image ../ cyphernodeconf && clear && echo "Thinking..." -# build SatoshiPortal images -arch=x86_64 -build_docker_image ../SatoshiPortal/dockers/$arch/bitcoin-core btcnode -build_docker_image ../SatoshiPortal/dockers/$arch/LN/c-lightning clnimg - -# build cyphernode images -build_docker_image ../../cron_docker/ proxycronimg -build_docker_image ../../proxy_docker/ btcproxyimg -build_docker_image ../../pycoin_docker/ pycoinimg - -# build setup docker image -build_docker_image ../ cyphernodeconf - -# configure bitcoind -cyphernodeconf_configure bitcoind \ No newline at end of file +# configure features of cyphernode +cyphernodeconf_configure