Skip to content

Add ddev describe command - #116

Merged
beeradb merged 18 commits into
ddev:masterfrom
beeradb:35-describe-command
Apr 6, 2017
Merged

beeradb merged 18 commits into
ddev:masterfrom
beeradb:35-describe-command

Conversation

@beeradb

@beeradb beeradb commented Mar 31, 2017 •

Copy link
Copy Markdown
Contributor

The Problem:

We need to add a ddev describe command which gives extended information about services which are running within a ddev application.

The Fix:

The resulting ddev describe command returns the following information about a site when run from within the document root:

newmedia/drupal8 ‹gke:drud-test› git:(master) » ddev describe
NAME   	DOCROOT                                         	TYPE   	URL                      	STATUS
drupal8	/Users/beeradb/Projects/newmedia/drupal8/docroot	drupal8	http://drupal8.ddev.local	running

MySQL Credentials
-----------------
Username:       	root
Password:       	root
Database name:  	data
Connection Info:	drupal8.ddev.local:3306

Other Services
--------------
MailHog:	http://drupal8.ddev.local:8025

It can also be run using the site name, as in ddev describe drupal8, from any path.

Additional work

As a part of these fixes, I also reworked application instantiation within cobra commands. Gone is the "activeApp" global. It's been replaced with a getActiveApp() which returns an initialized application, along with an error (if an active app can't be found). I also updated all instances of app instantiation to use this new method.

Additionally, all instances of app.Init() now require a path to the application root, as a string parameter. See https://github.com/drud/ddev/pull/116/files#diff-ef6770d9874ceccc0d1f5c859385f6feR36

Overall the goal was to make the process of getting the active application interface more consistent and less reliant on globals.

Automation Overview:

This has reasonably good test coverage as a starting point. Review the cmd/ddev/cmd/describe_test.go file. There are both binary based integration tests and unit tests.

Should we also test the describe method of the local platform struct (in pkg/platform/local.go?) or move some of the more unit-test related functionality there?

Related Issue Link(s):

#35

Release/Deployment notes:

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

@beeradb

beeradb commented Apr 3, 2017

Copy link
Copy Markdown
Contributor Author

Removed WIP but added needs docs. This is good to go from a functionality perspective, but probably still needs a few lines in the docs covering it.

@beeradb
beeradb requested a review from rickmanelius April 3, 2017 22:01
@rickmanelius

Copy link
Copy Markdown
Contributor

Testing Results

  • CD ./ddev
  • Checkout beeradb/ddev at 8903295
  • Run "make clean && make darwin"
  • Run "ddev list" to confirm site name "drupal8"
  • CD ./drupal8 w/.ddev already configuration
  • From within a working directory, run 'ddev describe'
  • Output pasted below
NAME   	DOCROOT                             	TYPE   	URL                      	STATUS
drupal8	/Users/MYUSERA/git/drupal8/docroot	drupal8	http://drupal8.ddev.local	running

MySQL Credentials
-----------------
Username:       	root
Password:       	root
Database name:  	data
Connection Info:	drupal8.ddev.local:3306

Other Services
--------------
MailHog:	http://drupal8.ddev.local:8025
  • Comparing against proposed output here As a developer, I want a describe command to provide connection/service info for a site #35 (comment), I see everything appears except for the phpMyAdmin service, which may or may not be available at this time.
  • I can confirm Mailhog is at the listed host:port
  • I can confirm that I can login to mysql via the host + credentials provided from within the container. By default, I don't have mysql installed outside the container, so I haven't fully verified these are working outside. But I am able to ddev ssh into the container, and then login to mysql using the username/password provided.
  • Running ddev stop and then ddev describe outputs 2017/04/04 08:54:46 Could not describe app: ddev site is configured but not currently running, which is a fair warning.
  • I have not tested on WordPress.
  • I can confirm it works outside of the working directory. For example, ddev describe drupal8 works when at ~/.

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

Added my review notes here instead of in this modal. #116 (comment)

@beeradb

beeradb commented Apr 4, 2017

Copy link
Copy Markdown
Contributor Author

Correct. My goal would be to add PHPMyAdmin/xdebug/whatever other info to this list as it lands. Considering the xdebug PR is currently open, this may also need to happen as a followup depending on ordering.

  • I can confirm that I can login to mysql via the host + credentials provided from within the container. By default, I don't have mysql installed outside the container, so I haven't fully verified these are working outside. But I am able to ddev ssh into the container, and then login to mysql using the username/password provided.

I did cheat a bit here. I believe we need to open up the port on the router to make this actually happen.

@rickmanelius

Copy link
Copy Markdown
Contributor

Noted on phpMyAdmin being in a separate ticket. Also I know the port/router was a nitpick only because, as an end-user receiving that information, I would expect to be able to use that directly from the command line. However. If that is not the case, then we probably need to provide information/instructions on how to use that information.

@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 would propose that our mysql description could be improved. This text is directly from the issue, but it would be cool if we could find a way to explain where the mysql server actually lives from an internal perspective (host named 'db') and also how to access it from an external perspective (currently mocked)

@beeradb

beeradb commented Apr 5, 2017

Copy link
Copy Markdown
Contributor Author

This text is directly from the issue, but it would be cool if we could find a way to explain where the mysql server actually lives from an internal perspective (host named 'db') and also how to access it from an external perspective (currently mocked)

Agreed. I'm not sure how to convey that, but it's something that gave me pause when adding this functionality. I'm open to any suggestions on how to better get that across. Ultimately I went w/ what I felt was the most common need of the user, but who knows if I hit the mark.

I actually wonder if we can make the hostname the same from both outside/inside the container. I may play w/ that this morning.

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

This works pretty nicely, and good work with the code. Thanks for the good effort. It's worth considering whether this would be the time to pioneer the non-binary-run testing technique.

Comment thread cmd/ddev/cmd/describe.go Outdated
// DescribeCommand represents the `ddev config` command
var DescribeCommand = &cobra.Command{
Use: "describe",
Short: "Get a detailed description about a running ddev 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.

s/about a running/of a running/

Comment thread cmd/ddev/cmd/describe.go
Short: "Get a detailed description about a running ddev site.",
Run: func(cmd *cobra.Command, args []string) {
if len(args) > 1 {
log.Fatal("Too many arguments detected. Please use `ddev describe` or `ddev describe [appname]`")

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 describe -h shows [flags] as an option, but there are none, right? Is there a way to fix that?

Comment thread cmd/ddev/cmd/describe.go
},
}

func describeApp(appName 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.

This is not a global, so automated tools are not flagging a required explanatory comment, but should we have one in general anyway? I'd be in favor.

Comment thread cmd/ddev/cmd/describe.go
labels := map[string]string{
"com.ddev.site-name": appName,
"com.ddev.container-type": "web",
}

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 general pattern looks like it will show up many places. Does it already? Can/should it be moved into a utility package?

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.

It is generalized in the platform package. Thus far, I believe that is the only place we need it. Happy to move it into a utils package if we need it elsewhere.

Comment thread cmd/ddev/cmd/describe_test.go Outdated

}

// TestDevLogs tests that the Dev logs functionality is working.

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 comment needs to be updated to be informational :) golint doesn't check _test.go so it didn't validate, sadly.

Comment thread cmd/ddev/cmd/rm.go Outdated
app.Init()
app, err := getActiveApp()
if err != nil {
log.Fatalf("Could not find an active ddev configuration, have you ran 'ddev config'?: %v", err)

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.

run

Comment thread cmd/ddev/cmd/start.go Outdated
app, err := getActiveApp()
if err != nil {
log.Fatalf("Could not initialize application: %v", err)
log.Fatalf("Could not find an active ddev configuration, have you ran 'ddev config'?: %v", err)

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.

run

Comment thread cmd/ddev/cmd/stop.go Outdated
app.Init()
app, err := getActiveApp()
if err != nil {
log.Fatalf("Could not find an active ddev configuration, have you ran 'ddev config'?: %v", err)

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.

run

return nil
}

// FindContainerByLabels takes a map of label names and values and returns any docker containers which match all labels.

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 generalization, thanks.

Comment thread pkg/plugins/platform/utils.go Outdated
}
}

return docker.APIContainers{}, fmt.Errorf("could not find containers which matched search criteria")

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 would be better if the search criteria were listed in the error.

Comment thread README.md
You can also see more detailed information about a site by running `ddev describe` or `ddev describe [site-name]`.

```
NAME DOCROOT TYPE URL STATUS

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 don't think we should output docroot here, but instead the root of the project possibly labeled as Location. Docroot is an important detail when it comes to what directory should be served, but I wouldn't consider it the location i want to jump to first when switching to a project. There can often be code or tools at the root of the repo that would be frequently interacted with, so I think its more useful and consistent to provide the root.

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.

@rickmanelius this is your purview I believe. Care to weigh in?

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 think project location is more valuable to an end-user as a means to know where to change the directory in order to be within scope for ddev commands that are not global.

Offline, it was suggested that perhaps we put both, but I think widening the terminal output wouldn't really be of benefit. My vote would be location and point to the top level directory.

Comment thread README.md
Username: root
Password: root
Database name: data
Connection Info: drupal8.ddev.local:3306

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 a bit of a confusing scenario, as port 3306 is valid within the compose network, but we actually expose a random port to the host system. If I attempted to connect w/ the provided credentials via mysql cli on the host machine, this would fail to connect. Ideally the port would be consistent inside and out of container, but I'm not sure how we would achieve that when each site would have a port to expose, and I don't believe we can change the internal port expose on the fly. It's not ideal to output 2 different connection options, but I think it's necessary in order to ensure we are providing connection info that will work for utilities regardless of whether they are on the host system or within the compose network.

@tannerjfco

Copy link
Copy Markdown
Contributor

Code looks great and works as advertised. Welcome improvements re: active app as well. 👍

@beeradb
beeradb force-pushed the 35-describe-command branch from 74cef71 to 65b012a Compare April 6, 2017 20:38
@beeradb

beeradb commented Apr 6, 2017

Copy link
Copy Markdown
Contributor Author

I believe I have responded to all the feedback on this, and if I can get an approval I would like to merge.

There is the outstanding issue of the mysql host name, but I have that working and will be opening a PR shortly. I'm comfortable moving forward w/ this as-is if others are but would understand if we want to wait until the mysql proxy PR is opened/merged first.

@rfay

rfay commented Apr 6, 2017

Copy link
Copy Markdown
Member

Go for it, @beeradb - thanks for the good work.

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