Skip to content

Commit c2b4bde

Browse files
committed
Fixes #75
1 parent e9273bb commit c2b4bde

File tree

6 files changed

+42
-14
lines changed

6 files changed

+42
-14
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ ENV CONSUL_ADDRESS="" \
2222
SERVICE_NAME="proxy" \
2323
STATS_USER="admin" STATS_PASS="admin" \
2424
TIMEOUT_HTTP_REQUEST="5" TIMEOUT_HTTP_KEEP_ALIVE="15" TIMEOUT_CLIENT="20" TIMEOUT_CONNECT="5" TIMEOUT_QUEUE="30" TIMEOUT_SERVER="20" \
25-
USERS=""
25+
USERS="" \
26+
EXTRA_FRONTEND=""
2627

2728
EXPOSE 80
2829
EXPOSE 443

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,21 @@ The following environment variables can be used to configure the *Docker Flow: P
4545

4646
|Variable |Description |Required|Default|Example|
4747
|-------------------|----------------------------------------------------------|--------|-------|-------|
48-
|CONSUL_ADDRESS |The address of a Consul instance used for storing proxy information and discovering running nodes. Multiple addresses can be separated with comma (e.g. 192.168.0.10:8500,192.168.0.11:8500).|Only in *default* mode||192.168.0.10:8500|
48+
|CONSUL_ADDRESS |The address of a Consul instance used for storing proxy information and discovering running nodes. Multiple addresses can be separated with comma (e.g. 192.168.0.10:8500,192.168.0.11:8500).|Only in the *default* mode||192.168.0.10:8500|
49+
|EXTRA_FRONTEND |Value will be added to the default `frontend` configuration.|No ||http-request set-header X-Forwarded-Proto https if { ssl_fc }|
4950
|LISTENER_ADDRESS |The address of the [Docker Flow: Swarm Listener](https://github.com/vfarcic/docker-flow-swarm-listener) used for automatic proxy configuration.|Only in *swarm* mode||swarm-listener|
5051
|PROXY_INSTANCE_NAME|The name of the proxy instance. Useful if multiple proxies are running inside a cluster|No|docker-flow|docker-flow|
5152
|MODE |Two modes are supported. The *default* mode should be used for general purpose. It requires a Consul instance and service data to be stored in it (e.g. through Registrator). The *swarm* mode is designed to work with new features introduced in Docker 1.12 and assumes that containers are deployed as Docker services (new Swarm).|No |default|swarm|
5253
|SERVICE_NAME |The name of the service. It must be the same as the value of the `--name` argument used to create the proxy service. Used only in the *swarm* mode.|No|proxy|my-proxy|
53-
|STATS_USER |Username for the statistics page | |admin |my-user|
54-
|STATS_PASS |Password for the statistics page | |admin |my-pass|
55-
|TIMEOUT_CONNECT |The connect timeout in seconds | |5 |3 |
56-
|TIMEOUT_CLIENT |The client timeout in seconds | |20 |5 |
57-
|TIMEOUT_SERVER |The server timeout in seconds | |20 |5 |
58-
|TIMEOUT_QUEUE |The queue timeout in seconds | |30 |10 |
59-
|TIMEOUT_HTTP_REQUEST|The HTTP request timeout in seconds | |5 |3 |
60-
|TIMEOUT_HTTP_KEEP_ALIVE|The HTTP keep alive timeout in seconds | |15 |10 |
61-
|USERS |A comma-separated list of credentials(<user>:<pass>) for HTTP basic auth, which applies to all the backend routes.|||user1:pass1,user2:pass2|
54+
|STATS_USER |Username for the statistics page |No |admin |my-user|
55+
|STATS_PASS |Password for the statistics page |No |admin |my-pass|
56+
|TIMEOUT_CONNECT |The connect timeout in seconds |No |5 |3 |
57+
|TIMEOUT_CLIENT |The client timeout in seconds |No |20 |5 |
58+
|TIMEOUT_SERVER |The server timeout in seconds |No |20 |5 |
59+
|TIMEOUT_QUEUE |The queue timeout in seconds |No |30 |10 |
60+
|TIMEOUT_HTTP_REQUEST|The HTTP request timeout in seconds |No |5 |3 |
61+
|TIMEOUT_HTTP_KEEP_ALIVE|The HTTP keep alive timeout in seconds |No |15 |10 |
62+
|USERS |A comma-separated list of credentials(<user>:<pass>) for HTTP basic auth, which applies to all the backend routes.|No||user1:pass1,user2:pass2|
6263

6364
### Custom Config
6465

haproxy.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ defaults
3737
frontend services
3838
bind *:80
3939
bind *:443{{.CertsString}}
40-
mode http
40+
mode http
41+
{{.ExtraFrontend}}

proxy/ha_proxy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type ConfigData struct {
3030
UserList string
3131
ExtraGlobal string
3232
ExtraDefaults string
33+
ExtraFrontend string
3334
}
3435

3536
func NewHaProxy(templatesPath, configsPath string, certs map[string]bool) Proxy {
@@ -202,5 +203,6 @@ func (m HaProxy) getConfigData() ConfigData {
202203
option dontlognull
203204
option dontlog-normal`
204205
}
206+
d.ExtraFrontend = os.Getenv("EXTRA_FRONTEND")
205207
return d
206208
}

proxy/ha_proxy_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ defaults
6868
frontend services
6969
bind *:80
7070
bind *:443
71-
mode http`
71+
mode http
72+
`
7273
s.ServicesContent = `
7374
7475
config1 fe content
@@ -203,6 +204,27 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsDebug() {
203204
s.Equal(expectedData, actualData)
204205
}
205206

207+
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsExtraFrontEnd() {
208+
extraFrontendOrig := os.Getenv("EXTRA_FRONTEND")
209+
defer func() { os.Setenv("EXTRA_FRONTEND", extraFrontendOrig) }()
210+
os.Setenv("EXTRA_FRONTEND", "this is an extra content")
211+
var actualData string
212+
tmpl := s.TemplateContent + "this is an extra content"
213+
expectedData := fmt.Sprintf(
214+
"%s%s",
215+
tmpl,
216+
s.ServicesContent,
217+
)
218+
writeFile = func(filename string, data []byte, perm os.FileMode) error {
219+
actualData = string(data)
220+
return nil
221+
}
222+
223+
NewHaProxy(s.TemplatesPath, s.ConfigsPath, map[string]bool{}).CreateConfigFromTemplates()
224+
225+
s.Equal(expectedData, actualData)
226+
}
227+
206228
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsCert() {
207229
var actualFilename string
208230
expectedFilename := fmt.Sprintf("%s/haproxy.cfg", s.ConfigsPath)

proxy/test_configs/tmpl/haproxy.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ defaults
3737
frontend services
3838
bind *:80
3939
bind *:443{{.CertsString}}
40-
mode http
40+
mode http
41+
{{.ExtraFrontend}}

0 commit comments

Comments
 (0)