Skip to content

Commit

Permalink
Merge pull request #88 from Capgemini/15-terraform-digitalocean
Browse files Browse the repository at this point in the history
15 terraform digitalocean
  • Loading branch information
tayzlor committed Apr 23, 2015
2 parents 8dc7bf6 + 7a024f3 commit ef56889
Show file tree
Hide file tree
Showing 34 changed files with 836 additions and 45 deletions.
20 changes: 9 additions & 11 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,26 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box_version = conf['mesos_version']

ansible_groups = {
"mesos-masters" => ["master1", "master2", "master3"],
"mesos-slaves" => ["slave1"],
"all:children" => ["mesos-masters", "mesos-slaves"]
"mesos_masters" => ["master1", "master2", "master3"],
"mesos_slaves" => ["slave1"],
"all:children" => ["mesos_masters", "mesos_slaves"],
"zookeeper_servers:children" => ["mesos_masters"],
"consul_servers:children" => ["mesos_masters"],
"weave_servers:children" => ["mesos_slaves"],
}

# Mesos master nodes
master_n = conf['master_n']
master_infos = (1..master_n).map do |i|
node = {
:zookeeper_id => i,
:quorum => (master_n.to_f/2).ceil,
:hostname => "master#{i}",
:ip => conf['master_ipbase'] + "#{10+i}",
:mem => conf['master_mem'],
:cpus => conf['master_cpus'],
}
end
zookeeper_url = "zk://"+master_infos.map{|master| master[:ip]+":2181"}.join(",")
mesos_zk_url = "zk://"+master_infos.map{|master| master[:ip]+":2181"}.join(",")+"/mesos"
zookeeper_conf = master_infos.map{|master| "server.#{master[:zookeeper_id]}"+"="+master[:ip]+":2888:3888"}.join("\n")
consul_join = master_infos.map{|master| master[:ip]}.join(" ")

Expand Down Expand Up @@ -67,11 +69,9 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
ansible.extra_vars = {
zookeeper_id: node[:zookeeper_id],
zookeeper_conf: zookeeper_conf,
zookeeper_url: zookeeper_url,
mesos_quorum: node[:quorum],
mesos_zk_url: mesos_zk_url,
consul_join: consul_join,
consul_advertise: node[:ip],
consul_bootstrap_expect: master_n,
mesos_local_address: node[:ip],
consul_bind_addr: node[:ip]
}
Expand All @@ -95,12 +95,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
ansible.playbook = "site.yml"
ansible.sudo = true
ansible.extra_vars = {
zookeeper_url: zookeeper_url,
mesos_quorum: node[:quorum],
mesos_zk_url: mesos_zk_url,
consul_join: consul_join,
consul_advertise: node[:ip],
consul_is_server: false,
consul_bootstrap_expect: master_n,
mesos_local_address: node[:ip],
consul_bind_addr: node[:ip]
}
Expand Down
4 changes: 4 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[defaults]
ssh_args = -o ControlMaster=auto -o ControlPersist=30m
host_key_checking = no
record_host_keys = no
2 changes: 1 addition & 1 deletion bootstrap/aws/config-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ AWS_ACCESS_KEY=${AWS_ACCESS_KEY:?"Need to set AWS_ACCESS_KEY non-empty"}
AWS_SSH_KEY=${AWS_SSH_KEY:-$HOME/.ssh/apollo_aws_rsa}
AWS_SSH_KEY_NAME=${AWS_SSH_KEY_NAME:-apollo}
ATLAS_TOKEN=${ATLAS_TOKEN:?"Need to set ATLAS_TOKEN non-empty"}
ATLAS_INFRASTRUCTURE=${ATLAS_INFRASTRUCTURE-:capgemini/infrastructure}
ATLAS_INFRASTRUCTURE=${ATLAS_INFRASTRUCTURE:-capgemini/infrastructure}
ZONE=${APOLLO_AWS_ZONE:-eu-west-1b}
MASTER_SIZE=${MASTER_SIZE:-m1.medium}
SLAVE_SIZE=${SLAVE_SIZE:-m1.medium}
Expand Down
16 changes: 16 additions & 0 deletions bootstrap/digitalocean/config-default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

DIGITALOCEAN_REGION=${DIGITALOCEAN_REGION:-lon1}
DIGITALOCEAN_SSH_KEY=${DIGITALOCEAN_SSH_KEY:?"Need to set DIGITALOCEAN_SSH_KEY non-empty"}
DIGITALOCEAN_SSH_FINGERPRINT=${DIGITALOCEAN_SSH_FINGERPRINT:?"Need to set DIGITALOCEAN_SSH_FINGERPRINT non-empty"}
DIGITALOCEAN_API_TOKEN=${DIGITALOCEAN_API_TOKEN:?"Need to set DIGITALOCEAN_API_TOKEN non-empty"}
DO_CLIENT_ID=${DO_CLIENT_ID:?"Need to set DO_CLIENT_ID non-empty"}
DO_API_KEY=${DO_API_KEY:?"Need to set DO_API_KEY non-empty"}

ATLAS_TOKEN=${ATLAS_TOKEN:?"Need to set ATLAS_TOKEN non-empty"}
ATLAS_INFRASTRUCTURE=${ATLAS_INFRASTRUCTURE:-capgemini/infrastructure}
MASTER_SIZE=${MASTER_SIZE:-512mb}
SLAVE_SIZE=${SLAVE_SIZE:-512mb}
NUM_SLAVES=${NUM_SLAVES:-1}
MASTER_IMAGE=${MASTER_IMAGE:-11147507}
SLAVE_IMAGE=${SLAVE_IMAGE:-11147507}
60 changes: 60 additions & 0 deletions bootstrap/digitalocean/util.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# Use the config file specified in $APOLLO_CONFIG_FILE, or default to
# config-default.sh.
APOLLO_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${APOLLO_ROOT}/bootstrap/digitalocean/${APOLLO_CONFIG_FILE-"config-default.sh"}"

verify_prereqs() {
if [[ "$(which terraform)" == "" ]]; then
echo -e "${color_red}Can't find terraform in PATH, please fix and retry.${color_norm}"
exit 1
fi
if [[ "$(which ansible-playbook)" == "" ]]; then
echo -e "${color_red}Can't find ansible-playbook in PATH, please fix and retry.${color_norm}"
exit 1
fi
}

apollo_launch() {
terraform_apply
ansible_playbook_run
open_urls
}

ansible_playbook_run() {
pushd $APOLLO_ROOT
DO_CLIENT_ID=$DO_CLIENT_ID DO_API_KEY=$DO_API_KEY ansible-playbook --user=root --inventory-file=$APOLLO_ROOT/inventory/digitalocean --extra-vars "consul_atlas_infrastructure=${ATLAS_INFRASTRUCTURE} consul_atlas_join=true consul_atlas_token=${ATLAS_TOKEN}" site.yml
popd
}

apollo_down() {
pushd $APOLLO_ROOT/terraform/digitalocean
terraform destroy -var "do_token=${DIGITALOCEAN_API_TOKEN}" \
-var "key_file=${DIGITALOCEAN_SSH_KEY}" \
-var "ssh_fingerprint=${DIGITALOCEAN_SSH_FINGERPRINT}" \
-var "region=${DIGITALOCEAN_REGION}"
popd
}

terraform_apply() {
pushd $APOLLO_ROOT/terraform/digitalocean
terraform apply -var "do_token=${DIGITALOCEAN_API_TOKEN}" \
-var "key_file=${DIGITALOCEAN_SSH_KEY}" \
-var "ssh_fingerprint=${DIGITALOCEAN_SSH_FINGERPRINT}" \
-var "instance_size.master=${MASTER_SIZE}" \
-var "instance_size.slave=${SLAVE_SIZE}" \
-var "image.master=${MASTER_IMAGE}" \
-var "image.slave=${SLAVE_IMAGE}" \
-var "slaves=${NUM_SLAVES}" \
-var "region=${DIGITALOCEAN_REGION}"
popd
}

open_urls() {
pushd $APOLLO_ROOT/terraform/digitalocean
/usr/bin/open "http://$(terraform output master.1.ip):5050"
/usr/bin/open "http://$(terraform output master.1.ip):8080"
/usr/bin/open "http://$(terraform output master.1.ip):8500"
popd
}
Loading

0 comments on commit ef56889

Please sign in to comment.