This node.js script allows you upload an application to multiple DigitalOcean droplets and then load-balance between them using nginx. This way your application can handle more requests at the same time.
You need to have SSH keys added to your DigitalOcean accounts.
You only have to change the do_token
, ssh_keys
, key
fields to make the demo work!
This script will cause charges to your DigitalOcean account. If you spin up 100 droplets using this script, it's your fault!
All fields are required. Load-balancing has to work using nginx, otherwise you are free to use any technology you'd like.
var clusterDeploy = require('do-cluster-deploy');
var fs = require('fs');
clusterDeploy.deploy({
prefix: 'test',
region: 'fra1',
do_token: '9801xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
size: '512mb',
private_networking: true,
ssh_keys: ['3b:03:7d:abxxxxxxxxxxxxxxxxxxx'],
image: 'ubuntu-14-04-x64',
instances: 2,
commands: [
'hash git || sudo apt-get install git --yes',
'hash nodejs || curl -sL https://deb.nodesource.com/setup | sudo bash -',
'hash nodejs || sudo apt-get install nodejs --yes',
'rm -rf node-hello-world',
'git clone git://github.com/JonnyBurger/node-hello-world.git',
'npm install forever -g',
'killall node && killall nodejs',
'forever start node-hello-world/index.js'
],
master_before: [
'hash nginx || sudo apt-get install nginx --yes'
],
master_after: [
'sudo service nginx restart'
],
nginx: [
'server {',
' listen 80;',
' location / {',
' proxy_pass http://cluster;',
' }',
'}'
].join('\n'),
port: 5000,
key: fs.readFileSync('/Users/jonnyburger/.ssh/id_rsa')
})