diff --git a/.gitignore b/.gitignore index efe72ace6d6..61b58ad4491 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,6 @@ bower_components report .DS_Store +build -bitcore.js -bitcore.min.js -bitcore.js.sig -bitcore.min.js.sig tests.js diff --git a/.travis.yml b/.travis.yml index 867d38cb144..b9ddf237673 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,19 @@ -language: node_js sudo: false +language: node_js +env: + - CXX=g++-4.8 CC=gcc-4.8 +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 + - gcc-4.8 + - libzmq3-dev node_js: -- '0.12' -before_install: - - npm install -g bower - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - '0.12' + - '4' install: - - bower install - npm install -after_script: - - gulp coveralls +script: + - npm run test diff --git a/README.md b/README.md index 3ffc158ad58..7b406c3bd31 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Infrastructure to build Bitcoin and blockchain-based applications for the next g ## Getting Started -Before you begin you'll need to have Node.js v0.12 installed. There are several options for installation. One method is to use [nvm](https://github.com/creationix/nvm) to easily switch between different versions, or download directly from [Node.js](https://nodejs.org/). +Before you begin you'll need to have Node.js v4 or v0.12 installed. There are several options for installation. One method is to use [nvm](https://github.com/creationix/nvm) to easily switch between different versions, or download directly from [Node.js](https://nodejs.org/). ```bash npm install -g bitcore @@ -79,6 +79,7 @@ You can also use our pre-generated files, provided for each release along with a To verify signatures, use the following PGP keys: - @braydonf: https://pgp.mit.edu/pks/lookup?op=get&search=0x9BBF07CAC07A276D +- @kleetus: https://pgp.mit.edu/pks/lookup?op=get&search=0x33195D27EF6BDB7F - @pnagurny: https://pgp.mit.edu/pks/lookup?op=get&search=0x0909B33F0AA53013 ## License diff --git a/package.json b/package.json index bf49b3d051c..4a9544c3916 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { "name": "bitcore", - "version": "3.0.0", + "version": "4.0.0", "description": "A platform to build bitcoin and blockchain-based applications.", "author": "BitPay ", "main": "index.js", "scripts": { - "test": "./node_modules/.bin/mocha test/** --recursive" + "test": "./node_modules/.bin/mocha test/** --recursive", + "build-deb": "./scripts/build-deb" }, "bin": { "bitcore": "./bin/bitcore", @@ -81,10 +82,10 @@ "request": "browser-request" }, "dependencies": { - "bitcore-lib": "^0.13.12", - "bitcore-node": "^2.0.0", - "insight-api": "^0.3.2", - "insight-ui": "^0.3.0" + "bitcore-lib": "^0.13.14", + "bitcore-node": "~3.0.0", + "insight-api": "^0.4.0", + "insight-ui": "^0.4.0" }, "license": "MIT", "devDependencies": { diff --git a/scripts/build-deb b/scripts/build-deb new file mode 100755 index 00000000000..83f4f723c08 --- /dev/null +++ b/scripts/build-deb @@ -0,0 +1,97 @@ +#!/bin/bash +set -e +set -o pipefail + +log_title() { + local code="\033[" + local color="${code}1;34m" + [ -z "$text" ] && local text="$color$1${code}0m" + echo -e "\n$text" +} + +root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." + +package_arch="amd64" +package_version=$(jq -r ".version" "${root_dir}/package.json") +package_maintainer=$(jq -r ".author" "${root_dir}/package.json") +package_description=$(jq -r ".description" "${root_dir}/package.json") + +deb_dir="${root_dir}/build/bitcore_${package_version}_${package_arch}" + +log_title "Making Debian package:\n" +echo -e " Name: bitcore" +echo -e " Version: ${package_version}" +echo -e " Maintainer: ${package_maintainer}" +echo -e " Description: ${package_description}" +echo -e "" + +if [ -e "$deb_dir" ]; then rm -rf "$deb_dir"; fi + +escape() { + sed -e 's/[]\/$*.^|[]/\\&/g' -e 's/&/\\&/g' <<< "$@" +} + +replace_vars() { + declare -r file="$1" + declare -r target_file="$2" + + sed < "$file" \ + -e "s/{{ deb_package_version }}/$(escape $package_version)/g" \ + -e "s/{{ deb_package_description }}/$(escape $package_description)/g" \ + -e "s/{{ deb_package_maintainer }}/$(escape $package_maintainer)/g" \ + -e "s/{{ deb_package_arch }}/$(escape $package_arch)/g" \ + > "$target_file" +} + +log_title "Setting up Debian package:" +mkdir -vp "$deb_dir/DEBIAN" \ + "$deb_dir/etc/bitcore" \ + "$deb_dir/usr/opt/bitcore" \ + "$deb_dir/usr/opt/bitcore/bin" \ + "$deb_dir/usr/bin" + +mkdir -vp "$deb_dir/etc/init" +mkdir -vp "$deb_dir/etc/systemd/system" +replace_vars "${root_dir}/scripts/debian/control" "$deb_dir/DEBIAN/control" +replace_vars "${root_dir}/scripts/debian/postinst" "$deb_dir/DEBIAN/postinst" +replace_vars "${root_dir}/scripts/debian/prerm" "$deb_dir/DEBIAN/prerm" +replace_vars "${root_dir}/scripts/debian/bitcore.conf" "$deb_dir/etc/init/bitcore.conf" +replace_vars "${root_dir}/scripts/debian/bitcore.service" "$deb_dir/etc/systemd/system/bitcore.service" +replace_vars "${root_dir}/scripts/debian/bitcore-bitcoind.conf" "$deb_dir/etc/init/bitcore-bitcoind.conf" +replace_vars "${root_dir}/scripts/debian/bitcore-bitcoind.service" "$deb_dir/etc/systemd/system/bitcore-bitcoind.service" +chmod -vR 0755 "$deb_dir/DEBIAN/" + +log_title "Copying Bitcore" + +app_dir="$deb_dir/usr/opt/bitcore" + +cp -v "${root_dir}/bin/bitcored" "${app_dir}/bin/bitcored" +cp -v "${root_dir}/bin/bitcore" "${app_dir}/bin/bitcore" +chmod -vR 0755 "${app_dir}/bin/bitcore" "${app_dir}/bin/bitcored" +cp -v "${root_dir}/package.json" "${app_dir}" +cp -v "${root_dir}/README.md" "${app_dir}" +cp -v "${root_dir}/index.js" "${app_dir}" +pushd "${deb_dir}/usr/bin" +ln -vs "../opt/bitcore/bin/bitcore" +ln -vs "../opt/bitcore/bin/bitcored" +ln -vs "../opt/bitcore/node_modules/.bin/bitcoind" "bitcore-bitcoind" +popd + +log_title "Installing Bitcore Modules" +pushd "${app_dir}" +VERIFY_BITCOIN_DOWNLOAD=1 npm install --production +echo "Cleanup Node.js addon binaries before packaging:" +find "${app_dir}" -type f -name '*.node' -print -delete +find "${app_dir}" -type f -name '*.o' -print -delete +echo "Cleanup intermediate files:" +rm -v "${deb_dir}/usr/opt/bitcore/node_modules/bitcore-node/bin/bitcoin-0.12.0-linux64.tar.gz" +npm shrinkwrap --dev +popd + +log_title "Building Debian package" +dpkg-deb -Z gzip --verbose --build "$deb_dir" + +log_title "Signing Debian package" +dpkg-sig --sign builder "${deb_dir}.deb" + +echo -e "Success.\n" diff --git a/scripts/debian/bitcore-bitcoind.conf b/scripts/debian/bitcore-bitcoind.conf new file mode 100644 index 00000000000..b07bccb5451 --- /dev/null +++ b/scripts/debian/bitcore-bitcoind.conf @@ -0,0 +1,24 @@ +description "Bitcoin Core for Bitcore" +author "BitPay, Inc." + +limit nofile 20000 30000 + +start on runlevel [2345] +stop on runlevel [016] + +kill timeout 300 +kill signal SIGINT + +# user/group for bitcore daemon to run as +setuid bitcore +setgid bitcore + +# home dir of the bitcore daemon user +env HOME=/home/bitcore + +respawn +respawn limit 5 15 + +script + exec bitcore-bitcored -datadir=/home/bitcore/.bitcore/data/ +end script diff --git a/scripts/debian/bitcore-bitcoind.service b/scripts/debian/bitcore-bitcoind.service new file mode 100644 index 00000000000..8c1ab19578e --- /dev/null +++ b/scripts/debian/bitcore-bitcoind.service @@ -0,0 +1,20 @@ +[Unit] +Description=Bitcoin Core for Bitcore +Requires=network.target + +[Service] +Type=simple +WorkingDirectory=/usr/opt/bitcore +ExecStart=/usr/bin/bitcore-bitcoind -datadir=/home/bitcore/.bitcore/data/ +ExecReload=/bin/kill -HUP $MAINPID +Restart=on-failure +RestartSec=15 +User=bitcore +ExecStartPre=/bin/mkdir -p /run/bitcore +ExecStartPre=/bin/chown bitcore:bitcore /run/bitcore +ExecStartPre=/bin/chmod 755 /run/bitcore +PermissionsStartOnly=true +TimeoutStopSec=300 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/etc/init/bitcored.conf b/scripts/debian/bitcore.conf similarity index 65% rename from etc/init/bitcored.conf rename to scripts/debian/bitcore.conf index 99adce836b6..a534786683e 100644 --- a/etc/init/bitcored.conf +++ b/scripts/debian/bitcore.conf @@ -1,5 +1,3 @@ -# Bitcored Upstart script - description "Bitcore Daemon" author "BitPay, Inc." @@ -18,9 +16,6 @@ setgid bitcore # home dir of the bitcore daemon user env HOME=/home/bitcore -# path should include the correct version of node -env PATH=/home/bitcore/.nvm/versions/node/v0.12.7/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - respawn respawn limit 5 15 diff --git a/scripts/debian/bitcore.service b/scripts/debian/bitcore.service new file mode 100644 index 00000000000..dc83ed6c2a0 --- /dev/null +++ b/scripts/debian/bitcore.service @@ -0,0 +1,20 @@ +[Unit] +Description={{ deb_package_description }} +Requires=network.target + +[Service] +Type=simple +WorkingDirectory=/usr/opt/bitcore +ExecStart=/usr/opt/bitcore/bin/bitcored +ExecReload=/bin/kill -HUP $MAINPID +Restart=on-failure +RestartSec=15 +User=bitcore +ExecStartPre=/bin/mkdir -p /run/bitcore +ExecStartPre=/bin/chown bitcore:bitcore /run/bitcore +ExecStartPre=/bin/chmod 755 /run/bitcore +PermissionsStartOnly=true +TimeoutStopSec=300 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/scripts/debian/control b/scripts/debian/control new file mode 100644 index 00000000000..8ad682591da --- /dev/null +++ b/scripts/debian/control @@ -0,0 +1,8 @@ +Package: bitcore +Version: {{ deb_package_version }} +Section: base +Priority: optional +Architecture: {{ deb_package_arch }} +Depends: nodejs, nodejs-legacy, npm, build-essential, libzmq3-dev +Maintainer: {{ deb_package_maintainer }} +Description: {{ deb_package_description }} diff --git a/scripts/debian/postinst b/scripts/debian/postinst new file mode 100644 index 00000000000..63ec2eb4f96 --- /dev/null +++ b/scripts/debian/postinst @@ -0,0 +1,37 @@ +#!/bin/bash +set -e +set -o pipefail + +# add group +if ! getent group | grep -q "^bitcore:" ; then + echo "Creating system group: bitcore" + groupadd --system bitcore +fi + +# add user +if ! getent passwd | grep -q "^bitcore:"; then + echo "Creating bitcore system user" + useradd --gid "bitcore" --system -m bitcore +fi + +# build nodejs addons +cd "/usr/opt/bitcore" +SKIP_BITCOIN_DOWNLOAD=1 npm rebuild + +# setup data directory +mkdir -p "/home/bitcore/.bitcore/data" +chown -R bitcore:bitcore "/home/bitcore/.bitcore" + +# start bitcore +if hash service 2> /dev/null; then + service bitcore start || echo "bitcore could not be registered or started" +elif hash start 2> /dev/null; then + start bitcore || echo "bitcore could not be registered or started" +elif hash systemctl 2> /dev/null; then + { + systemctl enable "bitcore.service" && \ + systemctl start "bitcore.service" + } || echo "bitcore could not be registered or started" +else + echo 'Your system does not appear to use upstart or systemd, so bitcore could not be started' +fi diff --git a/scripts/debian/prerm b/scripts/debian/prerm new file mode 100644 index 00000000000..23bbee6cd8d --- /dev/null +++ b/scripts/debian/prerm @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e +set -o pipefail + +if hash service 2> /dev/null; then + service bitcore stop || echo "bitcore wasn't running!" +elif hash stop 2> /dev/null; then + stop "$service_name" || echo "bitcore wasn't running!" +elif hash systemctl 2> /dev/null; then + systemctl disable "bitcore.service" || echo "bitcore wasn't running!" +else + echo "Your system does not appear to use upstart or systemd, so bitcore could not be stopped" +fi