Skip to content

Instantly share code, notes, and snippets.

@jaketrent
Created May 20, 2014 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaketrent/28105d44cf7f13e14f85 to your computer and use it in GitHub Desktop.
Save jaketrent/28105d44cf7f13e14f85 to your computer and use it in GitHub Desktop.
Local AWS Junk Drawer (dynamo and cloudsearch
'use strict'
const config = require('config')
const cp = require('child_process')
const path = require('path')
var http = require('http')
var fs = require('fs')
module.exports = function () {
const sh = cp.spawn('sh', [ 'bin/cmds/gen-localdb.sh' ], {
cwd: path.join(__dirname, '..', '..')
})
sh.stdout.setEncoding('utf8')
sh.stdout.on('data', function (data) {
console.log(data)
})
sh.stderr.setEncoding('utf8')
sh.stderr.on('data', function (err) {
console.log(err)
})
sh.on('close', function () {
console.log('Completed.')
})
}
echo 'Generating local db environment...'
echo "Download development.ini..."
curl -O http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_2014-01-08.tar.gz
echo "Unpacking..."
tar xvf dynamodb_local_2014-01-08.tar.gz
echo "Moving..."
mv dynamodb_local_2014-01-08 localdb
echo "Cleaning up..."
rm dynamodb_local_2014-01-08.tar.gz
'use strict'
const config = require('config')
const cp = require('child_process')
const path = require('path')
var http = require('http')
var fs = require('fs')
module.exports = function () {
const sh = cp.spawn('sh', [ 'bin/cmds/gen-localsearch.sh' ], {
cwd: path.join(__dirname, '..', '..')
})
sh.stdout.setEncoding('utf8')
sh.stdout.on('data', function (data) {
console.log(data)
})
sh.stderr.setEncoding('utf8')
sh.stderr.on('data', function (err) {
console.log(err)
})
sh.on('close', function () {
console.log('Completed.')
})
}
echo 'Generating local search environment...'
echo "Installing mongodb..."
brew install mongodb
echo "Installing python..."
brew install python
echo "Installing virtualenv..."
easy_install virtualenv
echo "Setup virtualenv nozama..."
virtualenv nozama
echo "Activate virtualenv nozama..."
source nozama/bin/activate
echo "Install nozama-cloudsearch-service..."
easy_install nozama-cloudsearch-service
echo "Download development.ini..."
curl -O https://raw.github.com/oisinmulvihill/nozama-cloudsearch/master/nozama-cloudsearch-service/development.ini
echo "Download elasticsearch..."
curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.0.tar.gz
echo "Unpacking elasticsearch..."
tar xf elasticsearch-*.tar.gz
echo "Removing tarfile..."
rm elasticsearch-*.tar.gz
echo "Renaming elasticsearch..."
mv elasticsearch-* elasticsearch
echo "Completed."
'use strict'
const cp = require('child_process')
const debug = require('debug')('localdb')
const path = require('path')
const spawn = require('./util/spawn')
const DYNAMO_LOCAL_PORT = 8000
const launch = function (databaseDir, port) {
const workingDir = path.resolve(databaseDir)
const javaDir = '.'
const libDir = path.join(javaDir, 'DynamoDBLocal_lib')
const cmd = 'java'
const args = [
'-Djava.library.path=' + libDir,
'-jar',
path.join(javaDir, 'DynamoDBLocal.jar'),
'--port',
port
]
const server = cp.spawn(cmd, args, {
cwd: workingDir,
env: process.env
})
server.stdout.setEncoding('utf8')
server.stdout.on('data', spawn.log(debug))
server.stderr.setEncoding('utf8')
server.stderr.on('data', spawn.log(debug))
server.on('close', spawn.log(debug))
}
module.exports = function () {
launch('localdb', DYNAMO_LOCAL_PORT)
console.log('Running dynamo-local on ' + DYNAMO_LOCAL_PORT + '...')
}
echo "Activate virtualenv nozama..."
source nozama/bin/activate
echo "Running nozama..."
pserve development.ini
'use strict'
const cp = require('child_process')
const path = require('path')
const spawn = require('./util/spawn')
const log = function (proc, debug) {
proc.stdout.setEncoding('utf8')
proc.stdout.on('data', spawn.log(debug))
proc.stderr.on('data', spawn.log(debug))
proc.on('close', spawn.log(debug))
}
module.exports = function () {
const mongo = cp.spawn('mongod', ['--config', '/usr/local/etc/mongod.conf'])
log(mongo, require('debug')('localsearch:mongo'))
const nozama = cp.spawn('sh', [ 'bin/cmds/localsearch-nozama.sh' ], {
cwd: path.join(__dirname, '..', '..')
})
log(nozama, require('debug')('localsearch:nozama'))
const elastic = cp.spawn('sh', [ 'elasticsearch' ], {
cwd: path.join(__dirname, '..', '..', 'elasticsearch', 'bin')
})
log(elastic, require('debug')('localsearch:elastic'))
}
const dataExists = function (data) {
return data && ('' + data).trim().length > 0
}
const lastCharIsNewline = function (data) {
return data[data.length - 1] == '\n'
}
const removeNewLine = function (data) {
if (lastCharIsNewline(data)) {
return data.substring(0, data.length - 1)
} else {
return data
}
}
const log = function (debug) {
if (!debug)
debug = require('debug')('crux')
return function (data) {
if (dataExists(data))
debug(removeNewLine(data))
}
}
exports.log = log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment