diff --git a/README.md b/README.md index c1352044..7142e0f7 100644 --- a/README.md +++ b/README.md @@ -32,12 +32,6 @@ If Node.js v0.12 isn't installed, it can be installed using "nvm", it can be don nvm install v0.12 ``` -Install node-pre-gyp to allow you to get the binaries for bindings or to build the objects from source: - -```bash -npm install node-pre-gyp -g -``` - To build Bitcoin Core and bindings development packages are needed: ```bash @@ -85,12 +79,6 @@ If Node.js v0.12 and associated commands "node", "npm" and "nvm" are not already nvm install v0.12 ``` -Install node-pre-gyp to allow you to get the binaries for bindings or to build the objects from source: - -```bash -npm install node-pre-gyp -g -``` - Clone the bitcore-node repository locally: ```bash @@ -123,8 +111,7 @@ To run tests against the bindings, as defined in `bindings.gyp` the regtest feat ```bash export BITCORENODE_ENV=test -node-pre-gyp clean -npm install +npm run build ``` If you do not already have mocha installed: @@ -142,9 +129,11 @@ mocha -R spec integration/regtest.js If any changes have been made to the bindings in the "src" directory, manually compile the Node.js bindings, as defined in `bindings.gyp`, you can run (-d for debug): ```bash -$ node-pre-gyp -d rebuild +$ node-gyp -d rebuild ``` +Note: `node-gyp` can be installed with `npm install node-gyp -g` + To be able to debug you'll need to have `gdb` and `node` compiled for debugging with gdb using `--gdb` (sometimes called node_g), and you can then run: ```bash diff --git a/RELEASE.md b/RELEASE.md index 8acb7d23..245cb203 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,30 +1,34 @@ -## Release Notes +## Release Process -Binaries for the C++ binding file (which includes libbitcoind statically linked in) are distributed with the help of node-pre-gyp. Node-pre-gyp publishes pre-built binaries to S3 for later download and installation. Source files can also be built if binaries are not desired. +Binaries for the C++ binding file (which includes libbitcoind statically linked in) are distributed for convenience. The binary binding file `bitcoind.node` is published to S3 for later download and installation. Source files can also be built if binaries are not desired. -## How to release +### How to Release -Ensure you've followed the instructions in the README.md for building the project from source. You will be using the node-pre-gyp to package and publish the project to S3. You will also need credentials for Bitpay's bitcore-node S3 bucket and be listed as an author for the bitcore-node's npm module. +Ensure you've followed the instructions in the README.md for building the project from source. You will be using the node-gyp to build buildings and a script upload the binary to S3. You will also need credentials for BitPay's bitcore-node S3 bucket and be listed as an author for the bitcore-node's npm module. -- Create a file, ".node_pre_gyprc" in your home directory +- Create a file `.bitcore-node-upload.json` in your home directory - The format of this file should be: - ```json { + "region": "us-east-1", "accessKeyId": "xxx", "secretAccessKey": "yyy" } ``` -- then run the commands to push binaries corresponding to the version in package.json to S3 and npm +To make a release, bump the version of the package.json: ```bash +git commit -a -m "Bump package version to " npm install -node-pre-gyp package publish +npm run upload npm publish ``` - - +And then update the version of the package.json for development (e.g. "0.3.2-dev"): +```bash +git commit -a -m "Bump development version to " +git push upstream master +``` diff --git a/bin/build-libbitcoind b/bin/build similarity index 97% rename from bin/build-libbitcoind rename to bin/build index 53c8b380..c2ba552e 100755 --- a/bin/build-libbitcoind +++ b/bin/build @@ -148,3 +148,16 @@ apply the current patch from "${root_dir}"/etc/bitcoin.patch? (y/N): " else echo 'Using existing static library.' fi + +# Building the Bindings + +set -e + +cd "${root_dir}" + +debug= +if test x"$1" = x'debug'; then + debug=--debug +fi + +node-gyp ${debug} rebuild diff --git a/bin/build-bindings b/bin/build-bindings deleted file mode 100755 index 7b535542..00000000 --- a/bin/build-bindings +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -set -e - -root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." -cd "${root_dir}" - -debug= -if test x"$1" = x'debug'; then - debug=--debug -fi - -node-pre-gyp ${debug} rebuild --fallback-to-build - - diff --git a/bin/get-tarball-name.js b/bin/get-tarball-name.js new file mode 100644 index 00000000..0c54e732 --- /dev/null +++ b/bin/get-tarball-name.js @@ -0,0 +1,12 @@ +'use strict'; + +var bindings = require('bindings'); +var packageRoot = bindings.getRoot(bindings.getFileName()); +var version = require(packageRoot + '/package.json').version; +var platform = process.platform; +var arch = process.arch; +var tarballName = 'libbitcoind-' + version + '-' + platform + '-' + arch + '.tgz'; + +if (require.main === module) { + process.stdout.write(tarballName); +} diff --git a/bin/install b/bin/install new file mode 100755 index 00000000..54ff97f1 --- /dev/null +++ b/bin/install @@ -0,0 +1,22 @@ +#!/bin/bash + +root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." + +cd "${root_dir}" + +tarball_name=`node bin/get-tarball-name.js` +bucket_name="bitcore-node" +binary_url="https://${bucket_name}.s3.amazonaws.com/${tarball_name}" + +echo "Downloading binary: ${binary_url}" + +wget -N $binary_url + +if test -e "${tarball_name}"; then + echo "Unpacking binary distribution" + tar -xvzf $tarball_name + exit 0; +else + echo "Prebuild binary could not be downloaded, building from source..." + ./bin/build +fi diff --git a/bin/upload.js b/bin/upload.js new file mode 100644 index 00000000..3d5a59d2 --- /dev/null +++ b/bin/upload.js @@ -0,0 +1,77 @@ +'use strict'; + +var fs = require('fs'); +var chainlib = require('chainlib'); +var log = chainlib.log; +var AWS = require('aws-sdk'); + +var config = require(process.env.HOME + '/.bitcore-node-upload.json'); + +AWS.config.region = config.region; +AWS.config.update({ + accessKeyId: config.accessKeyId, + secretAccessKey: config.secretAccessKey +}); + +var bindings = require('bindings'); +var packageRoot = bindings.getRoot(bindings.getFileName()); +var binaryPath = bindings({ + path: true, + bindings: 'bitcoind.node' +}); + +var relativeBinaryPath = binaryPath.replace(packageRoot + '/', ''); +var exec = require('child_process').exec; +var version = require(packageRoot + '/package.json').version; +var platform = process.platform; +var arch = process.arch; +var tarballName = 'libbitcoind-' + version + '-' + platform + '-' + arch + '.tgz'; +var bucketName = 'bitcore-node'; +var url = 'https://' + bucketName + '.s3.amazonaws.com/' + tarballName; + +var child = exec('tar -C ' + packageRoot + ' -cvzf ' + tarballName + ' ' + relativeBinaryPath, + function (error, stdout, stderr) { + + if (error) { + throw error; + } + + if (stdout) { + log.info('Tar:', stdout); + } + + if (stderr) { + log.error(stderr); + } + + var fileStream = fs.createReadStream(packageRoot + '/' + tarballName); + + fileStream.on('error', function(err) { + if (err) { + throw err; + } + }); + + fileStream.on('open', function() { + + var s3 = new AWS.S3(); + + var params = { + ACL: 'public-read', + Key: tarballName, + Body: fileStream, + Bucket: bucketName + }; + + s3.putObject(params, function(err, data) { + if (err) { + throw err; + } else { + log.info('Successfully uploaded to: ' + url); + } + }); + + }); + + } +); diff --git a/binding.gyp b/binding.gyp old mode 100755 new mode 100644 index 48deb620..c4f034e3 --- a/binding.gyp +++ b/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "<(module_name)", + "target_name": "libbitcoind", "include_dirs" : [ "", - "version": "0.2.0", + "version": "0.2.0-dev", "main": "./index.js", "repository": "git://github.com/bitpay/bitcore-node.git", "homepage": "https://github.com/bitpay/bitcore-node.js", @@ -27,10 +27,11 @@ } ], "scripts": { - "preinstall": "./bin/build-libbitcoind", - "install": "./bin/build-bindings", - "start": "node bin/start.js", + "install": "./bin/install", + "build": "./bin/build", "clean": "./bin/clean", + "upload": "node bin/upload.js", + "start": "node bin/start.js", "test": "NODE_ENV=test mocha --recursive", "coverage": "istanbul cover _mocha -- --recursive", "libbitcoind": "node bin/start-libbitcoind.js" @@ -40,8 +41,8 @@ "bitcoind" ], "dependencies": { - "node-pre-gyp": "0.5.x", "async": "1.3.0", + "bindings": "^1.2.1", "bitcore": "^0.12.15", "chainlib": "^0.1.1", "errno": "^0.1.2", @@ -60,13 +61,5 @@ "proxyquire": "^1.3.1", "rimraf": "^2.4.2", "sinon": "^1.15.4" - }, - "bundledDependencies": ["node-pre-gyp"], - "binary": { - "module_name" : "bitcoind", - "module_path" : "./build/{configuration}/{node_abi}-{platform}-{arch}/", - "remote_path" : "./{module_name}/v{version}/{configuration}/", - "package_name": "{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz", - "host" : "https://bitcore-node.s3-us-west-2.amazonaws.com" } }