Skip to content

Commit

Permalink
Remove use of import-db directory (#1445)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Mar 21, 2019
1 parent 8fd114c commit e3e30f0
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 49 deletions.
2 changes: 0 additions & 2 deletions pkg/ddevapp/config.go
Expand Up @@ -237,8 +237,6 @@ func (app *DdevApp) ReadConfig() error {
app.OmitContainers = globalconfig.DdevGlobalConfig.OmitContainers
}

app.ImportDir = app.GetConfigPath("import-db")

app.SetApptypeSettingsPaths()

return nil
Expand Down
49 changes: 10 additions & 39 deletions pkg/ddevapp/ddevapp.go
Expand Up @@ -2,6 +2,8 @@ package ddevapp

import (
"fmt"
"github.com/mattn/go-isatty"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand All @@ -28,7 +30,6 @@ import (
"github.com/drud/ddev/pkg/version"
"github.com/fsouza/go-dockerclient"
"github.com/lextoumbourou/goodhosts"
"github.com/mattn/go-isatty"
"github.com/mattn/go-shellwords"
)

Expand Down Expand Up @@ -90,7 +91,6 @@ type DdevApp struct {
Platform string `yaml:"-"`
Provider string `yaml:"provider,omitempty"`
DataDir string `yaml:"-"`
ImportDir string `yaml:"-"`
SiteSettingsPath string `yaml:"-"`
SiteLocalSettingsPath string `yaml:"-"`
providerInstance Provider `yaml:"-"`
Expand Down Expand Up @@ -263,16 +263,16 @@ func (app *DdevApp) GetWebserverType() string {
func (app *DdevApp) ImportDB(imPath string, extPath string, progress bool) error {
app.DockerEnv()
var extPathPrompt bool
dbPath := app.ImportDir

err := app.ProcessHooks("pre-import-db")
dbPath, err := ioutil.TempDir(filepath.Dir(app.ConfigPath), "importdb")
//nolint: errcheck
defer os.RemoveAll(dbPath)
if err != nil {
return err
}

err = fileutil.PurgeDirectory(dbPath)
err = app.ProcessHooks("pre-import-db")
if err != nil {
return fmt.Errorf("failed to cleanup %s before import: %v", dbPath, err)
return err
}

if imPath == "" {
Expand Down Expand Up @@ -340,9 +340,11 @@ func (app *DdevApp) ImportDB(imPath string, extPath string, progress bool) error
return fmt.Errorf("no .sql or .mysql files found to import")
}

// Inside the container, the dir for imports will be at /mnt/ddev_config/<tmpdir_name>
insideContainerImportPath := path.Join("/mnt/ddev_config", filepath.Base(dbPath))
_, _, err = app.Exec(&ExecOpts{
Service: "db",
Cmd: []string{"bash", "-c", "mysql --database=mysql -e 'DROP DATABASE IF EXISTS db; CREATE DATABASE db;' && pv /db/*.*sql | mysql db"},
Cmd: []string{"bash", "-c", "mysql --database=mysql -e 'DROP DATABASE IF EXISTS db; CREATE DATABASE db;' && pv " + insideContainerImportPath + "/*.*sql | mysql db"},
Tty: progress && isatty.IsTerminal(os.Stderr.Fd()),
})

Expand Down Expand Up @@ -696,11 +698,6 @@ func (app *DdevApp) Start() error {
return err
}

err = app.prepSiteDirs()
if err != nil {
return err
}

err = app.AddHostsEntries()
if err != nil {
return err
Expand Down Expand Up @@ -933,7 +930,6 @@ func (app *DdevApp) DockerEnv() {
"DDEV_BGSYNCIMAGE": app.BgsyncImage,
"DDEV_APPROOT": app.AppRoot,
"DDEV_DOCROOT": app.Docroot,
"DDEV_IMPORTDIR": app.ImportDir,
"DDEV_URL": app.GetHTTPURL(),
"DDEV_HOSTNAME": app.HostName(),
"DDEV_UID": uidStr,
Expand Down Expand Up @@ -1367,31 +1363,6 @@ func (app *DdevApp) RemoveHostsEntries() error {
return nil
}

// prepSiteDirs creates a site's directories for db container mounts
func (app *DdevApp) prepSiteDirs() error {

dirs := []string{
app.ImportDir,
}

for _, dir := range dirs {
fileInfo, err := os.Stat(dir)

if os.IsNotExist(err) { // If it doesn't exist, create it.
err = os.MkdirAll(dir, os.FileMode(int(0774)))
if err != nil {
return fmt.Errorf("Failed to create directory %s, err: %v", dir, err)
}
} else if err == nil && fileInfo.IsDir() { // If the directory exists, we're fine and don't have to create it.
continue
} else { // But otherwise it must have existed as a file, so bail
return fmt.Errorf("error trying to create directory %s, err: %v", dir, err)
}
}

return nil
}

// GetActiveAppRoot returns the fully rooted directory of the active app, or an error
func GetActiveAppRoot(siteName string) (string, error) {
var siteDir string
Expand Down
3 changes: 0 additions & 3 deletions pkg/ddevapp/templates.go
Expand Up @@ -15,9 +15,6 @@ services:
target: "/var/lib/mysql"
volume:
nocopy: true
- type: "bind"
source: "${DDEV_IMPORTDIR}"
target: "/db"
- type: "bind"
source: "."
target: "/mnt/ddev_config"
Expand Down
2 changes: 0 additions & 2 deletions pkg/dockerutil/testdata/docker-compose.override.yml
Expand Up @@ -4,8 +4,6 @@ services:
foo:
container_name: ddev-test-foo
image: some/image:1.1.0
volumes:
- "${DDEV_IMPORTDIR}:/db"
restart: always
environment:
- HTTP_EXPOSE=3306
Expand Down
2 changes: 0 additions & 2 deletions pkg/dockerutil/testdata/docker-compose.yml
Expand Up @@ -5,8 +5,6 @@ services:
container_name: ddev-test-db
image: DDEV_DBIMAGE
user: "$DDEV_UID:$DDEV_GID"
volumes:
- "${DDEV_IMPORTDIR}:/db"
restart: always
environment:
- SOME_ENV=env_value_goes_here
Expand Down
1 change: 0 additions & 1 deletion pkg/testcommon/testcommon.go
Expand Up @@ -201,7 +201,6 @@ func ClearDockerEnv() {
"DDEV_DOCROOT",
"DDEV_URL",
"DDEV_HOSTNAME",
"DDEV_IMPORTDIR",
"DDEV_PHP_VERSION",
"DDEV_PROJECT_TYPE",
"DDEV_ROUTER_HTTP_PORT",
Expand Down

0 comments on commit e3e30f0

Please sign in to comment.