Merge pull request #109 from hashicorp/f-examples

DigitalOcean Demo
This commit is contained in:
Ryan Uber 2015-09-24 22:22:42 -07:00
commit 779081970e
13 changed files with 319 additions and 0 deletions

2
.gitignore vendored
View File

@ -48,3 +48,5 @@ nomad_linux_amd64
nomad_darwin_amd64
TODO.md
.terraform
*.tfstate*

View File

@ -0,0 +1,5 @@
data_dir = "/opt/nomad"
log_level = "DEBUG"
enable_debug = true
bind_addr = "0.0.0.0"
disable_update_check = true

View File

@ -0,0 +1,49 @@
{
"variables": {
"bin_url": "{{ env `NOMAD_URL` }}"
},
"builders": [
{
"type": "digitalocean",
"image": "ubuntu-12-04-x64",
"region": "nyc3",
"size": "512mb",
"snapshot_name": "nomad-demo-{{timestamp}}"
}
],
"provisioners": [
{
"type": "shell",
"inline": [
"sudo apt-get -y update",
"sudo apt-get -y install unzip",
"curl -o /tmp/nomad.zip -L {{ user `bin_url` }}",
"sudo unzip -d /usr/local/bin /tmp/nomad.zip",
"mkdir -p /usr/local/etc/nomad",
"curl -s https://get.docker.com/gpg | sudo apt-key add -",
"curl -s https://get.docker.com/ | sudo sh"
]
},
{
"type": "file",
"source": "upstart.nomad",
"destination": "/etc/init/nomad.conf"
},
{
"type": "file",
"source": "default.hcl",
"destination": "/usr/local/etc/nomad/nomad.hcl"
}
],
"post-processors": [
{
"type": "atlas",
"artifact": "hashicorp/nomad-demo",
"artifact_type": "digitalocean.image"
}
],
"push": {
"name": "hashicorp/nomad-demo",
"vcs": true
}
}

View File

@ -0,0 +1,12 @@
description "Nomad by HashiCorp"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
script
CONFIG_DIR=/usr/local/etc/nomad
mkdir -p $CONFIG_DIR
exec /usr/local/bin/nomad agent -config $CONFIG_DIR >> /var/log/nomad.log 2>&1
end script

View File

@ -0,0 +1,2 @@
[statsite]
stream_cmd = cat >> /opt/statsite.out

View File

@ -0,0 +1,50 @@
{
"variables": {
"bin_url": "{{ env `STATSITE_URL` }}"
},
"builders": [
{
"type": "digitalocean",
"image": "ubuntu-12-04-x64",
"region": "nyc3",
"size": "512mb",
"snapshot_name": "nomad-demo-statsite-{{timestamp}}"
}
],
"provisioners": [
{
"type": "shell",
"inline": [
"sudo apt-get -y update",
"sudo apt-get -y install unzip build-essential scons",
"curl -o /tmp/statsite.zip -L {{ user `bin_url` }}",
"mkdir -p /tmp/statsite",
"unzip -d /tmp/statsite /tmp/statsite.zip",
"cd /tmp/statsite/* && make",
"mv /tmp/statsite/*/statsite /usr/local/bin",
"rm -rf /tmp/statsite"
]
},
{
"type": "file",
"source": "upstart.statsite",
"destination": "/etc/init/statsite.conf"
},
{
"type": "file",
"source": "default.conf",
"destination": "/usr/local/etc/statsite.conf"
}
],
"post-processors": [
{
"type": "atlas",
"artifact": "hashicorp/nomad-demo-statsite",
"artifact_type": "digitalocean.image"
}
],
"push": {
"name": "hashicorp/nomad-demo-statsite",
"vcs": true
}
}

View File

@ -0,0 +1,10 @@
description "Statsite"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
script
exec /usr/local/bin/statsite -f /usr/local/etc/statsite.conf >> /var/log/statsite.log 2>&1
end script

View File

@ -0,0 +1,6 @@
datacenter = "${datacenter}"
client {
enabled = true
servers = [${join(",", formatlist("\"%s:4647\"", servers))}]
node_class = "linux-64bit"
}

View File

@ -0,0 +1,35 @@
variable "count" {}
variable "image" {}
variable "region" {}
variable "size" { default = "1gb" }
variable "servers" {}
variable "ssh_keys" {}
resource "template_file" "client_config" {
filename = "${path.module}/client.hcl.tpl"
vars {
datacenter = "${var.region}"
servers = "${split(",", var.servers)}"
}
}
resource "digitalocean_droplet" "client" {
image = "${var.image}"
name = "nomad-client-${var.region}-${count.index}"
count = "${var.count}"
size = "${var.size}"
region = "${var.region}"
ssh_keys = ["${split(",", var.ssh_keys)}"]
provisioner "remote-exec" {
inline = <<CMD
cat > /usr/local/etc/nomad/client.hcl <<EOF
${template_file.client_config.rendered}
EOF
CMD
}
provisioner "remote-exec" {
inline = "sudo start nomad || sudo restart nomad"
}
}

View File

@ -0,0 +1,65 @@
variable "ssh_keys" {}
resource "atlas_artifact" "nomad-digitalocean" {
name = "hashicorp/nomad-demo"
type = "digitalocean.image"
version = "latest"
}
module "statsite" {
source = "./statsite"
region = "nyc3"
ssh_keys = "${var.ssh_keys}"
}
module "servers" {
source = "./server"
region = "nyc3"
image = "${atlas_artifact.nomad-digitalocean.id}"
ssh_keys = "${var.ssh_keys}"
statsite = "${module.statsite.addr}"
}
module "clients-nyc3" {
source = "./client"
region = "nyc3"
count = 500
image = "${atlas_artifact.nomad-digitalocean.id}"
servers = "${module.servers.addrs}"
ssh_keys = "${var.ssh_keys}"
}
module "clients-ams2" {
source = "./client"
region = "ams2"
count = 500
image = "${atlas_artifact.nomad-digitalocean.id}"
servers = "${module.servers.addrs}"
ssh_keys = "${var.ssh_keys}"
}
module "clients-ams3" {
source = "./client"
region = "ams3"
count = 500
image = "${atlas_artifact.nomad-digitalocean.id}"
servers = "${module.servers.addrs}"
ssh_keys = "${var.ssh_keys}"
}
module "clients-sfo1" {
source = "./client"
region = "sfo1"
count = 500
image = "${atlas_artifact.nomad-digitalocean.id}"
servers = "${module.servers.addrs}"
ssh_keys = "${var.ssh_keys}"
}
output "Nomad Servers" {
value = "${join(" ", split(",", module.servers.addrs))}"
}
output "Statsite Server" {
value = "${module.statsite.addr}"
}

View File

@ -0,0 +1,53 @@
variable "image" {}
variable "region" {}
variable "size" { default = "1gb" }
variable "ssh_keys" {}
variable "statsite" {}
resource "digitalocean_droplet" "server" {
image = "${var.image}"
name = "nomad-server-${var.region}-${count.index}"
count = 3
size = "${var.size}"
region = "${var.region}"
ssh_keys = ["${split(",", var.ssh_keys)}"]
provisioner "remote-exec" {
inline = <<CMD
cat > /usr/local/etc/nomad/server.hcl <<EOF
datacenter = "${var.region}"
server {
enabled = true
bootstrap_expect = 3
}
advertise {
rpc = "${self.ipv4_address}:4647"
serf = "${self.ipv4_address}:4648"
}
telemetry {
statsite_address = "${var.statsite}"
}
EOF
CMD
}
provisioner "remote-exec" {
inline = "sudo start nomad || sudo restart nomad"
}
}
resource "null_resource" "server_join" {
provisioner "local-exec" {
command = <<CMD
join() {
curl -X PUT ${digitalocean_droplet.server.0.ipv4_address}:4646/v1/agent/join?address=$1
}
join ${digitalocean_droplet.server.1.ipv4_address}
join ${digitalocean_droplet.server.2.ipv4_address}
CMD
}
}
output "addrs" {
value = "${join(",", digitalocean_droplet.server.*.ipv4_address)}"
}

View File

@ -0,0 +1,26 @@
variable "size" { default = "1gb" }
variable "region" {}
variable "ssh_keys" {}
resource "atlas_artifact" "statsite-digitalocean" {
name = "hashicorp/nomad-demo-statsite"
type = "digitalocean.image"
version = "latest"
}
resource "digitalocean_droplet" "statsite" {
image = "${atlas_artifact.statsite-digitalocean.id}"
name = "nomad-statsite-${var.region}-${count.index}"
count = 1
size = "${var.size}"
region = "${var.region}"
ssh_keys = ["${split(",", var.ssh_keys)}"]
provisioner "remote-exec" {
inline = "sudo start statsite || true"
}
}
output "addr" {
value = "${digitalocean_droplet.statsite.ipv4_address}:8125"
}

View File

@ -0,0 +1,4 @@
# This is a comma-separated list of SSH key ID's or fingerprints
# available in your DigitalOcean account. These keys will be granted
# SSH access to all of the deployed instances.
ssh_keys = "7b:40:be:5a:9a:90:1f:8a:b6:ec:7e:48:82:ae:73:dc"