Skip to content

Commit

Permalink
Allow arbitrary additional_fqdns, fixes #868 (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Jul 13, 2018
1 parent cb150bb commit 5fd0d9e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
21 changes: 20 additions & 1 deletion docs/users/extend/additional-hostnames.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,23 @@ additional_hostnames:
- it.mysite
```

This configuration would result in working hostnames of mysite.ddev.local, extraname.ddev.local, fr.mysite.ddev.local, es.mysite.ddev.local, and it.mysite.ddev.local (with full http and https URLs for each).
This configuration would result in working hostnames of mysite.ddev.local, extraname.ddev.local, fr.mysite.ddev.local, es.mysite.ddev.local, and it.mysite.ddev.local (with full http and https URLs for each).

**Although we recommend extreme care with this feature**, you can also provide additional_fqdn entries, which don't use the ".ddev.local" top-level domain. **This feature populates your hosts file with entries which may hide the real DNS entries on the internet, causing way too much head-scratching.**

```
name: somename
additional_fqdns:
- example.com
- somesite.example.com
- anothersite.example.com
```

This configuration would result in working FQDNs of somename.ddev.local, example.com, somesite.example.com, and anothersite.example.com.

**Note**: If you see ddev-router status become unhealthy in `ddev list`, it's most often a result of trying to use conflicting FQDNs in more than one project. "example.com" can only be assigned to one project, or it will break ddev-router.

**Warning**: this may not work predictably on all systems. There are operating systems and machines where /etc/hosts may not be the first or only resolution technique, especially if the additional_fqdn you use is also in DNS.

**Warning**: if you use an additional_fqdn that exists on the internet (like "www.google.com"), your hosts file will override access to the original (internet) site, and you'll be sad and confused that you can't get to it.
4 changes: 4 additions & 0 deletions pkg/ddevapp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ func (app *DdevApp) GetHostnames() []string {
nameListMap[name+"."+version.DDevTLD] = 1
}

for _, name := range app.AdditionalFQDNs {
nameListMap[name] = 1
}

// Now walk the map and extract the keys into an array.
nameListArray := make([]string, 0, len(nameListMap))
for k := range nameListMap {
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddevapp/ddevapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type DdevApp struct {
RouterHTTPSPort string `yaml:"router_https_port"`
XdebugEnabled bool `yaml:"xdebug_enabled"`
AdditionalHostnames []string `yaml:"additional_hostnames"`
AdditionalFQDNs []string `yaml:"additional_fqdns"`
ConfigPath string `yaml:"-"`
AppRoot string `yaml:"-"`
Platform string `yaml:"-"`
Expand Down Expand Up @@ -794,8 +795,7 @@ func (app *DdevApp) DockerEnv() {
envVars["COLUMNS"] = strconv.Itoa(columns)
envVars["LINES"] = strconv.Itoa(lines)

if len(app.AdditionalHostnames) > 0 {
// TODO: Warn people about additional names in use.
if len(app.AdditionalHostnames) > 0 || len(app.AdditionalFQDNs) > 0 {
envVars["DDEV_HOSTNAME"] = strings.Join(app.GetHostnames(), ",")
}

Expand Down
19 changes: 13 additions & 6 deletions pkg/ddevapp/ddevapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/drud/ddev/pkg/output"
"github.com/drud/ddev/pkg/testcommon"
"github.com/drud/ddev/pkg/util"
"github.com/drud/ddev/pkg/version"
"github.com/fsouza/go-dockerclient"
"github.com/lunixbochs/vtclean"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -256,6 +257,10 @@ func TestDdevStartMultipleHostnames(t *testing.T) {
// should uniqueify them.
app.AdditionalHostnames = []string{"sub1." + site.Name, "sub2." + site.Name, "subname.sub3." + site.Name, site.Name, site.Name, site.Name}

// sub1.<sitename>.ddev.local and sitename.ddev.local are deliberately included to prove they don't
// cause ddev-router failures"
app.AdditionalFQDNs = []string{"one.example.com", "two.example.com", "a.one.example.com", site.Name + "." + version.DDevTLD, "sub1." + site.Name + version.DDevTLD}

err = app.WriteConfig()
assert.NoError(err)

Expand Down Expand Up @@ -286,8 +291,16 @@ func TestDdevStartMultipleHostnames(t *testing.T) {
assert.NoError(err)
}

// Multiple projects can't run at the same time with the fqdns, so we need to clean
// up these for tests that run later.
app.AdditionalFQDNs = []string{}
app.AdditionalHostnames = []string{}
app.WriteConfig()

err = app.Stop()
assert.NoError(err)
err = app.Down(false)
assert.NoError(err)

runTime()
}
Expand Down Expand Up @@ -681,12 +694,6 @@ func TestDdevLogs(t *testing.T) {
out := stdout()
assert.Contains(out, "Server started")

stdout = testcommon.CaptureUserOut()
err = app.Logs("db", false, false, "1000")
assert.NoError(err)
out = stdout()
assert.Contains(out, "Database initialized")

stdout = testcommon.CaptureUserOut()
err = app.Logs("db", false, false, "")
assert.NoError(err)
Expand Down
6 changes: 6 additions & 0 deletions pkg/ddevapp/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ const ConfigInstructions = `
# would provide http and https URLs for "somename.ddev.local"
# and "someothername.ddev.local".
#additional_fqdns:
# - example.com
# - sub1.example.com
# would provide http and https URLs for "example.com" and "sub1.example.com"
# Please take care with this because it can cause great confusion.
# provider: default # Currently either "default" or "pantheon"
#
# Many ddev commands can be extended to run tasks after the ddev command is
Expand Down

0 comments on commit 5fd0d9e

Please sign in to comment.