Skip to content

Commit

Permalink
Fixes #205
Browse files Browse the repository at this point in the history
  • Loading branch information
vfarcic committed Apr 24, 2017
1 parent 3952d62 commit 4c6ab96
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 54 deletions.
6 changes: 3 additions & 3 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ The following environment variables can be used to configure the *Docker Flow Pr
PROXY_INSTANCE_NAME|The name of the proxy instance. Useful if multiple proxies are running inside a cluster.|No|docker-flow|
|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.<br>Example: my-proxy|No|proxy|
|SKIP_ADDRESS_VALIDATION|Whether to skip validating service address before reconfiguring the proxy.<br>Example: false|No|true|
|STATS_USER |Username for the statistics page. If not set, stats will not be available.<br>Example: my-user|No |admin |
|STATS_USER_ENV |The name of the environment variable that holds the username for the statistics page<br>Example: MY_USER|No|STATS_USER|
|STATS_PASS |Password for the statistics page. If not set, stats will not be available.<br>Example: my-pass|No |admin |
|STATS_USER |Username for the statistics page. If not set, stats will not be available. If both `STATS_USER` and `STATS_PASS` are set to `none`, statistics will be available without authentication.<br>Example: my-user|No |admin |
|STATS_USER_ENV |The name of the environment variable that holds the username for the statistics page.<br>Example: MY_USER|No|STATS_USER|
|STATS_PASS |Password for the statistics page. If not set, stats will not be available. If both `STATS_USER` and `STATS_PASS` are set to `none`, statistics will be available without authentication.<br>Example: my-pass|No|admin|
|STATS_PASS_ENV |The name of the environment variable that holds the password for the statistics page.<br>Example: MY_PASS|No|STATS_PASS|
|STATS_URI |URI for the statistics page.<br>Example: proxyStats |No |/admin?proxy|
|STATS_URI_ENV |The name of the environment variable that holds the URI for the statistics page.<br>Example: MY_URI|No|STATS_URI|
Expand Down
11 changes: 11 additions & 0 deletions integration_tests/integration_swarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func TestGeneralIntegrationSwarmTestSuite(t *testing.T) {
-p 6379:6379 \
--network proxy \
-e MODE=swarm \
-e STATS_USER=none \
-e STATS_PASS=none \
%s/docker-flow-proxy:beta`,
s.dockerHubUser)
s.createService(cmd)
Expand Down Expand Up @@ -78,6 +80,15 @@ func (s IntegrationSwarmTestSuite) Test_Reconfigure() {
s.Equal(200, resp.StatusCode, s.getProxyConf())
}

func (s IntegrationSwarmTestSuite) Test_Stats() {
url := fmt.Sprintf("http://%s/admin?stats", s.hostIP)

resp, err := http.Get(url)

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

func (s IntegrationSwarmTestSuite) Test_Remove() {
s.reconfigureGoDemo("")

Expand Down
11 changes: 7 additions & 4 deletions proxy/ha_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ backend dummy-be
return content.String(), nil
}

// TODO: Too big... Refactor it.
func (m HaProxy) getConfigData() ConfigData {
certPaths := m.GetCertPaths()
certsString := []string{}
Expand Down Expand Up @@ -206,12 +205,16 @@ func (m HaProxy) getConfigData() ConfigData {
stats enable
stats refresh 30s
stats realm Strictly\ Private
stats auth %s:%s
stats uri %s`,
statsUser,
statsPass,
statsUri,
)
if !strings.EqualFold(statsUser, "none") && !strings.EqualFold(statsPass, "none") {
d.Stats += fmt.Sprintf(`
stats auth %s:%s`,
statsUser,
statsPass,
)
}
}
m.getUserList(&d)
d.ExtraFrontend = GetSecretOrEnvVar("EXTRA_FRONTEND", "")
Expand Down
29 changes: 28 additions & 1 deletion proxy/ha_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ defaults
stats enable
stats refresh 30s
stats realm Strictly\ Private
stats auth admin:admin
stats uri /admin?stats
stats auth admin:admin
frontend services
bind *:80
Expand Down Expand Up @@ -312,6 +312,33 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsLogging_WhenDebug()
s.Equal(expectedData, actualData)
}

func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_RemovesStatsAuth_WhenUserIsNone() {
var actualData string
statUserOrig := os.Getenv("STATS_USER")
statPassOrig := os.Getenv("STATS_PASS")
defer func() {
os.Setenv("STATS_USER", statUserOrig)
os.Setenv("STATS_PASS", statPassOrig)
}()
os.Setenv("STATS_USER", "none")
os.Setenv("STATS_PASS", "none")
statsAuth := `
stats auth admin:admin`
expectedData := fmt.Sprintf(
"%s%s",
strings.Replace(s.TemplateContent, statsAuth, "", -1),
s.ServicesContent,
)
writeFile = func(filename string, data []byte, perm os.FileMode) error {
actualData = string(data)
return nil
}

NewHaProxy(s.TemplatesPath, s.ConfigsPath).CreateConfigFromTemplates()

s.Equal(expectedData, actualData)
}

func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsHttpLogFormat_WhenSpecified() {
debugOrig := os.Getenv("DEBUG")
debugHttpFormatOrig := os.Getenv("DEBUG_HTTP_FORMAT")
Expand Down
3 changes: 1 addition & 2 deletions proxy/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ type Service struct {
PathType string `split_words:"true"`
// Whether to redirect to https when X-Forwarded-Proto is http
RedirectWhenHttpProto bool `split_words:"true"`
// The request mode. The proxy should be able to work with any mode supported by HAProxy. However, actively supported and tested modes are *http* and *tcp*. Please open an GitHub issue if the mode you're using does not work as expected. The default value is *http*.
// Adding support for *sni*. Setting this to "sni" implies TCP with an SNI-based routing.
// The request mode. The proxy should be able to work with any mode supported by HAProxy. However, actively supported and tested modes are *http*, *tcp*, and *sni*.
ReqMode string `default:"http" split_words:"true"`
// Deprecated in favor of ReqPathReplace
ReqRepReplace string `split_words:"true"`
Expand Down
48 changes: 4 additions & 44 deletions tmp.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,12 @@
```bash
docker network create --driver overlay proxy

docker network create --driver overlay go-demo

docker service create --name go-demo-db \
--network go-demo \
mongo

docker service create --name go-demo \
-e DB=go-demo-db \
--network go-demo \
--label com.df.notify=true \
--label com.df.distribute=true \
--label com.df.servicePath=/demo \
--label com.df.port=8080 \
vfarcic/go-demo








docker run --rm -v $PWD:/usr/src/myapp -w /usr/src/myapp -v go:/go golang:1.6 bash -c "go get -d -v -t && CGO_ENABLED=0 GOOS=linux go build -v -o docker-flow-swarm-listener"

docker build -t vfarcic/docker-flow-swarm-listener:test .

docker push vfarcic/docker-flow-swarm-listener:test

docker service create --name swarm-listener \
--network proxy \
--mount "type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock" \
-e DF_NOTIFY_CREATE_SERVICE_URL=http://proxy:8080/v1/docker-flow-proxy/reconfigure \
-e DF_NOTIFY_REMOVE_SERVICE_URL=http://proxy:8080/v1/docker-flow-proxy/remove \
-e DF_RETRY=2 \
--constraint 'node.role==manager' \
vfarcic/docker-flow-swarm-listener:test

docker service create --name proxy \
-p 80:80 \
-p 443:443 \
-p 8080:8080 \
--network proxy \
-e MODE=swarm \
-e LISTENER_ADDRESS=swarm-listener \
-e DFP_SERVICE_1_SERVICE_NAME=go-demo_main \
-e DFP_SERVICE_1_SERVICE_PATH=/demo \
-e DFP_SERVICE_1_PORT=8080 \
vfarcic/docker-flow-proxy

docker ps

docker service rm proxy swarm-listener
```

0 comments on commit 4c6ab96

Please sign in to comment.