Skip to content

Commit

Permalink
Use simple tempdir for import instead of a separate mount
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Mar 20, 2019
1 parent 0a71132 commit a282904
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
17 changes: 10 additions & 7 deletions pkg/ddevapp/ddevapp.go
Original file line number Diff line number Diff line change
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 @@ -262,16 +263,16 @@ func (app *DdevApp) GetWebserverType() string {
func (app *DdevApp) ImportDB(imPath string, extPath string, progress bool) error {
app.DockerEnv()
var extPathPrompt bool

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 = os.MkdirAll(app.ImportDir, 0777)
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 @@ -339,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
2 changes: 0 additions & 2 deletions pkg/dockerutil/testdata/docker-compose.override.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 a282904

Please sign in to comment.