Skip to content

Commit e0a0cb5

Browse files
committed
vagrantfile added
1 parent 25b9315 commit e0a0cb5

File tree

3 files changed

+188
-2
lines changed

3 files changed

+188
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vagrant/

README.md

+101-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,101 @@
1-
# marathon-consul-playground
2-
An easy way to experiment with marathon-consul
1+
# Playground for [marathon-consul](https://github.com/allegro/marathon-consul)
2+
3+
This repository contains a [Vagrantfile](https://www.vagrantup.com/) which makes it easy to experiment with
4+
the [marathon-consul](https://github.com/allegro/marathon-consul) project.
5+
6+
It creates a virtual machine with [mesos](http://mesos.apache.org/), [marathon](https://mesosphere.github.io/marathon/),
7+
[consul](https://www.consul.io/) and [marathon-consul](https://github.com/allegro/marathon-consul) installed.
8+
9+
## Requirements
10+
11+
* Vagrant (1.7+)
12+
* VirtualBox (4.0.x, 4.1.x, 4.2.x, 4.3.x, 5.0.x)
13+
14+
## Usage
15+
16+
Download the [Vagrantfile](https://raw.githubusercontent.com/dankraw/marathon-consul-playground/master/Vagrantfile) and run `vagrant up`.
17+
18+
When everything is up and running the services should be available at the following locations:
19+
20+
* Mesos: http://10.10.10.10:5050
21+
* Marathon: http://10.10.10.10:8080
22+
* Consul: http://10.10.10.10:8500
23+
24+
You can access the machine with `vagrant ssh` and stop it with `vagrant halt`.
25+
26+
`Marathon-consul` logs are available at `/var/log/upstart/marathon-consul.log` file.
27+
28+
### Example scenario
29+
30+
Create an application in Marathon by sending a `PUT` request to `10.10.10.10:8080` with some example data:
31+
32+
```js
33+
[{
34+
"id": "/myapp",
35+
"cmd": "python -m SimpleHTTPServer $PORT0",
36+
"instances": 1,
37+
"cpus": 0.1,
38+
"mem": 16,
39+
"disk": 0,
40+
"executor": "",
41+
"ports": [0],
42+
"healthChecks": [{
43+
"path": "/",
44+
"protocol": "HTTP",
45+
"portIndex": 0,
46+
"gracePeriodSeconds": 300,
47+
"intervalSeconds": 60,
48+
"timeoutSeconds": 20,
49+
"maxConsecutiveFailures": 3,
50+
"ignoreHttp1xx": false
51+
}],
52+
"labels": {
53+
"consul": "true"
54+
}
55+
}]
56+
```
57+
58+
Example using `curl`:
59+
```bash
60+
curl -s -X PUT -H "Content-Type: application/json" http://10.10.10.10:8080/v2/apps -d '[{"id":"/myapp","cmd":"python -m SimpleHTTPServer $PORT0","instances":1,"cpus":0.1,"mem":16,"disk":0,"executor":"","ports":[0],"healthChecks":[{"path":"/","protocol":"HTTP","portIndex":0,"gracePeriodSeconds":300,"intervalSeconds":60,"timeoutSeconds":20,"maxConsecutiveFailures":3,"ignoreHttp1xx":false}],"labels":{"consul":"true"}}]' | python -m json.tool
61+
```
62+
```js
63+
{
64+
"deploymentId": "898acddc-9279-4915-84a1-81cbb6bf4b0d",
65+
"version": "2016-01-13T13:58:58.034Z"
66+
}
67+
```
68+
69+
Now you should be able to see it in the Marathon console at http://10.10.10.10:8080/.
70+
71+
When the healthcheck goes green it will be registered as a service in Consul (http://10.10.10.10:8500/):
72+
73+
```bash
74+
curl -s 10.10.10.10:8500/v1/agent/services | python -m json.tool
75+
```
76+
```js
77+
{
78+
"consul": {
79+
"Address": "",
80+
"CreateIndex": 0,
81+
"EnableTagOverride": false,
82+
"ID": "consul",
83+
"ModifyIndex": 0,
84+
"Port": 8300,
85+
"Service": "consul",
86+
"Tags": []
87+
},
88+
"myapp.cc533052-b9f8-11e5-9fc0-080027fcad58": {
89+
"Address": "10.10.10.10",
90+
"CreateIndex": 0,
91+
"EnableTagOverride": false,
92+
"ID": "myapp.cc533052-b9f8-11e5-9fc0-080027fcad58",
93+
"ModifyIndex": 0,
94+
"Port": 31867,
95+
"Service": "myapp",
96+
"Tags": [
97+
"marathon"
98+
]
99+
}
100+
}
101+
```

Vagrantfile

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
Vagrant.configure(2) do |config|
5+
6+
config.vm.box = "ubuntu/trusty64"
7+
config.vm.network "private_network", ip: "10.10.10.10"
8+
config.vm.hostname = "marathon-consul"
9+
config.vm.provider "virtualbox" do |vb|
10+
vb.name = "marathon-consul"
11+
end
12+
config.vm.post_up_message = """
13+
14+
* Mesos: http://10.10.10.10:5050
15+
* Marathon: http://10.10.10.10:8080
16+
* Consul: http://10.10.10.10:8500
17+
18+
"""
19+
20+
config.vm.provision "shell", inline: <<-SHELL
21+
22+
curl -s https://bintray.com/user/downloadSubjectPublicKey?username=allegro | sudo apt-key add -
23+
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E56151BF
24+
25+
DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
26+
CODENAME=$(lsb_release -cs)
27+
echo "deb http://repos.mesosphere.io/${DISTRO} ${CODENAME} main" | \
28+
sudo tee /etc/apt/sources.list.d/mesosphere.list
29+
echo "deb http://dl.bintray.com/v1/content/allegro/deb /" | \
30+
sudo tee /etc/apt/sources.list.d/marathon-consul.list
31+
sudo add-apt-repository ppa:webupd8team/java
32+
sudo apt-get -y update
33+
34+
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
35+
sudo apt-get -qy install oracle-java8-set-default
36+
37+
sudo apt-get -qy install curl unzip zookeeper mesos marathon marathon-consul
38+
39+
echo "10.10.10.10" > /etc/mesos-slave/hostname
40+
mkdir -p /etc/marathon/conf
41+
echo "http_callback" > /etc/marathon/conf/event_subscriber
42+
echo "http://10.10.10.10:4000/events" > /etc/marathon/conf/http_endpoints
43+
44+
mkdir -p /usr/share/consul
45+
mkdir -p /etc/consul.d/server
46+
mkdir -p /var/consul
47+
CONSUL_VERSION=0.6.1
48+
curl -OLs https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip
49+
unzip -o consul_${CONSUL_VERSION}_linux_amd64.zip -d /usr/local/bin && rm consul_${CONSUL_VERSION}_linux_amd64.zip
50+
curl -OLs https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_web_ui.zip
51+
unzip -o consul_${CONSUL_VERSION}_web_ui.zip -d /usr/share/consul/ui && rm consul_${CONSUL_VERSION}_web_ui.zip
52+
53+
cat > /etc/consul.d/server/config.json <<EOF
54+
{
55+
"bootstrap": true,
56+
"server": true,
57+
"datacenter": "dc1",
58+
"data_dir": "/var/consul",
59+
"advertise_addr": "10.10.10.10",
60+
"client_addr": "10.10.10.10",
61+
"log_level": "INFO",
62+
"enable_syslog": true,
63+
"ui_dir": "/usr/share/consul/ui"
64+
}
65+
EOF
66+
67+
cat > /etc/init/consul.conf <<EOF
68+
description "Consul server process"
69+
70+
start on (local-filesystems and net-device-up IFACE=eth0)
71+
stop on runlevel [!12345]
72+
73+
respawn
74+
75+
exec consul agent -config-dir /etc/consul.d/server
76+
EOF
77+
78+
service zookeeper restart
79+
service mesos-slave restart
80+
service mesos-master restart
81+
service marathon restart
82+
service consul restart
83+
service marathon-consul restart
84+
85+
SHELL
86+
end

0 commit comments

Comments
 (0)