Skip to content

Commit e9273bb

Browse files
committed
Fixes #77
1 parent 4dedb30 commit e9273bb

File tree

17 files changed

+164
-46
lines changed

17 files changed

+164
-46
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
1212
RUN mkdir -p /cfg/tmpl
1313
RUN mkdir /consul_templates
1414
RUN mkdir /templates
15-
RUN mkdir -p /certs
15+
RUN mkdir /certs
1616

1717
ENV CONSUL_ADDRESS="" \
1818
DEBUG="false" \
@@ -30,6 +30,7 @@ EXPOSE 8080
3030

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

33+
COPY errorfiles /errorfiles
3334
COPY haproxy.cfg /cfg/haproxy.cfg
3435
COPY haproxy.tmpl /cfg/tmpl/haproxy.tmpl
3536
COPY docker-flow-proxy /usr/local/bin/docker-flow-proxy

README.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ Docker Flow: Proxy
88
* [The Swarm Mode (Docker 1.12+) with manual configuration](articles/swarm-mode.md)
99
* [The Default Mode](articles/standard-mode.md)
1010

11-
* [Containers Definition](#containers-definition)
11+
* [Container Config](#container-config)
12+
13+
* [Environment Variables](#environment-variables)
14+
* [Custom Config](#custom-config)
15+
* [Custom Errors](#custom-errors)
16+
1217
* [Usage](#usage)
1318

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

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

21-
Introduction
22-
------------
26+
## Introduction
2327

2428
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.
2529

26-
Modes
27-
-----
30+
## Modes
2831

2932
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.
3033

31-
### [The Swarm Mode (Docker 1.12+) with automatic configuration](articles/swarm-mode-listener.md)
32-
### [The Swarm Mode (Docker 1.12+) with manual configuration](articles/swarm-mode.md)
33-
### [The Default Mode](articles/standard-mode.md)
34+
### [The Swarm Mode (Docker 1.12+) with automatic configuration](articles/swarm-mode-listener.md)
35+
### [The Swarm Mode (Docker 1.12+) with manual configuration](articles/swarm-mode.md)
36+
### [The Default Mode](articles/standard-mode.md)
3437

35-
Usage
36-
-----
38+
## Container Config
3739

38-
### Container Config
40+
### Environment Variables
3941

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

63+
### Custom Config
6164

62-
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.
65+
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.
6366

6467
```
6568
FROM vfarcic/docker-flow-proxy
6669
COPY haproxy.tmpl /cfg/tmpl/haproxy.tmpl
6770
```
6871

72+
### Custom Errors
73+
74+
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`.
75+
76+
## Usage
77+
6978
### Reconfigure
7079

7180
> Reconfigures the proxy using information stored in Consul

TODO.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,2 @@
11
# TODO
22

3-
## Logging
4-
5-
[ ] Implement
6-
[ ] Add integration tests
7-
[ ] Test manually
8-
[ ] Write an article
9-
[ ] Update README
10-
[ ] Create a release
11-
12-
## Template
13-
14-
[ ] Implement
15-
[ ] Add integration tests
16-
[ ] Test manually
17-
[ ] Write an article
18-
[ ] Update README
19-
[ ] Create a release
20-
21-
## Videos
22-
23-
[ ] Wilde: https://www.youtube.com/watch?v=oP0_H_UkkGA

articles/contribute.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ docker-compose -f docker-compose-test.yml run --rm unit
3939
### Staging (Integration) Tests
4040

4141
```bash
42+
docker build -t vfarcic/docker-flow-proxy .
43+
4244
docker-compose -f docker-compose-test.yml up -d staging-dep
4345

4446
docker-compose -f docker-compose-test.yml run --rm staging

errorfiles/400.http

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
HTTP/1.0 400 Bad Request
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html>
7+
<body>
8+
<h3>Docker Flow: Proxy</h3>
9+
<h1>400 Bad Request</h1>
10+
No server is available to handle this request.
11+
</body>
12+
</html>

errorfiles/403.http

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
HTTP/1.0 403 Forbidden
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html>
7+
<body>
8+
<h3>Docker Flow: Proxy</h3>
9+
<h1>403 Forbidden</h1>
10+
No server is available to handle this request.
11+
</body>
12+
</html>

errorfiles/405.http

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
HTTP/1.0 405 Method Not Allowed
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html>
7+
<body>
8+
<h3>Docker Flow: Proxy</h3>
9+
<h1>405 Method Not Allowed</h1>
10+
No server is available to handle this request.
11+
</body>
12+
</html>

errorfiles/408.http

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
HTTP/1.0 408 Request Timeout
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html>
7+
<body>
8+
<h3>Docker Flow: Proxy</h3>
9+
<h1>408 Request Timeout</h1>
10+
No server is available to handle this request.
11+
</body>
12+
</html>

errorfiles/429.http

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
HTTP/1.0 429 Too Many Requests
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html>
7+
<body>
8+
<h3>Docker Flow: Proxy</h3>
9+
<h1>429 Too Many Requests</h1>
10+
No server is available to handle this request.
11+
</body>
12+
</html>

errorfiles/500.http

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
HTTP/1.0 500 Internal Server Error
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html>
7+
<body>
8+
<h3>Docker Flow: Proxy</h3>
9+
<h1>500 Internal Server Error</h1>
10+
No server is available to handle this request.
11+
</body>
12+
</html>

errorfiles/502.http

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
HTTP/1.0 502 Bad Gateway
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html>
7+
<body>
8+
<h3>Docker Flow: Proxy</h3>
9+
<h1>502 Bad Gateway</h1>
10+
No server is available to handle this request.
11+
</body>
12+
</html>

errorfiles/503.http

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
HTTP/1.0 503 Service Unavailable
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html>
7+
<body>
8+
<h3>Docker Flow: Proxy</h3>
9+
<h1>503 Service Unavailable</h1>
10+
No server is available to handle this request.
11+
</body>
12+
</html>

errorfiles/504.http

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
HTTP/1.0 504 Gateway Timeout
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html>
7+
<body>
8+
<h3>Docker Flow: Proxy</h3>
9+
<h1>504 Gateway Timeout</h1>
10+
No server is available to handle this request.
11+
</body>
12+
</html>

haproxy.tmpl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@ global
55
defaults
66
mode http
77
balance roundrobin
8-
{{.ExtraDefaults}}
8+
{{.ExtraDefaults}}
99
option http-server-close
1010
option forwardfor
1111
option redispatch
1212

13+
errorfile 400 /errorfiles/400.http
14+
errorfile 403 /errorfiles/403.http
15+
errorfile 405 /errorfiles/405.http
16+
errorfile 408 /errorfiles/408.http
17+
errorfile 429 /errorfiles/429.http
18+
errorfile 500 /errorfiles/500.http
19+
errorfile 502 /errorfiles/502.http
20+
errorfile 503 /errorfiles/503.http
21+
errorfile 504 /errorfiles/504.http
22+
1323
maxconn 5000
1424
timeout connect {{.TimeoutConnect}}s
1525
timeout client {{.TimeoutClient}}s

integration_tests/integration_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ func (s IntegrationTestSuite) Test_Reconfigure_ReqRep() {
133133

134134
s.NoError(err)
135135
s.Equal(200, resp.StatusCode)
136-
s.printConf()
137136
}
138137

139138
func (s IntegrationTestSuite) Test_Stats_Auth() {
@@ -257,16 +256,6 @@ func (s IntegrationTestSuite) Test_Certs() {
257256

258257
s.Equal(200, resp.StatusCode)
259258

260-
// // HTTPS works
261-
// url = fmt.Sprintf("https://%s:8080/v2/test", os.Getenv("DOCKER_IP"))
262-
// req, _ = http.NewRequest("GET", url, nil)
263-
// client = &http.Client{}
264-
//
265-
// resp, err := client.Do(req)
266-
//
267-
// s.NoError(err)
268-
// s.Equal(200, resp.StatusCode)
269-
270259
// Can retrieve certs
271260
url = fmt.Sprintf("http://%s:8080/v1/docker-flow-proxy/certs", os.Getenv("DOCKER_IP"))
272261
req, _ = http.NewRequest("GET", url, nil)

proxy/ha_proxy_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ defaults
4141
option forwardfor
4242
option redispatch
4343
44+
errorfile 400 /errorfiles/400.http
45+
errorfile 403 /errorfiles/403.http
46+
errorfile 405 /errorfiles/405.http
47+
errorfile 408 /errorfiles/408.http
48+
errorfile 429 /errorfiles/429.http
49+
errorfile 500 /errorfiles/500.http
50+
errorfile 502 /errorfiles/502.http
51+
errorfile 503 /errorfiles/503.http
52+
errorfile 504 /errorfiles/504.http
53+
4454
maxconn 5000
4555
timeout connect 5s
4656
timeout client 20s

proxy/test_configs/tmpl/haproxy.tmpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ defaults
1010
option forwardfor
1111
option redispatch
1212

13+
errorfile 400 /errorfiles/400.http
14+
errorfile 403 /errorfiles/403.http
15+
errorfile 405 /errorfiles/405.http
16+
errorfile 408 /errorfiles/408.http
17+
errorfile 429 /errorfiles/429.http
18+
errorfile 500 /errorfiles/500.http
19+
errorfile 502 /errorfiles/502.http
20+
errorfile 503 /errorfiles/503.http
21+
errorfile 504 /errorfiles/504.http
22+
1323
maxconn 5000
1424
timeout connect {{.TimeoutConnect}}s
1525
timeout client {{.TimeoutClient}}s

0 commit comments

Comments
 (0)