Skip to content

Commit

Permalink
add getting started to readme and examples [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
gondor committed Sep 24, 2016
1 parent c2a1437 commit f0164df
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 4 deletions.
45 changes: 41 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Is a Mesos/Marathon stream listener which manages an NGINX proxy instance within

This is a similar solution to `marathon-lb` but for the HTTP layer offering NGINX's advance http level uri routing.

## Overview
### Overview

![Architecture](images/architecture.jpg?raw=true "Architecture")

Expand All @@ -23,11 +23,48 @@ After the template has been parsed a temp Nginx configuration file is rendered w
* Listens to the realtime SSE from Marathon to quickly change upstreams based on application/tasks state changes
* RESTful endpoints for current status
* Flexible configuration options (local config, spring-cloud configuration remote configuration fetching and ENV variables)
* Easy to get started add a `FROM containx/beethoven` to your `Dockerfile` add your template, config options and release!
* Easy to get started add a `FROM containx/beethoven` to your `Dockerfile` add your template, config options and deploy!

## Getting Started
### Getting Started

TODO DOC
Below we will cover the barebones setup to get going.

#### Create a Template

Create a file called `nginx.template`. Refer to the `nginx.template` found in the [examples/](https://github.com/ContainX/beethoven/tree/master/examples) directory in this repo. Modify the example to suit your own needs

**A couple notes about the example template:**
- The `{{#if}}` blocks are optional. I prefer these so if an application is removed all together in the cluster then the final `nginx.conf` is valid
- The `/_health` endpoint at the bottom is optional. If allows for Marathon health checks to use that to determine Nginx is running.
- The `/_bt` endpoint at the bottom is optional. If you would like to find information such as updated times and any failures from Beethoven then this mapping allows you to expose these internal endpoints via Nginx. Alternatively you can expose Beethoven via it's configured port.

### Create the Beethoven Configuration File

Create a file that ends in `.json`. In this example we'll call it `btconf.json`. Refer to the `btconf.json` found in the [examples/](https://github.com/ContainX/beethoven/tree/master/examples) directory in this repo.

Add/Modify any options to suit your needs. For a description and all possible configuration options refer to the docs found within the [config.go](https://github.com/ContainX/beethoven/blob/master/config/config.go) file.

### Create a Dockerfile

Next we will create the `Dockerfile` to package up the `nginx.template` and `btconf.json` files. If you used the filenames in this guide then simply copy the code below into your `Dockerfile`.

```
FROM containx/beethoven
ADD nginx.template /etc/nginx/nginx.template
ADD btconf.json /etc/btconf.json
```

### Build and Testing your Container

Build and Run your Container

```
docker build -t myloadbalancer .
docker run -p 80:80 -d myloadbalancer -c /etc/btconf.json
```

Now open your browser and test paths you created at http://localhost

## License

Expand Down
9 changes: 9 additions & 0 deletions examples/btconf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"marthon_urls": [ "http://marathon-host-1:8080"],
"username": "",
"password": "",
"filter_regex": "",
"port": 7777,
"template": "/etc/nginx/nginx.template",
"nginx_config": "/etc/nginx/nginx.conf"
}
60 changes: 60 additions & 0 deletions examples/nginx.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /dev/stdout main;
sendfile on;
keepalive_timeout 65;

## Dynamic App Upstreams ##

{{#if my-app}}
upstream my-app {
{{#each apps-homes-search.Tasks}}
server {{this.Host}}:{{this.Ports[0]}};
{{/each}}
}
{{/if}}

server {
listen 80;

## Dynamic App Routes ##

{{#if my-app}}
location /my/path {
proxy_pass http://my-app;
}

location /my/path2 {
proxy_pass http://my-app;
}
{{/if}}

# optional: health endpoint for Marathon
location /_health {
access_log off;
return 200 'A-OK!';
add_header Content-Type text/plain;
}

# optional: expose RESTful API for Beethoven
location /_bt {
proxy_pass http://127.0.0.1:7777/;
}
}
}

0 comments on commit f0164df

Please sign in to comment.