Skip to content

Add ddev config command - #63

Merged
beeradb merged 44 commits into
ddev:masterfrom
beeradb:57-ddev-config
Mar 17, 2017
Merged

beeradb merged 44 commits into
ddev:masterfrom
beeradb:57-ddev-config

Conversation

@beeradb

@beeradb beeradb commented Mar 13, 2017 •

Copy link
Copy Markdown
Contributor

The Problem:

The problem is outlined in #57

The Fix:

This introduces a ddev config command. It still requires an app-name and env-name, but those values are not used. The need for them should be removed alongside the working-directory based changes that are coming.

The Test:

This changes (and relies) on container labels, so any existing ddev sites you have running should be stopped/removed.

  1. Compile the binary
  2. Check out a Drupal or wordpress codebase. Example: https://github.com/newmediadenver/drud-d8
  3. Run ddev config from the repository root directory.
  4. If you run the config again, it should default to the values already in the config.yaml
  5. If your docroot contains D7/D8/wordpress source code, the app type should default.
  6. If you docroot does not exist, you should be notified of that via a prompt.
  7. Run ddev start

Also worth noting, I went pretty heavy on DRUD_DEBUG output (maybe too heavy). Enabling it will show you lots about what is happening internally, but it can be very distracting.

Automation Overview:

There is no automation at the time of opening this PR. This absolutely need automation before merging.

Related Issue Link(s):

#57

@rfay

rfay commented Mar 13, 2017 •

Copy link
Copy Markdown
Member

Gave it a quick spin.

  • docroot relative or absolute or? Is there a way to say "docroot is right here" or something? I put '.' in there and it took it but not sure what the results of that will be. One of the problems with this is that there's no way to tell what you're up to at the time, and it's not clear whether relative paths are allowed, etc.
  • IMO 'version' should be cfg_format_version or something that implies it's talking about the yaml version.

@beeradb

beeradb commented Mar 14, 2017 •

Copy link
Copy Markdown
Contributor Author

@rfay "version" was stolen from docker-compose. Of course, that doesn't make it automatically right. It may even make it more confusing!

Potential alternatives:

  • config-version
  • APIVersion
  • cfg-version

And probably 1000 others. I'm not too partial to any of them. Generally, I prefer dashes to underscores, but I'm not sure I have a valid reason even for that..

@rfay

rfay commented Mar 14, 2017

Copy link
Copy Markdown
Member

I'd vote for APIVersion.

@beeradb

beeradb commented Mar 16, 2017 •

Copy link
Copy Markdown
Contributor Author

This still needs tests before merge, but as it's a big (and important) change, I'd love a smoketest from both a code perspective (from @tannerjfco or @rfay), and a functional perspective (cc @rickmanelius) before starting down that path. Testing instructions are up to date.

Just wanna make sure we all agree it's close to the mark.

@tannerjfco

Copy link
Copy Markdown
Contributor

config cmd worked great for me, but I hit the following error trying to run start after:

DEBU[0002] Command Result                                Result=The Compose file '/Users/tannerjfco/sites/drud-d8/.ddev/docker-compose.yaml' is invalid because:
Invalid service name 'local-${DDEV_SITENAME}-web' - only [a-zA-Z0-9\._\-] characters are allowed

@tannerjfco tannerjfco 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.

This mostly seems to work for me. Great work!

I did encounter some unexpected behavior with ddev rm, though removal still succeeded. Looks like the env vars aren't getting set:

tannerjfco sites/drud-d7 ‹staging*› » ddev rm
DEBU[0000] Starting Config Read                          Existing config={
  APIVersion: "1",
  Name: "",
  AppType: "",
  Docroot: "",
  WebImage: "drud/nginx-php-fpm7-local:0.2.0",
  DBImage: "drud/mysql-docker-local-57:v0.2.0",
  ConfigPath: "/Users/tannerjfco/sites/drud-d7/.ddev/config.yaml",
  AppRoot: "/Users/tannerjfco/sites/drud-d7",
  Platform: "local"
}
DEBU[0000] Finished config read                          Existing config={
  APIVersion: "1",
  Name: "drud-d7",
  AppType: "drupal7",
  Docroot: "docroot",
  WebImage: "drud/nginx-php-fpm7-local:0.2.0",
  DBImage: "drud/mysql-docker-local-57:v0.2.0",
  ConfigPath: "/Users/tannerjfco/sites/drud-d7/.ddev/config.yaml",
  AppRoot: "/Users/tannerjfco/sites/drud-d7",
  Platform: "local"
}
WARNING: The DDEV_SITENAME variable is not set. Defaulting to a blank string.
WARNING: The DDEV_WEBIMAGE variable is not set. Defaulting to a blank string.
WARNING: The DDEV_URL variable is not set. Defaulting to a blank string.
WARNING: The DDEV_DOCROOT variable is not set. Defaulting to a blank string.
WARNING: The DDEV_APPROOT variable is not set. Defaulting to a blank string.
WARNING: The DDEV_HOSTNAME variable is not set. Defaulting to a blank string.
WARNING: The DDEV_DBIMAGE variable is not set. Defaulting to a blank string.
ERROR: Service 'local-drud-d7-web' depends on service 'local--db' which is undefined.
INFO[0000] Running Command                               Command=docker stop 667db801f10c9914f00e7aba13dc811bdf69cd35e02add022e9f637e27101112
DEBU[0011] Command Result                                Result=667db801f10c9914f00e7aba13dc811bdf69cd35e02add022e9f637e27101112

INFO[0011] Running Command                               Command=docker rm 667db801f10c9914f00e7aba13dc811bdf69cd35e02add022e9f637e27101112
DEBU[0011] Command Result                                Result=667db801f10c9914f00e7aba13dc811bdf69cd35e02add022e9f637e27101112

INFO[0011] Running Command                               Command=docker stop cbc5115b1076f47a9dc5bd4a70247d2080fdaf872763fa1d6d8295530f6bce5f
DEBU[0014] Command Result                                Result=cbc5115b1076f47a9dc5bd4a70247d2080fdaf872763fa1d6d8295530f6bce5f

INFO[0014] Running Command                               Command=docker rm cbc5115b1076f47a9dc5bd4a70247d2080fdaf872763fa1d6d8295530f6bce5f
DEBU[0014] Command Result                                Result=cbc5115b1076f47a9dc5bd4a70247d2080fdaf872763fa1d6d8295530f6bce5f

Successfully removed the drud-d7 application.

I hit a similar issue with ddev logs, in this case the command fails with no helpful information beyond the warnings seen above for dddev rm.

Comment thread pkg/ddevapp/config.go
defaultLocations := map[string]string{
"scripts/drupal.sh": "drupal7",
"core/scripts/drupal.sh": "drupal8",
"wp": "wordpress",

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'll need a better check for wp - this one would only work for newmedia wp repos

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.

Well dang. you are correct.

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 sure we can provide a foolproof check for this w/ a simple path check. We could easily search for one of the wp- prefixed files, but if a codebase has moved core to its own folder, that folder could be named anything. I think we could check for maybe wp-activate.php and call it a day. The user can still manually define it if detection fails.

Comment thread pkg/ddevapp/templates.go
container_name: {{ .plugin }}-${DDEV_SITENAME}-web
image: $DDEV_WEBIMAGE
volumes:
- "{{ .docroot }}/:/var/www/html/docroot"

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 we make this /var/www/html now, or rename from docroot? my concern is if a user had a differently named docroot like htdocs, if they were to run an ssh cmd i could see them potentially becoming disoriented.

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.

Agree we should do it. Wanna make a case for why it should be now? :)

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.

it can wait

appName := label["com.drud.site-name"]
appType := label["com.drud.app-type"]
containerType := label["com.drud.container-type"]
appName := label["com.ddev.site-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.

if we follow the documented recommendation, these should use a real domain that we own:

Authors of third-party tools should prefix each label key with the reverse DNS notation of a domain they own, such as `com.example.some-label`.

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.

But... ddev.com is available for only $10,000 !!!

}).Debug("Setting DockerEnv variable")

err := os.Setenv(k, v)
// @ TODO: I have no idea what a Setenv error would even look like, so I'm not sure what

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 certain there's anything more to do here - i figure if we can't set an env var something really weird must be going on, and there are bigger problems to solve. perhaps we should fatal in that case and call it a day?

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.

Basically, we need a standard way of handling errors-that-cant-happen, instead of the standard oh-so-wordy golang metaphor. Agreed this doesn't need handling. _ = os.Setenv() would be OK.

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.

However, despite both these comments, thanks for noting and handling and reporting errors!

Status string
}

// AppOptions ..

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.

glad to see this go, along w/ the rest of the clean up here

Comment thread pkg/ddevapp/config.go
const DDevDefaultPlatform = "local"

// DDevTLD defines the tld to use for DDev site URLs.
const DDevTLD = "ddev.local"

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.

TLD++


// DockerEnv sets environment variables for a docker-compose run.
func (l LocalApp) DockerEnv() {
envVars := map[string]string{

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.

what's the motivation behind using env vars for this data?

@tannerjfco

Copy link
Copy Markdown
Contributor

A couple questions/comments:

  1. With this change, are we expecting that the docker-compose.yaml would be committed to the repo? I had envisioned that this would be a config file we maintain control over, populating w/ info defined by config.yaml and the future ddev-compose.yaml.
  2. This is currently writing out webimage/dbimage configuration for every site. I feel like this should be an optional configuration to define if a user needs to pin a specific image or provide a custom image.

My concern is if we require these configurations and have users commit them to repos, that they would have to update that configuration any time we pushed an update. This is manageable for a small number of sites, but not as much for a large number of sites.

@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 had a problem doing an install.php on drud-d7 (staging). In the second step of the install.php it redirected to the wrong hostname - http://local-drud-d7/install.php?profile=standard - and that got a 503. I imagine that's because the old hostname formula is still embedded in there somewhere?

Comment thread cmd/ddev/cmd/dev_exec.go
"-f", app.DockerComposeYAMLPath(),
"exec",
"-T", nameContainer,
}

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 the DockerComposeYAMLPath() but would prefer to see the whole docker compose command execution packaged as a function.

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.

agreed. There's a lot of things (like this) that would have been nice to do, but this PR was already pretty big and we have less test coverage than would be ideal.

If we think important enough to do now I'm happy to do it, but I tried to avoid rewriting more than I had to.

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 by me, but thanks for getting the DockerComposeYAMLPath() in!

appName := label["com.drud.site-name"]
appType := label["com.drud.app-type"]
containerType := label["com.drud.container-type"]
appName := label["com.ddev.site-name"]

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.

But... ddev.com is available for only $10,000 !!!

@beeradb

beeradb commented Mar 17, 2017

Copy link
Copy Markdown
Contributor Author

@rfay could your error have been because an existing settings.php was in place from a previous install or import?

That is a bit of weirdness in the way we are currently doing things that I had noticed. If you have previously installed and are using the same codebase, you would need to remove it.

@rfay

rfay commented Mar 17, 2017

Copy link
Copy Markdown
Member

Yes, the existing settings.php will be the problem - the existing settings.php has that hostname in it. And drupal 7's .gitignore (which I am probably responsible for) ignores settings.php. I knew I had a clean repo... but didn't remember that.

@rfay

rfay commented Mar 17, 2017

Copy link
Copy Markdown
Member

I was able to bring up a site where the docroot was the main dir by leaving docroot empty. That results in the var being set correctly. It's not very intuitive of course.

In the process of learning that I tried a rooted docroot - that doesn't work at all (and I would think it should). I think a relative path is fine, but most command-line type apps know the difference between a relative path and a rooted full path. So if you put in /Users/rfay/workspace/d7git for the docroot, it will not go well.

@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.

ddev logs seems to be broken, see https://gist.github.com/rfay/8e683d66092021310ca4a023a20f92ca - I thought it was working before.

ddev config says it has flags in the --help but there are none that I can find.

@beeradb

beeradb commented Mar 17, 2017 •

Copy link
Copy Markdown
Contributor Author

@rfay I took a stab at the docroot change:

ddev needs to know where your site files exist. This is a relative directory path from your application root (/Users/username/Projects/drupal8)
You may leave this value blank if your site files are in your application root
Docroot Location (docroot):

Thoughts?

@beeradb

beeradb commented Mar 17, 2017

Copy link
Copy Markdown
Contributor Author

To close the loop, here's what we ended up going with for now:

The docroot is the directory from which your site is served. This is a relative path from your application root (/Users/username/Projects/drupal8)
You may leave this value blank if your site files are in the application root
Docroot Location:

@beeradb

beeradb commented Mar 17, 2017

Copy link
Copy Markdown
Contributor Author

🎉 🎈

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.

5 participants