Skip to content

Adds import-db and import-files commands - #123

Merged
tannerjfco merged 42 commits into
ddev:masterfrom
tannerjfco:import
Apr 18, 2017
Merged

tannerjfco merged 42 commits into
ddev:masterfrom
tannerjfco:import

Conversation

@tannerjfco

@tannerjfco tannerjfco commented Apr 3, 2017 •

Copy link
Copy Markdown
Contributor

The Problem:

See #33 for full details. Our existing import functionality is heavily reliant on site archives in a very specific structure and naming convention. We want import functionality that does not require rigid archive formats, and we want to be able to separately import the database and files as desired.

The Fix:

This PR introduces 2 new commands, ddev import-db and ddev import-files. The commands have some similar functionality. They both accept a path provided by user prompt or by using a --src flag. They both accept tar.gz archives, and if provided, will be extracted so the assets within can be imported.

The import-db command ultimately expects a single .sql file be provided. This means either a file path should be provided directly, or an archive containing a sql dump at the root of the archive should be provided.

The import-files command ultimately expects a directory path be provided. The provided directory's contents will be copied to the default uploaded files directory for the given application. In Drupal's case, this is sites/default/files. In WordPress' case, this is wp-content/uploads. If an archive is provided, the contents of the archive are copied as-is to the default location.

This also implements a new wp-config.php template that will work with a standard installation. Full details of this can be seen at the closed PR for this task #112

This PR does not remove the previous import command and its related functionality. For the purpose of easier reviews, the removal will be completed in a separate PR.

The Test:

Note: You will need to set the database container tag in the .ddev/config.yaml of the site you are testing to the import-update tag.

You should be able to test this with a pre-existing site, provided the site uses standard location for uploaded files. You can also use the following test sites that I have compiled test assets for:
https://github.com/drud/drupal8/releases/tag/v0.2.2
https://github.com/drud/wordpress/releases/tag/v0.1.0
https://github.com/drud/drupal-kickstart/releases/tag/v0.1.0

Usage examples:

examples are for import-files, but also valid for import-db, provided you are providing a sql dump.
Prompt:

ddev import-files
Provide the path to the directory or archive you wish to import. Please note, if the destination directory exists, it will be replaced with the import assets specified here.
Import path:
~/Desktop/wp-files.tar.gz
Successfully imported files for testsite1

Flag:

ddev import-files --src ~/Desktop/wp-files.tar.gz

or

ddev import-files --src=~/Desktop/wp-files.tar.gz

Automation Overview:

I have added test coverage for ImportDB and ImportFiles at the local plugin level. I have also added test coverage for the new appimport and files packages.

Related Issue Link(s):

#33 OP
#107 / #112 update wp-config template
drud/mysql-docker-local#11 - mysql import updates

Release/Deployment notes:

Does this affect anything else, or are there ramifications for other code? Does anything have to be done on deployment?

This PR does not remove the previous import command and its related functionality. For the purpose of easier reviews, the removal will be completed in a separate PR.

drud/mysql-docker-local#11 - mysql import updates is required for this change. A new tag will need to be pushed for this container.

@beeradb beeradb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not test functionality or even compile, but did a code review pass.

}

func init() {
ImportFileCmd.Flags().StringVarP(&fileSource, "src", "", "", "Provide the path to a directory or .tar.gz archive of files to import")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder about renaming this from --files-src, as it was in the mockups. The mockup names were chosen so that if/when we add an eventual "import" which does both, we could have consistent flag names across all the commands. It does create some stuttering, though.

Ultimately it's @rickmanelius, just pointing it out for consideration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to make it --src for both commands so that usage was consistent between the two commands, and for the flag to be shorter to type, in addition to resolving the stuttering you mentioned. Amusingly, I also kept trying to type --db-url which is apparently still muscle memory for me from drush site-install.

IMO, it would not be an issue if the flags were different for a combo cmd vs the single cmd, but that is indeed Rick's call

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it being --src for both.

Comment thread pkg/appimport/appimport.go Outdated
homedir "github.com/mitchellh/go-homedir"
)

// ValidateAsset determines if a given asset matches the required criteria for a given asset type. If the path provided is a tarball, it will extract, validate, and return the extracted asset path.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not much of a stickler for 80 characters but this may be long enough that splitting it into multiple lines would enhance readability

Comment thread pkg/appimport/appimport.go Outdated

// ValidateAsset determines if a given asset matches the required criteria for a given asset type. If the path provided is a tarball, it will extract, validate, and return the extracted asset path.
func ValidateAsset(assetPath string, assetType string) (string, error) {
var invalidAssetError = "%s. Please provide a valid asset path."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%v is typically preferred over %s for printing errors from what I have seen. From https://golang.org/pkg/fmt/

%v	the value in a default format
	when printing structs, the plus flag (%+v) adds field names

Comment thread pkg/appimport/appimport.go Outdated
}

if len(files) > 1 {
fmt.Println("WARNING: Multiple .sql files found. Only the first .sql file will be used.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably prefer to just import all SQL files found. Maybe that's an edge case, though.

At the very least, printing the filename of the SQL file that is actually being imported would likely reduce confusion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's unlikely that we could handle multi-part imports reliably, as the order in which they are imported tends to be important in that case (e.g. table structures before data goes in). I think it's best to warn and leave it to the user.

Totally valid to provide the sql file that will be used though.

Comment thread pkg/appimport/appimport.go Outdated

// if we extracted an archive, clean up the extraction point
if strings.Contains(source, os.TempDir()) {
os.RemoveAll(path.Dir(source))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should maybe be a defer?

Comment thread pkg/appimport/appimport.go Outdated
log.Fatal(err)
}
out, err := system.RunCommand(
"tar",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already shell out all over the place, but I think we also recognize it as a portability problem we probably need to get away from.

It may be wise to look into the archive/tar and compress/gzip packages to see if we can easily handle this without shelling out. A quick google returns this https://gist.github.com/indraniel/1a91458984179ab4cf80 gist which looks to extract tar.gz files.

This may also help us get around the awkward extract-copy-delete scenario above, as we could only extract the files needed and do so directly to the correct directory.

Comment thread pkg/appimport/appimport.go Outdated
}

// findFileExt walks a given directory searching for a given extension and returns a list of matching results.
func findFileExt(dirpath string, ext string) ([]string, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we be a bit more explicit with the name here?

Suggestions:

  • findFilesBy[Ext|Extension]
  • findFilesInDirectory

Comment thread pkg/ddevapp/config.go Outdated
// Define an application name.
fmt.Print(namePrompt + ": ")
c.Name = getInput(c.Name)
c.Name = GetInput(c.Name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine w/ reusing this but we should likely move it into a utils or inputreader package if we do.

Comment thread cmd/ddev/cmd/import-files.go Outdated
},
Run: func(cmd *cobra.Command, args []string) {
app := platform.PluginMap[strings.ToLower(plugin)]
app.Init()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fault of my bad example (which I've fixed in my latest PR #116), but the return of Init, err, needs to be checked here. It will return an error if a config can't be read, which is almost certainly a problem in this case.

@@ -295,6 +382,7 @@ func (l *LocalApp) FindPorts() error {
// as well as other sensitive data like salts.
func (l *LocalApp) Config() error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs to be modified to only try writing if a config file doesn't exist (or maybe it does? hard to tell from the diff)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad idea. I also had the idea of providing a --skip-config or similar flag for the db command, which would allow the user to skip it entirely and provide their own.

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the opposite of @beeradb and still have plenty to do, but first round:

  1. Import-db worked fine, although I suspect (drupal-specific) it's dependent on the settings.php config, and that may affect actual customer success.
  2. I was expecting import-db to handle a gzipped, zipped, or plain-text .sql file. If we have left that expectation behind, it's probably OK, but it would likely lead to a happier customer experience. I note that the error message I was given was enough to get me on the right path.

I'll continue onto files import and then code review.

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I experimented with both the file import and db import, and had satisfactory experiences with both.

I totally understand that this PR takes on a lot of ground and not every nit is going to be able to resolved here, but like @beeradb I had a few reactions to things that may or may not be valid.

I'll return to actually reviewing the code later; this really just covered my experiences with the actual usage and code it happened to lead me to.

Thanks for your patience @tannerjfco !

Comment thread cmd/ddev/cmd/import-db.go Outdated
var ImportDBCmd = &cobra.Command{
Use: "import-db",
Short: "Import the database of an existing site to the local dev environment.",
Long: "Import the database of an existing site to the local development environment. The database can be provided as a SQL dump in a .sql or .tar.gz format. For the .tar.gz format, a SQL dump in .sql format must be present at the root of the archive.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The database dump provided will be imported into a database named 'data' on the devsite host named 'db'. Your site database settings need to point to this database." or something like that will be helpful. Remember that people may or may not understand the architecture ddev is imposing wrt WebImage, DBImage, etc.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tannerjfco I was suggesting changed verbiage here, maybe that wasn't clear.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please validate extra commands and or flags here and in files import, this was confusing to me.

$ ddev import-db src=/tmp/v0.2.1.tar.gz
Provide the path to the database you wish to import.
Import path:

Comment thread pkg/appimport/appimport.go Outdated
}

// if we have a tarball, extract and set path to the extraction point
if strings.HasSuffix(assetPath, ".tar.gz") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please check file type rather than file extension. .tgz should work fine - it's what is inside that counts. I guess I'd be ok with checking both .tar.gz and .tgz, but would much prefer actually checking to see if it's gzipped and then see if it has a tarball in it. I guess what I'd really like is 1) gunzip or unzip based on file type, 2) check to see if the resulting file is tarball or zipball, 3) Unzip appropriately. I understand that might be too much, but it's what I was expecting and had written in the issue.

Comment thread pkg/appimport/appimport.go Outdated
}

// findFileByExtension walks a given directory searching for a given extension and returns a list of matching results.
func findFileByExtension(dirpath string, ext string) ([]string, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned elsewhere, extension is a very Windows way of doing things, and I would much prefer a more file-type way of doing it. So I'm uncomfortable with using extensions as a base idea at all.

Comment thread pkg/appimport/appimport.go Outdated
// CopyDir recursively copies a directory tree, attempting to preserve permissions.
// Source directory must exist, destination directory must *not* exist.
// Symlinks are ignored and skipped. Credit @m4ng0squ4sh https://gist.github.com/m4ng0squ4sh/92462b38df26839a3ca324697c8cba04
func CopyDir(src string, dst string) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we seriously have to recreate CopyFile and CopyDir functions in golang? Yuckie. I guess I didn't know that. Would be be better to just cp -rp or rsync in that case?

Comment thread pkg/appimport/appimport.go Outdated
return err
}
} else {
// Skip symlinks.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be an error to have a symlink? Is it OK to just continue?

Comment thread pkg/appimport/appimport.go Outdated
// destination file exists, all it's contents will be replaced by the contents
// of the source file. The file mode will be copied from the source and
// the copied data is synced/flushed to stable storage. Credit @m4ng0squ4sh https://gist.github.com/m4ng0squ4sh/92462b38df26839a3ca324697c8cba04
func CopyFile(src string, dst string) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to introduce utility functions, we at least need to get them into a utility package, rather than have them here. I agree that they could live here until required elsewhere and be moved then. But next dev might not ever know that this was done.

Comment thread pkg/appimport/appimport.go Outdated

// CopyFile copies the contents of the file named src to the file named
// by dst. The file will be created if it does not already exist. If the
// destination file exists, all it's contents will be replaced by the contents

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/it's/its/

@beeradb beeradb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I attempted to do a DB import both from tar.gz and from a DB file and neither appeared to work as advertised

First, from .sql

ddev/drupal8 ‹gke:drud-test› git:(master) » ddev import-db --src=db.sql
no file to import found at /db/data.sql
A settings file already exists for your application, so ddev did not generate one.
Run 'ddev describe' to find the database credentials for this application.
Successfully imported database for drupal8

Now, from .tar.gz

ddev/drupal8 ‹gke:drud-test› git:(master) » ddev import-db
Provide the path to the database you wish to import.
Import path:
db.tar.gz
no file to import found at /db/data.sql
Generating settings.php file for database connection.

The files import appears to work as advertised, though.

@tannerjfco

Copy link
Copy Markdown
Contributor Author

You will need to set the database container tag in the .ddev/config.yaml of the site you are testing to the import-update tag. I updated the test instructions to highlight this detail better.

@beeradb beeradb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with one (optional) comment:

  • ddev import-db sudhfuisdhfiudsfhsduifhsdiufh prompts me for the import path. It may be better to fail if there are arguments detected.

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming back for review now, just trying some things out.

ddev import-db --src=../fredthrall.com/fredthrall.sql.gz
Unable to successfully import database for drud-d7: failed to extract provided archive: archive/tar: invalid tar header

Wouldn't a sql.gz file be an obvious thing to import? I see that the help doesn't offer that, so I'll move on and try it with .sql

Comment thread cmd/ddev/cmd/import-db.go Outdated

err = app.ImportDB(dbSource)
if err != nil {
Failed("Unable to successfully import database for %s: %s", app.GetName(), err)

@rfay rfay Apr 12, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change "Unable to successfully import" to "Failed to import database" please?

@rfay

rfay commented Apr 12, 2017

Copy link
Copy Markdown
Member

Question for discussion: I would expect import-db to drop all tables before importing, I don't think it does right now. Is that what we want?

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK now for the wall-o-text. I'm exhausted, so I know you're way beyond exhausted with all this.

Thanks for the great work and the thoughtful tests. This is a pile of work, and I think it's nearly good to go.

It worked for me in nearly everything I tried; the exception was *.sql.gz db imports.

I had a few comments that really deserve followup (checking returns on filesystem operations, deciding if *.sql.gz is supported, and if is, testing it). Then a lot of coaching-type or questioning type comments.

I'm leaving it at "requesting changes" at this point because some of those do need to be addressed.

Comment thread .vscode/settings.json
@@ -0,0 +1,4 @@
// Place your settings in this file to overwrite default and user settings.
{
"go.testTimeout": "360s"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be added in another PR but I won't tell if you don't. Also... I'm assuming you want this here and that everybody should have it; otherwise it should go in .gitignore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setting is specific to the project, as the default 30s timeout isn't going to be all that useful for some of these tests.

Comment thread Makefile
PATH=$$PWD/bin/$(TESTOS):$$PATH CGO_ENABLED=0 DDEV_BINARY_FULLPATH=$(DDEV_BINARY_FULLPATH) DRUD_DEBUG=true go test -timeout 20m -v -installsuffix 'static' -ldflags "$(LDFLAGS)" ./pkg/...
PATH=$$PWD/bin/$(TESTOS):$$PATH CGO_ENABLED=0 DDEV_BINARY_FULLPATH=$(DDEV_BINARY_FULLPATH) go test -p 1 -timeout 20m -v -installsuffix static -ldflags "$(LDFLAGS)" ./cmd/...
PATH=$$PWD/bin/$(TESTOS):$$PATH CGO_ENABLED=0 DDEV_BINARY_FULLPATH=$(DDEV_BINARY_FULLPATH) DRUD_DEBUG=true go test -timeout 20m -v -installsuffix static -ldflags "$(LDFLAGS)" ./pkg/...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will conflict with #140, which moves these two into separate targets; There is no damage in removing the single quotes from 'static', but also I don't believe there can be any benefit (or change).

Comment thread README.md

```
➜ ddev import-db
Provide the path to the database you wish to import.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this doc out of date? Shouldn't it have --src= ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cmd will provide a prompt if no flags are provided.

Comment thread README.md Outdated
Successfully imported database for drupal8
```

The `import-db` command allows you to specify the location of a SQL dump to be imported as the active database for your site. The database may be provided as a `.sql` file, `.sql.gz` or `.tar.gz` archive. The provided dump will be imported into the database named `data` in the database container for your site. A database connection file will be generated for your site if one does not exist (`settings.php` for Drupal, `wp-config.php` for WordPress). If you have already created a connection file, you will need to ensure your connection credentials match the ones provided in `ddev describe`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think sql.gz works right now.
$ ddev import-db --src=../fredthrall.com/fredthrall.sql.gz Unable to successfully import database for drud-d7: failed to extract provided archive: archive/tar: invalid tar header Unable to successfully import database for drud-d7: failed to extract provided archive: archive/tar: invalid tar header

Comment thread README.md Outdated
Successfully imported files for drupal8
```

The `import-files` command allows you to specify the location of uploaded file assets to import for your site. For Drupal, this is the public files directory, located at `sites/default/files` by default. For WordPress, this is the uploads directory, located at `wp-content/uploads` by default. The files may be provided as a directory or archive containing the contents of the uploads folder. The contents of the directory or archive provided will be copied to the default location of the upload directory for your site.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ ddev import-files --src=/tmp/fredthrall_files.tgz
Unable to successfully import files for drud-d7: remove /Users/rfay/workspace/drud-d7/docroot/sites/default/files: permission denied

This is the classic problem of drupal setting the sites/default to 0555. - We may want to explicitly chmod u+w sites/default ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document needs to say what the contents of the "files" tarball looks like. AFAICT it is supposed to be the files and directories within the files directory, not including files/ - This may want to be in the help for the command as well.

Comment thread pkg/testcommon/testcommon.go Outdated
os.Setenv("DRUD_NONINTERACTIVE", "true")

err = system.DownloadFile(site.archivePath(), site.DownloadURL)
err = system.DownloadFile(site.archivePath(), site.SourceURL)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have conflict with #140 here.

// DownloadURL is the URL of the tarball to be used for building the site.
DownloadURL string
Dir string
// SourceURL is the URL of the source code tarball to be used for building the site.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused at first about the name change DownloadURL -> SourceURL, but the comment helps - "source code tarball"

Comment thread pkg/util/files/files.go Outdated
return err
}

tf := tar.NewReader(gf)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! Thanks.

Comment thread pkg/util/files/files_test.go Outdated

err = Untargz(testArchivePath, exDir)
assert.NoError(err)
assert.True(system.FileExists(path.Join(exDir, "2017", "04", "pexels-photo-265186-100x100.jpeg")))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty stinking fragile :( Might there be a way to infer general structure, rather than the exact contents? Basically this tightly-couples the test here and the tarball there, making it so either one can break the test, and neither one is actually relevant to the underlying reason for the test (with is to make sure we can untar a tarball).


file, err := os.Stat(dest)
assert.NoError(err)
assert.Equal(int(file.Mode()), 0644)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about an assertion to see if they're actually equal, maybe exec a cksum command, or another golang technique?

@rickmanelius

Copy link
Copy Markdown
Contributor

Testing #123

Prep for ddev

  • Checkout ddev repo from tannerjfco/import at commit ccc6901
  • Run make clean && make darwin

Prepping Site Configuration

  • Checkout codebase for personal blog site.
  • Run ddev config with general configurations
  • Open .ddev/config.yml and updated the database image to drud/mysql-docker-local-57:import-update.
  • Starting the containers by running ddev start and verified that the site URL is accessible, but with the expected database error because the site currently doesn't have a db yet.

Importing Assets

  • Downloaded my files as *.tar.gz and database as *.sql.gz.
    • I later noted that the database needs to be unzipped, and therefore unzipped before running the next command.
  • Ran ddev import-db and specified ~/Downloads/*.sql
  • Terminal reported a successful install!
  • I still had a custom settings.php file in place, so I had to delete this first.
  • Re-running ddev rm and then ddev start got me to the installation page!
  • Re-runnuing ddev import-db --src=~/Downloads/DB.sql reported a successful install AND created a new settings.php and drush.settings.php file.
  • Visiting http://SITENAME.ddev.local/ shows a success db import!
  • Ran ddev import-files --src=~/Downloads/files.tar.gz and received the warning: "Unable to successfully import files for rickmanelius: failed to extract provided archive: open /Users/rmanelius/git/rickmanelius/sites/default/files/files_live/IMCE/content/visual-alignment-arrows.psd:"
    • Note that I was able to unzip that zip directly through the macOS finder and from the command line (gunzip and tar xvf).

I'm stopping for now because I need to change gears for our meetings, but any help on fixing the file archive will help get this to an approved state.

@rickmanelius

Copy link
Copy Markdown
Contributor

Follow up to my last message. I was actually able to solve this, but I'm guessing there are two parts needed to address. The issue was that the SITENAME.tar.zip downloaded from Pantheon unzips with a files-live parent folder wherease the files.tar.gz that Tanner referenced here https://github.com/drud/drupal-kickstart/releases/tag/v0.1.0 unzips without a folder that encloses the files normally expected in sites/default/files.

So my work-around was to do the following. I manually ran gunzip and tar xvf, then created a new tar.gz from within that directory. Then I was able to effectively import the files.

I'm not sure how I would necessarily solve. We could run a quick check to see if unzipping the file tar.gz results in a single folder and then assume that we should move the files from within that singular directory instead of copying the enclosing folder over.

The second issue, which I'm not sure how to address, is why the zip from Pantheon refused to work even with the parent folder. For example, I originally unzipped and rezipped with the files-live parent folder as the enclosing folder within the zip. I was still able to successfully run ddev import-files with that new tar.gz. There might be some weird discrepancy in these Pantheon zips that is removed once a manual gunzip/gzip is run to correct the enclosing files directory issue.

I would recommend spinning up a free demo site on Patheon, pulling a zip, and using that to address the enclosing folder issue. Hopefully that fixes the other issue as to why it wasn't unzipping in the first place, but I wanted to surface this just in case.

@rickmanelius rickmanelius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the scope of this ticket didn't include compatibility with zips from Pantheon, the enclosing folder issue will be a gotcha for those that aren't careful on how they zip their files directory. Additionally, since we are targeting Pantheon integration, I would be curious as to why the zip wasn't working as it is (it could also be user error on my part).

@tannerjfco

Copy link
Copy Markdown
Contributor Author

With the latest updates, sql.gz import should work as expected. Additionally, tar files will work whether or not they are gzipped. Once we have green board on the tests, this should be ready to come in.

@rfay

rfay commented Apr 18, 2017

Copy link
Copy Markdown
Member

I tested .sql, .sql.gz for database and .tar, .tar.gz, .tgz for files. They all seemed to work fine. Approved. There will be followups, we know. Huge accomplishment, thanks for hanging in there.

@rfay
rfay dismissed rickmanelius’s stale review April 18, 2017 23:24

I read through Rick's review and believe all his issues are solved at this point (or punted to future issues). And we should get this merged. Hope that's OK Rick.

@tannerjfco
tannerjfco merged commit 137ec3b into ddev:master Apr 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants