ddev: Prevent execution of `ddev config` in the wrong directory

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem?

The other day I was creating a new DDEV instance using the ddev composer create command.

I wasn’t concentrating (I know, bad move) and accidentally didn’t enter the folder I had just created for this purpose. These should have been the steps:

cd ~/dev
mkdir drupal10
cd drupal10
ddev config --auto
ddev composer create drupal/recommended-project

Except, I got distracted and skipped the cd drupal10 step …

I quickly hit “Enter” through the prompts from the ddev config and ddev composer create commands, which looked all right. But since I wasn’t in ~/dev/drupal10, but instead in the ~/dev folder, where all my projects are (around 15) they were almost all deleted, until the process got stopped by a write-only folder.

Yes I know, I should have double checked the prompts.

Describe your solution

It would be awesome if it was possible to designate folders, where DDEV will gladly run project commands such as ddev composer create (i.e. those where you can get a could not find a project message) and reject them elsewhere. ddev list and similar commands which doesn’t alter anything should still be allowed from any folder.

We only need to check for ddev config, since without a .ddev sub-folder present, no file altering commands will run, but simply return a “Failed to get project(s): could not find a project in /home/username.”.

For example, I only ever run DDEV commands in project sub-folders within a development folder called ~/dev (/home/username/dev), such as /home/username/dev/drupal10.

So a rule could be, to only allow DDEV to execute file altering commands in sub-folders of ~dev with the pattern /home/username/dev/*.

Meaning: Only allow running ddev config from for example /home/username/dev/drupal10

Everywhere else, for example /home/username/dev or /home/username you get a message like this:

You can only run ddev config to start new DDEV projects from /home/username/dev/projectname

Defining the rule in plain speech: “Only allow running ddev config from these folders”. Since there can be more than one, it should probably be an array, like this:

allow_ddev_config: ["/home/rfay/workspace/*", "/tmp/*"]

How it could look in .ddev/global_config.yaml:

# Only allow running ddev config from these folders
# Separate multiple values with comma, quoted
# allow_ddev_config: ["/home/username/workspace/*", "/tmp/*"]

The ddev config command already checks if it is run from the home folder, which it doesn’t allow and returns the message “could not create new config: ddev config is not useful in your home directory (/home/username)”.

https://github.com/ddev/ddev/blob/master/pkg/ddevapp/config.go#L67-L70

Maybe the allow_ddev_config setting can be added similarly?

Describe alternatives

No response

Additional context

No response

About this issue

  • Original URL
  • State: open
  • Created 8 months ago
  • Reactions: 1
  • Comments: 42 (24 by maintainers)

Commits related to this issue

Most upvoted comments

I still feel strongly about the above, and I have another suggestion which you will probably hate (or not 😃):

  1. add a ddev init command that’s pretty much ddev config but without the warning and that you can only run it on a directory where there’s not a previously init ddev project. This can be run anywhere.
  2. I would like to have ddev config only work for already init configs (same as npm config), that would default to the closest project in up in the tree and not allow for creating new projects with this. So if you no ddev project is found upwards, you can say something like: There’s no project found to config, please run ddev init to set one up.

If you don’t like two as it means changing something so hardcoded in ddev mindset you can continue to leave it as is and allow both commands to co-exist for some time but update the docs to refere to this new command for new projects.

If you do 2, however, you are, by escence, fixing this issue, you cannot run ddev config in the wrong directory anymore.

@gitressa let’s keep this one open as I think it’s still valid as far what @rfay steered it to. For that matter, I would expect this to work pretty much like npm:

  • npm install will apply to the closest parent package-json.lock
  • npm init can still be run inside a subdirectory

So I would do the same here:

  • allow ddev config to run inside subdirectories of parent projects you can maybe add a warning, or at most a prompt, but I think whatever you do, it’s not destructive so you can easily delete, again, same as npm init or git init
  • consider the project root the closest config.yaml in the tree, not the further away.

@gitressa if you can give #5499 a try that’d be awesome.

I am working on a PR

I have done this many times. I do it in the ~/workspace/ddev folder periodically because I’m working on DDEV code and am in the wrong window. My problem is typically doing it with ddev config in the wrong directory. Also, ddev config will create a project in a subdirectory of a project that already exists in some situations, which is also annoying. However, I’m not sure how to actually deal with it appropriately. I create projects in ~/workspace/* and ~/tmp/* sometimes. I don’t ever want to create one in ~/workspace or ~/tmp, always in a subdirectory, but never in ~/workspace/ddev.

More thoughts about how this would work? I don’t think we could encourage most of the people that need it to use it, and experienced users already know exactly what happened, and novices wouldn’t know how to configure it…

If you use ddev config in a subdirectory of a project it checks things,

$ ddev config --auto
it usually does not make sense to `ddev config` in a subdirectory of an existing project. Is it possible you wanted to `ddev config` in parent directory /Users/rfay/workspace/d10?

But sometimes you don’t see that and don’t realize that your config didn’t work.