Skip to content

Commit

Permalink
Fixes #75
Browse files Browse the repository at this point in the history
  • Loading branch information
vfarcic committed Dec 19, 2016
1 parent e9273bb commit c2b4bde
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ ENV CONSUL_ADDRESS="" \
SERVICE_NAME="proxy" \
STATS_USER="admin" STATS_PASS="admin" \
TIMEOUT_HTTP_REQUEST="5" TIMEOUT_HTTP_KEEP_ALIVE="15" TIMEOUT_CLIENT="20" TIMEOUT_CONNECT="5" TIMEOUT_QUEUE="30" TIMEOUT_SERVER="20" \
USERS=""
USERS="" \
EXTRA_FRONTEND=""

EXPOSE 80
EXPOSE 443
Expand Down
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@ The following environment variables can be used to configure the *Docker Flow: P

|Variable |Description |Required|Default|Example|
|-------------------|----------------------------------------------------------|--------|-------|-------|
|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|
|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|
|EXTRA_FRONTEND |Value will be added to the default `frontend` configuration.|No ||http-request set-header X-Forwarded-Proto https if { ssl_fc }|
|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|
|PROXY_INSTANCE_NAME|The name of the proxy instance. Useful if multiple proxies are running inside a cluster|No|docker-flow|docker-flow|
|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|
|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|
|STATS_USER |Username for the statistics page | |admin |my-user|
|STATS_PASS |Password for the statistics page | |admin |my-pass|
|TIMEOUT_CONNECT |The connect timeout in seconds | |5 |3 |
|TIMEOUT_CLIENT |The client timeout in seconds | |20 |5 |
|TIMEOUT_SERVER |The server timeout in seconds | |20 |5 |
|TIMEOUT_QUEUE |The queue timeout in seconds | |30 |10 |
|TIMEOUT_HTTP_REQUEST|The HTTP request timeout in seconds | |5 |3 |
|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|
|STATS_USER |Username for the statistics page |No |admin |my-user|
|STATS_PASS |Password for the statistics page |No |admin |my-pass|
|TIMEOUT_CONNECT |The connect timeout in seconds |No |5 |3 |
|TIMEOUT_CLIENT |The client timeout in seconds |No |20 |5 |
|TIMEOUT_SERVER |The server timeout in seconds |No |20 |5 |
|TIMEOUT_QUEUE |The queue timeout in seconds |No |30 |10 |
|TIMEOUT_HTTP_REQUEST|The HTTP request timeout in seconds |No |5 |3 |
|TIMEOUT_HTTP_KEEP_ALIVE|The HTTP keep alive timeout in seconds |No |15 |10 |
|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|

### Custom Config

Expand Down
3 changes: 2 additions & 1 deletion haproxy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ defaults
frontend services
bind *:80
bind *:443{{.CertsString}}
mode http
mode http
{{.ExtraFrontend}}
2 changes: 2 additions & 0 deletions proxy/ha_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ConfigData struct {
UserList string
ExtraGlobal string
ExtraDefaults string
ExtraFrontend string
}

func NewHaProxy(templatesPath, configsPath string, certs map[string]bool) Proxy {
Expand Down Expand Up @@ -202,5 +203,6 @@ func (m HaProxy) getConfigData() ConfigData {
option dontlognull
option dontlog-normal`
}
d.ExtraFrontend = os.Getenv("EXTRA_FRONTEND")
return d
}
24 changes: 23 additions & 1 deletion proxy/ha_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ defaults
frontend services
bind *:80
bind *:443
mode http`
mode http
`
s.ServicesContent = `
config1 fe content
Expand Down Expand Up @@ -203,6 +204,27 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsDebug() {
s.Equal(expectedData, actualData)
}

func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsExtraFrontEnd() {
extraFrontendOrig := os.Getenv("EXTRA_FRONTEND")
defer func() { os.Setenv("EXTRA_FRONTEND", extraFrontendOrig) }()
os.Setenv("EXTRA_FRONTEND", "this is an extra content")
var actualData string
tmpl := s.TemplateContent + "this is an extra content"
expectedData := fmt.Sprintf(
"%s%s",
tmpl,
s.ServicesContent,
)
writeFile = func(filename string, data []byte, perm os.FileMode) error {
actualData = string(data)
return nil
}

NewHaProxy(s.TemplatesPath, s.ConfigsPath, map[string]bool{}).CreateConfigFromTemplates()

s.Equal(expectedData, actualData)
}

func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsCert() {
var actualFilename string
expectedFilename := fmt.Sprintf("%s/haproxy.cfg", s.ConfigsPath)
Expand Down
3 changes: 2 additions & 1 deletion proxy/test_configs/tmpl/haproxy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ defaults
frontend services
bind *:80
bind *:443{{.CertsString}}
mode http
mode http
{{.ExtraFrontend}}

0 comments on commit c2b4bde

Please sign in to comment.