diff --git a/.gitignore b/.gitignore index 9146643e0..6f4997561 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,5 @@ nomad_linux_amd64 nomad_darwin_amd64 TODO.md +.terraform +*.tfstate* diff --git a/demo/digitalocean/packer/nomad/default.hcl b/demo/digitalocean/packer/nomad/default.hcl new file mode 100644 index 000000000..ac3b9da83 --- /dev/null +++ b/demo/digitalocean/packer/nomad/default.hcl @@ -0,0 +1,5 @@ +data_dir = "/opt/nomad" +log_level = "DEBUG" +enable_debug = true +bind_addr = "0.0.0.0" +disable_update_check = true diff --git a/demo/digitalocean/packer/nomad/packer.json b/demo/digitalocean/packer/nomad/packer.json new file mode 100644 index 000000000..4ec078d6c --- /dev/null +++ b/demo/digitalocean/packer/nomad/packer.json @@ -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 + } +} diff --git a/demo/digitalocean/packer/nomad/upstart.nomad b/demo/digitalocean/packer/nomad/upstart.nomad new file mode 100644 index 000000000..371b5d823 --- /dev/null +++ b/demo/digitalocean/packer/nomad/upstart.nomad @@ -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 diff --git a/demo/digitalocean/packer/statsite/default.conf b/demo/digitalocean/packer/statsite/default.conf new file mode 100644 index 000000000..c463054e3 --- /dev/null +++ b/demo/digitalocean/packer/statsite/default.conf @@ -0,0 +1,2 @@ +[statsite] +stream_cmd = cat >> /opt/statsite.out diff --git a/demo/digitalocean/packer/statsite/packer.json b/demo/digitalocean/packer/statsite/packer.json new file mode 100644 index 000000000..b80702938 --- /dev/null +++ b/demo/digitalocean/packer/statsite/packer.json @@ -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 + } +} diff --git a/demo/digitalocean/packer/statsite/upstart.statsite b/demo/digitalocean/packer/statsite/upstart.statsite new file mode 100644 index 000000000..8ab0673fc --- /dev/null +++ b/demo/digitalocean/packer/statsite/upstart.statsite @@ -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 diff --git a/demo/digitalocean/terraform/client/client.hcl.tpl b/demo/digitalocean/terraform/client/client.hcl.tpl new file mode 100644 index 000000000..d9bb6c4ee --- /dev/null +++ b/demo/digitalocean/terraform/client/client.hcl.tpl @@ -0,0 +1,6 @@ +datacenter = "${datacenter}" +client { + enabled = true + servers = [${join(",", formatlist("\"%s:4647\"", servers))}] + node_class = "linux-64bit" +} diff --git a/demo/digitalocean/terraform/client/main.tf b/demo/digitalocean/terraform/client/main.tf new file mode 100644 index 000000000..f86418bc1 --- /dev/null +++ b/demo/digitalocean/terraform/client/main.tf @@ -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 = < /usr/local/etc/nomad/client.hcl < /usr/local/etc/nomad/server.hcl <