Skip to content

Instantly share code, notes, and snippets.

@skarlekar
Last active June 7, 2018 18:12
Show Gist options
  • Save skarlekar/d1c48d1211b6b673fd7a0e5ff37b18b4 to your computer and use it in GitHub Desktop.
Save skarlekar/d1c48d1211b6b673fd7a0e5ff37b18b4 to your computer and use it in GitHub Desktop.
Hyperledger Composer Utilities
PID=`lsof -i :3000 | cut -c 8-13 | grep -v "PID" | head -n 1 | tr -d '[:space:]'`
[ -z "$PID" ] && echo "Composer REST Server not running on port 3000" || echo "Killing $PID"
[ -z "$PID" ] && echo "Nothing to kill!" || kill $PID
// Usage: node start-bna.js
// Run this in the directory where package.json is located. Make sure ./dist directory is available.
'use strict';
const {
execSync
} = require('child_process');
const fs = require('fs');
let rawdata = fs.readFileSync('package.json');
let jsondata = JSON.parse(rawdata);
let version = jsondata.version;
console.log('Current Version: '+version);
console.log('');
let cmd2 = 'cd dist; composer network install -a smartquora-bna@' + version + '.bna -c PeerAdmin@hlfv1' ;
console.log('Running ' + cmd2);
execSync(cmd2, {stdio: 'inherit'});
console.log('');
let cmd3 = 'cd dist; composer network start -A admin -S adminpw -c PeerAdmin@hlfv1 -n smartquora-bna -V ' + version ;
console.log('Running ' + cmd3);
execSync(cmd3, {stdio: 'inherit'});
console.log('');
let cmd31 = 'cd dist; composer card delete -c admin@smartquora-bna';
console.log('Running ' + cmd31);
execSync(cmd31, {stdio: 'inherit'});
console.log('');
let cmd32 = 'cd dist; composer card import -f ./admin@smartquora-bna.card';
console.log('Running ' + cmd32);
execSync(cmd32, {stdio: 'inherit'});
console.log('');
let cmd4 = 'cd dist; composer network ping -c admin@smartquora-bna';
console.log('Running ' + cmd4);
execSync(cmd4, {stdio: 'inherit'});
console.log('');
let cmd5 = 'cd dist; docker ps';
console.log('Running ' + cmd5);
execSync(cmd5, {stdio: 'inherit'});
console.log('');
console.log('Exiting');
export COMPOSER_CARD=admin@your-bna
export COMPOSER_NAMESPACES=always
export COMPOSER_AUTHENTICATION=true
export COMPOSER_TLS=true
export COMPOSER_WEBSOCKETS=true
export COMPOSER_MULTIUSER=true
export COMPOSER_PROVIDERS='{
"google": {
"provider": "google",
"module": "passport-google-oauth2",
"clientID": "your-client-id",
"clientSecret": "your-client-secret",
"authPath": "/auth/google",
"callbackURL": "/auth/google/callback",
"scope": "https://www.googleapis.com/auth/plus.login",
"successRedirect": "http://your-host:8081/index.html",
"failureRedirect": "/"
}
}'
export COMPOSER_DATASOURCES='{
"db": {
"name": "db",
"connector": "mongodb",
"host": "yourhost.mlab.com",
"port": "yourport",
"database": "quora-auth",
"user": "test",
"password": "test123"
}
}'
nohup composer-rest-server &
composer-rest-server -c admin@grants-bna -n always -w true -t true &
// Usage: node start-bna.js
// Run this in the directory where package.json is located. Make sure ./dist directory is available.
'use strict';
const {
execSync
} = require('child_process');
// Usage: node upgrade.js package.json
const fs = require('fs');
let rawdata = fs.readFileSync('package.json');
let jsondata = JSON.parse(rawdata);
let version = jsondata.version;
let desc = jsondata.description;
var arr = version.split(".");
let next = Number(arr[2]) + 1;
let nextVersion = "0.0." + next;
let newDesc = desc.replace(version, nextVersion);
console.log('Current Version: '+version);
console.log('Current Description: '+desc);
console.log('Next Version: ' +nextVersion);
console.log('New Description: '+newDesc);
jsondata.version = nextVersion;
jsondata.description = newDesc;
version = nextVersion;
fs.writeFileSync('new-package.json', JSON.stringify(jsondata,null,2));
fs.renameSync('new-package.json', 'package.json');
console.log('');
let cmd1 = 'cd dist; composer archive create -t dir -n ../';
console.log('Running ' + cmd1);
execSync(cmd1, {stdio: 'inherit'});
console.log('');
let cmd2 = 'cd dist; composer network install -a smartquora-bna@' + version + '.bna -c PeerAdmin@hlfv1' ;
console.log('Running ' + cmd2);
execSync(cmd2, {stdio: 'inherit'});
console.log('');
let cmd3 = 'cd dist; composer network upgrade -c PeerAdmin@hlfv1 -n smartquora-bna -V ' + version ;
console.log('Running ' + cmd3);
execSync(cmd3, {stdio: 'inherit'});
console.log('');
let cmd4 = 'cd dist; composer network ping -c admin@smartquora-bna';
console.log('Running ' + cmd4);
execSync(cmd4, {stdio: 'inherit'});
console.log('');
console.log('Exiting');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment