Skip to content

Commit

Permalink
Fixes #77
Browse files Browse the repository at this point in the history
  • Loading branch information
vfarcic committed Dec 18, 2016
1 parent 4dedb30 commit e9273bb
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 46 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
RUN mkdir -p /cfg/tmpl
RUN mkdir /consul_templates
RUN mkdir /templates
RUN mkdir -p /certs
RUN mkdir /certs

ENV CONSUL_ADDRESS="" \
DEBUG="false" \
Expand All @@ -30,6 +30,7 @@ EXPOSE 8080

CMD ["docker-flow-proxy", "server"]

COPY errorfiles /errorfiles
COPY haproxy.cfg /cfg/haproxy.cfg
COPY haproxy.tmpl /cfg/tmpl/haproxy.tmpl
COPY docker-flow-proxy /usr/local/bin/docker-flow-proxy
Expand Down
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ Docker Flow: Proxy
* [The Swarm Mode (Docker 1.12+) with manual configuration](articles/swarm-mode.md)
* [The Default Mode](articles/standard-mode.md)

* [Containers Definition](#containers-definition)
* [Container Config](#container-config)

* [Environment Variables](#environment-variables)
* [Custom Config](#custom-config)
* [Custom Errors](#custom-errors)

* [Usage](#usage)

* [Reconfigure](#reconfigure)
Expand All @@ -18,24 +23,21 @@ Docker Flow: Proxy

* [Feedback and Contribution](#feedback-and-contribution)

Introduction
------------
## Introduction

The goal of the *Docker Flow: Proxy* project is to provide an easy way to reconfigure proxy every time a new service is deployed, or when a service is scaled. It does not try to "reinvent the wheel", but to leverage the existing leaders and combine them through an easy to use integration. It uses [HAProxy](http://www.haproxy.org/) as a proxy and adds custom logic that allows on-demand reconfiguration.

Modes
-----
## Modes

Since the Docker 1.12 release, *Docker Flow: Proxy* supports two modes. The default mode is designed to work with any setup and requires Consul and Registrator. The **swarm** mode aims to leverage the benefits that come with *Docker Swarm* and new networking introduced in the 1.12 release. The later mode (*swarm*) does not have any dependency but Docker Engine. The *swarm* mode is recommended for all who use *Docker Swarm* features introduced in v1.12.

### [The Swarm Mode (Docker 1.12+) with automatic configuration](articles/swarm-mode-listener.md)
### [The Swarm Mode (Docker 1.12+) with manual configuration](articles/swarm-mode.md)
### [The Default Mode](articles/standard-mode.md)
### [The Swarm Mode (Docker 1.12+) with automatic configuration](articles/swarm-mode-listener.md)
### [The Swarm Mode (Docker 1.12+) with manual configuration](articles/swarm-mode.md)
### [The Default Mode](articles/standard-mode.md)

Usage
-----
## Container Config

### Container Config
### Environment Variables

> The *Docker Flow: Proxy* container can be configured through environment variables
Expand All @@ -58,14 +60,21 @@ The following environment variables can be used to configure the *Docker Flow: P
|TIMEOUT_HTTP_KEEP_ALIVE|The HTTP keep alive timeout in seconds | |15 |10 |
|USERS |A comma-separated list of credentials(<user>:<pass>) for HTTP basic auth, which applies to all the backend routes.|||user1:pass1,user2:pass2|

### Custom Config

The base HAProxy configuration can be found in [haproxy.tmpl](haproxy.tmpl). It can be customized by creating a new container. An example *Dockerfile* is as follows.
The base HAProxy configuration can be found in [haproxy.tmpl](haproxy.tmpl). It can be customized by creating a new image. An example *Dockerfile* is as follows.

```
FROM vfarcic/docker-flow-proxy
COPY haproxy.tmpl /cfg/tmpl/haproxy.tmpl
```

### Custom Errors

Default error messages are stored in the `/errorfiles` directory inside the *Docker Flow: Proxy* image. They can be customized by creating a new image with custom error files or mounting a volume. Currently supported errors are `400`, `403`, `405`, `408`, `429`, `500`, `502`, `503`, and `504`.

## Usage

### Reconfigure

> Reconfigures the proxy using information stored in Consul
Expand Down
21 changes: 0 additions & 21 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@
# TODO

## Logging

[ ] Implement
[ ] Add integration tests
[ ] Test manually
[ ] Write an article
[ ] Update README
[ ] Create a release

## Template

[ ] Implement
[ ] Add integration tests
[ ] Test manually
[ ] Write an article
[ ] Update README
[ ] Create a release

## Videos

[ ] Wilde: https://www.youtube.com/watch?v=oP0_H_UkkGA
2 changes: 2 additions & 0 deletions articles/contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ docker-compose -f docker-compose-test.yml run --rm unit
### Staging (Integration) Tests

```bash
docker build -t vfarcic/docker-flow-proxy .

docker-compose -f docker-compose-test.yml up -d staging-dep

docker-compose -f docker-compose-test.yml run --rm staging
Expand Down
12 changes: 12 additions & 0 deletions errorfiles/400.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
HTTP/1.0 400 Bad Request
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html>
<body>
<h3>Docker Flow: Proxy</h3>
<h1>400 Bad Request</h1>
No server is available to handle this request.
</body>
</html>
12 changes: 12 additions & 0 deletions errorfiles/403.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
HTTP/1.0 403 Forbidden
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html>
<body>
<h3>Docker Flow: Proxy</h3>
<h1>403 Forbidden</h1>
No server is available to handle this request.
</body>
</html>
12 changes: 12 additions & 0 deletions errorfiles/405.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
HTTP/1.0 405 Method Not Allowed
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html>
<body>
<h3>Docker Flow: Proxy</h3>
<h1>405 Method Not Allowed</h1>
No server is available to handle this request.
</body>
</html>
12 changes: 12 additions & 0 deletions errorfiles/408.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
HTTP/1.0 408 Request Timeout
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html>
<body>
<h3>Docker Flow: Proxy</h3>
<h1>408 Request Timeout</h1>
No server is available to handle this request.
</body>
</html>
12 changes: 12 additions & 0 deletions errorfiles/429.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
HTTP/1.0 429 Too Many Requests
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html>
<body>
<h3>Docker Flow: Proxy</h3>
<h1>429 Too Many Requests</h1>
No server is available to handle this request.
</body>
</html>
12 changes: 12 additions & 0 deletions errorfiles/500.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
HTTP/1.0 500 Internal Server Error
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html>
<body>
<h3>Docker Flow: Proxy</h3>
<h1>500 Internal Server Error</h1>
No server is available to handle this request.
</body>
</html>
12 changes: 12 additions & 0 deletions errorfiles/502.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
HTTP/1.0 502 Bad Gateway
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html>
<body>
<h3>Docker Flow: Proxy</h3>
<h1>502 Bad Gateway</h1>
No server is available to handle this request.
</body>
</html>
12 changes: 12 additions & 0 deletions errorfiles/503.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
HTTP/1.0 503 Service Unavailable
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html>
<body>
<h3>Docker Flow: Proxy</h3>
<h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body>
</html>
12 changes: 12 additions & 0 deletions errorfiles/504.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
HTTP/1.0 504 Gateway Timeout
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html>
<body>
<h3>Docker Flow: Proxy</h3>
<h1>504 Gateway Timeout</h1>
No server is available to handle this request.
</body>
</html>
12 changes: 11 additions & 1 deletion haproxy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ global
defaults
mode http
balance roundrobin
{{.ExtraDefaults}}
{{.ExtraDefaults}}
option http-server-close
option forwardfor
option redispatch

errorfile 400 /errorfiles/400.http
errorfile 403 /errorfiles/403.http
errorfile 405 /errorfiles/405.http
errorfile 408 /errorfiles/408.http
errorfile 429 /errorfiles/429.http
errorfile 500 /errorfiles/500.http
errorfile 502 /errorfiles/502.http
errorfile 503 /errorfiles/503.http
errorfile 504 /errorfiles/504.http

maxconn 5000
timeout connect {{.TimeoutConnect}}s
timeout client {{.TimeoutClient}}s
Expand Down
11 changes: 0 additions & 11 deletions integration_tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func (s IntegrationTestSuite) Test_Reconfigure_ReqRep() {

s.NoError(err)
s.Equal(200, resp.StatusCode)
s.printConf()
}

func (s IntegrationTestSuite) Test_Stats_Auth() {
Expand Down Expand Up @@ -257,16 +256,6 @@ func (s IntegrationTestSuite) Test_Certs() {

s.Equal(200, resp.StatusCode)

// // HTTPS works
// url = fmt.Sprintf("https://%s:8080/v2/test", os.Getenv("DOCKER_IP"))
// req, _ = http.NewRequest("GET", url, nil)
// client = &http.Client{}
//
// resp, err := client.Do(req)
//
// s.NoError(err)
// s.Equal(200, resp.StatusCode)

// Can retrieve certs
url = fmt.Sprintf("http://%s:8080/v1/docker-flow-proxy/certs", os.Getenv("DOCKER_IP"))
req, _ = http.NewRequest("GET", url, nil)
Expand Down
10 changes: 10 additions & 0 deletions proxy/ha_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ defaults
option forwardfor
option redispatch
errorfile 400 /errorfiles/400.http
errorfile 403 /errorfiles/403.http
errorfile 405 /errorfiles/405.http
errorfile 408 /errorfiles/408.http
errorfile 429 /errorfiles/429.http
errorfile 500 /errorfiles/500.http
errorfile 502 /errorfiles/502.http
errorfile 503 /errorfiles/503.http
errorfile 504 /errorfiles/504.http
maxconn 5000
timeout connect 5s
timeout client 20s
Expand Down
10 changes: 10 additions & 0 deletions proxy/test_configs/tmpl/haproxy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ defaults
option forwardfor
option redispatch

errorfile 400 /errorfiles/400.http
errorfile 403 /errorfiles/403.http
errorfile 405 /errorfiles/405.http
errorfile 408 /errorfiles/408.http
errorfile 429 /errorfiles/429.http
errorfile 500 /errorfiles/500.http
errorfile 502 /errorfiles/502.http
errorfile 503 /errorfiles/503.http
errorfile 504 /errorfiles/504.http

maxconn 5000
timeout connect {{.TimeoutConnect}}s
timeout client {{.TimeoutClient}}s
Expand Down

0 comments on commit e9273bb

Please sign in to comment.