-
-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ddev_drush_settings.php actually work on host, fixes #454 #1036
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually the issue in #454 I think and I suspect you've fixed it properly, but it should be removed from the docs and actually fixed in the generated settings.ddev.php (which is created in templates.go)
Thanks for chasing this, I think you've actually got it! The requirement is that it try to work both inside the container and on the host though. There may be a more elegant way of determining whether we're on the host. This has been untouched for like 2 years :)
Thanks @rfay, I didn't realise this was auto-generated as part of settings.ddev.php, just assumed it was an incorrect example. I've gone ahead and modified the templates and removed the snippet from the docs page and replaced it with some new wording. I haven't changed the use of the Let me know if there's anything else you'd like changed. |
This probably needs an automated test, but it's nontrivial to check the host-side drush usage on every platform, where we don't currently have drush installed. I think there are drush usage tests sprinkled around that would make sure it's working inside the web container. |
I'm happy to try and add some tests for drush usage on the host side, although I'm not familiar with go so might take me a bit of time. |
That seems like a lot to ask. When we test this we'll see if we can do some tests, if you'll allow push by rfay and andrewfrench to your fork (if you haven't already). |
Thanks - sounds good. Yes you should have access to push to the branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/users/developer-tools.md
Outdated
@@ -53,7 +53,7 @@ The port referenced is unique per running project, and randomly chosen from avai | |||
**Note:** The host database port is likely to change any time a project is stopped/removed and then later started again. | |||
|
|||
### Using Drush Installation on Host Machine | |||
If you have Drush installed on your host system, you can use it to interact with a ddev project by defining a `drush.settings.php` file at the docroot of your code base, and referencing it from your `settings.php` file. The `drush.settings.php` file should look similar to below, using the host port information for your project retrieved from `ddev describe`: | |||
If you have Drush installed on your host system, you can use it to interact with a ddev project by defining a `drush.settings.php` file at the docroot of your code base. This will be automatically referenced from the generated `settings.ddev.php` file which is located under `web/sites/default`. The `drush.settings.php` file should look similar to below, using the host port information for your project retrieved from `ddev describe`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite my statement to the contrary, I don't see ddev generating this automatically on d8. Also, the path listed "web/sites/default" is highly variable, I assume that should be <docroot>/sites/default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed to <docroot>/sites/default
. I tested this with D8 and the include statement is actually automatically generated in settings.ddev.php (not setttings.php)
pkg/ddevapp/drupal.go
Outdated
@@ -163,7 +163,7 @@ if (empty($config_directories[CONFIG_SYNC_DIRECTORY])) { | |||
// This determines whether or not drush should include a custom settings file which allows | |||
// it to work both within a docker container and natively on the host system. | |||
if (!empty($_SERVER["argv"]) && strpos($_SERVER["argv"][0], "drush") && empty($_ENV['DEPLOY_NAME'])) { | |||
include __DIR__ . '../../../drush.settings.php'; | |||
include __DIR__ . '/../../../drush.settings.php'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works inside the container (I think) but I don't think there's any guaranteed way it can work on the host.
If we're assuming that the drush.settings.php is to be in sites/default/drush.settings.php, wouldn't we just use
$drush_settings = dirname(__FILE__) . '/drush.settings.php';
if (is_readable($drush_settings)) {
require $ddev_settings;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd assumed there was a reason why it was referencing the doc root, rather than looking in sites/default, but if there isn't then this seems better as all the config files are then in one place.
I assume this should still check the environment variable and only do the include if we're not inside the container? Is there any reason why we'd even want this to work inside the container, if really the reason for it is to be able to access the db from the host? If so, then should we have 2 files, eg drush.settings.php and drush.host.settings.php?
Re #941 and transient ports, personally I'd much prefer to have a single db container exposed on a single port which can then be used by all the dev sites. I know that's not the 'docker way' and others probably wouldn't like this, but would fit my workflow better. At the moment I'm just running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well wow, I didn't intend to actually go to town with this, but thanks for the inspiration @JeremySkinner - I think this is now what it always wanted to be. The ddev_drush_settings.php is actually generated during ddev start
and it has the right port number for db; also fixed that it wouldn't have had the right host on docker toolbox. The docs are now much shorter because people don't have to manage this themselves.
I'm going to take the liberty of updating the OP testing instructions etc.
Thanks so much for the inspiration, and I hope you can test it out a bit @JeremySkinner .
Thanks @rfay, that looks good and will be much more useful. Looking forward to playing with it. Thanks again for getting this in so quickly 👍👍 |
Artifacts from this PR can be downloaded for testing from https://circleci.com/gh/drud/ddev/3225#artifacts/containers/0 for testing - there are builds for macOS, Linux, and Windows there. |
I've been using this today and it works nicely with no issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes look good and I was able to manually confirm that ddev_drush_settings.php were correctly generated on ddev start
.
c761007
to
e1d04bd
Compare
@andrewfrench there are probably a couple of things I slipped in here that you'll want to look at again and make sure you're good with them:
|
@@ -133,6 +133,10 @@ func (app *DdevApp) CreateSettingsFile() (string, error) { | |||
if err != nil { | |||
util.Warning("Unable to create settings file: %v", err) | |||
} | |||
if err := CreateGitIgnore(filepath.Dir(app.SiteSettingsPath), filepath.Base(app.SiteLocalSettingsPath), "ddev_drush_settings.php"); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be my CMS ignorance showing, but isn't this very Drupal-centric? Do TYPO3 and Wordpress projects have a ddev_drush_settings.php
file?
I suppose there's no harm in ignoring something that may not exist, but I think this block could be flagged for a CMS-specific refactor at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My assumption is that it's ok to ignore something that doesn't exist to make the code simpler. Drush is for Drupal only, but I guess it shouldn't be offensive to people to find a non-their-CMS file gitignored.
This is actually undoing the previous CMS-specific approach, which involved 4x duplicated code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, I see that now. That's fine with me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-approved after changes
…config, piggy-back gitignore creation on that
This one fails with the same #fail as master on TestDdevRestoreSnapshot, but only there, and only on Windows 10 Home. We'll definitely have to find out what's going on there, hopefully tomorrow, but it's not related to this PR. I'm going to go ahead and pull it. |
OP was from @JeremySkinner
The Problem/Issue/Bug:
drush.settings.php never did what we actually wanted it to do, see OP #454. We wanted it to work on the host so drush commands could be executed on the host. Here's hoping that @JeremySkinner isn't the only person in history that actually wanted/needed this.
How this PR Solves The Problem:
ddev start
time for drupal and backdrop. It's automatically included if on the host and the file is available.Manual Testing Instructions:
On a drupal6/7/8 project,
ddev config
to regenerate settingsddev start
to start it (and generate the ddev_drush_settings.php)drush sql-cli
ordrush ws
Automated Testing Overview:
Related Issue Link(s):
OP #454
Thanks to @JeremySkinner for making sure we finally actually got this to work.
This is currently slated for v1.1.0 but if we can't get it reviewed before that it can come in v1.2.0