Skip to content

Commit

Permalink
Merge pull request discoproject#582 from pooya/google
Browse files Browse the repository at this point in the history
Add scripts to automate deployment on google cloud
  • Loading branch information
pooya committed Sep 20, 2014
2 parents b52c800 + 2aff3cf commit 7f789b3
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cloud/google/README.md
@@ -0,0 +1,28 @@
Set up a Disco Cluster in Google Cloud
======================================

You can use disco in the Cloud! The scripts in this directory automate the
deployment of Disco on Google Cloud. You can simply run the setup script and
give it the number of worker nodes you want the cluster to have and everything
will be set up in a couple of minutes.

You can then go to discomaster:8989 and set the workers
to the following:

Nodes: disconode1:3
Max Workers: 1

Which means we have three nodes and each node will have 1 workers.

The stuff that you should to modify in the scripts for use in production:

1. The type of the instances. This script uses micro instances which are perfect
for testing.

2. The Erlang Cookie. Set it to something unique in the sript.

3. Add more firewall rules for your use-case.

Finally, when you are done with testing and want to discard the cluster, run the delete_all
script. You probably want to double check the console to make sure nothing is running afterwards.

30 changes: 30 additions & 0 deletions cloud/google/delete_all.sh
@@ -0,0 +1,30 @@
#!/bin/sh
# Run this script only after you are done with the cluster and want to discard
# the whole cluster. It will delete all of the traces of the cluster created by
# setup.sh

if [ $# -ne 1 ]
then
echo "Usage: ./delete_all n_slaves"
exit 1
fi
N_SLAVES=$1

ZONE=us-central1-a
NODES="discomaster "
for i in $(seq $N_SLAVES)
do
NODES=$(echo $NODES "disconode"$i)
done

echo "deleting the instances"
gcloud compute instances delete $NODES --zone $ZONE --quiet

echo "deleting the disco image"
gcloud compute images delete discoimage --quiet

echo "deleting the discoinstance disk"
gcloud compute disks delete discoinstance --zone $ZONE --quiet

echo "deleting the firewall rule"
gcloud compute firewall-rules delete http --quiet
45 changes: 45 additions & 0 deletions cloud/google/node_setup.sh
@@ -0,0 +1,45 @@
#!/bin/sh
# This is a helper script that will be used to create the disco image.

if [ $# -ne 1 ]
then
echo "Usage: ./node_setup.sh n_slaves"
exit 1
fi
N_SLAVES=$1
SECRET_COOKIE=disco_secret

# Set up ssh
ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

NODES="discomaster "
for i in $(seq $N_SLAVES)
do
NODES=$(echo $NODES "disconode"$i)
done

for node in $NODES
do
echo -n $node " ssh-rsa " >> ~/.ssh/known_hosts
ssh-keyscan discoinstance | awk '{print $3}' >> ~/.ssh/known_hosts
done

# Install dependencies
sudo apt-get update
sudo apt-get -y install erlang git make

# Set up distributed Erlang
echo $SECRET_COOKIE >> cookie
mv cookie .erlang.cookie
chmod 400 .erlang.cookie

# Install disco
git clone https://github.com/discoproject/disco
cd disco
git checkout origin/master
make
sudo make install
cd lib
sudo python setup.py install
sudo chown -R $USER /usr/var/disco
39 changes: 39 additions & 0 deletions cloud/google/setup.sh
@@ -0,0 +1,39 @@
#!/bin/sh

# This is the main script for setting up the cluster. The user should run this script
# on the local machine which is authorized to use google cloud

if [ $# -ne 1 ]
then
echo "Usage: ./setup.sh n_slaves"
exit 1
fi
N_SLAVES=$1
ZONE=us-central1-a

echo "Creating a disco instance"
gcloud compute instances create discoinstance --image debian-7 --zone $ZONE --machine-type f1-micro || exit 1

echo "Waiting for the instance to boot up..."
sleep 20

gcloud compute firewall-rules create http --description "Disco HTTP Access" --allow tcp:8989

gcloud compute copy-files node_setup.sh discoinstance: --zone $ZONE || exit 2

echo "Installing disco on the instance"
gcloud compute ssh discoinstance --zone $ZONE --command "./node_setup.sh $N_SLAVES"
gcloud compute instances delete discoinstance --quiet --zone $ZONE --keep-disks boot

echo "Creating the disco image"
gcloud compute images create discoimage --source-disk discoinstance --source-disk-zone $ZONE

echo "Creating the cluster"
NODES="discomaster "
for i in $(seq $N_SLAVES)
do
NODES=$(echo $NODES "disconode"$i)
done
gcloud compute instances create $NODES --image discoimage --zone $ZONE

gcloud compute ssh discomaster --zone $ZONE --command "disco start"

0 comments on commit 7f789b3

Please sign in to comment.