Repository navigation
Remove workspace and support cmds run from current working directory - #65
Conversation
|
Just a question: "Introduces a new $HOME/.ddev folder that contains the router's docker-compose.yml" - Why is that global-ish instead of in the repo's .ddev/ ? |
rfay
left a comment
There was a problem hiding this comment.
Nice work - starting code review shortly. Probably worth cleaning up ddev list to say "stopped" and remove the database URL or do something with it besides :0 - just so you have something to do while us slackers catch up.
$ ddev list
2 local sites found.
NAME TYPE URL DATABASE URL STATUS
drud-d7 http://local-drud-d7 127.0.0.1:0 exited
drud-d8 http://local-drud-d8 127.0.0.1:0 exited
rfay
left a comment
There was a problem hiding this comment.
Great stuff, I made lots of comments but you'll have to figure out how much is actionable. There's some stuff that you inherited that can definitely be cleaned up now... or later.
| var LocalDevExecCmd = &cobra.Command{ | ||
| Use: "exec [app_name] [environment_name] '[cmd]'", | ||
| Use: "exec '[cmd]'", | ||
| Short: "run a command in an app container.", |
There was a problem hiding this comment.
I think we'll want @rickmanelius (or somebody) to go through all the help and make it more accessible. Probably later in the cycle. But "Run a command in an app container" doesn't do it for me :)
There was a problem hiding this comment.
Suggest: "Execute a Linux command in the nginx container"
There was a problem hiding this comment.
Slight alternate: "Execute a Linux shell command in the webserver container"
| } | ||
| app.SetOpts(opts) | ||
|
|
||
| nameContainer := fmt.Sprintf("%s-%s", app.ContainerName(), serviceType) |
There was a problem hiding this comment.
I'm not sure that this type of naming ('local-drud-d7-web') isn't going to bite us as we go forward. Just mentioning it for conversation. The 'local' sure doesn't add anything from the user's perspective. I understand how it fits from a platform plugin perspective.
There was a problem hiding this comment.
The plugin prefix is currently used to determine which docker containers relate to a site managed by ddev. Specifically, the ddev list functionality uses it to find and sort the sites by plugin.
There was a problem hiding this comment.
I'd recommend moving that to a label. Feels unnecessary to cram it in here, though.
There was a problem hiding this comment.
i'll make a follow-up ticket
|
|
||
| cmdArgs := []string{ | ||
| "-f", path.Join(app.AbsPath(), "docker-compose.yaml"), | ||
| "-f", path.Join(app.AbsPath(), ".ddev", "docker-compose.yaml"), |
There was a problem hiding this comment.
Does there happen to be a docker compose golang API that we can use instead of the shelling technique? Probably no reason to change now, but shelling out is awfully fragile in the long run.
There was a problem hiding this comment.
This probably requires more thought moving forward. Any package we bring in to deal with this would also bring in a whole ton of dependencies. In that respect, having binaries as boundaries is nice. It does break portability, though.
There was a problem hiding this comment.
| } | ||
|
|
||
| color.Cyan("Successfully restarted %s %s", activeApp, activeDeploy) | ||
| color.Cyan("Successfully restarted %s", activeApp) |
There was a problem hiding this comment.
Since we're here, let's use the cmd.Success() call instead of explicit colors. I know it's not part of the scope, but because you changed the line it stands out :)
| color.Cyan("Successfully restarted %s %s", activeApp, activeDeploy) | ||
| color.Cyan("Successfully restarted %s", activeApp) | ||
| if siteURL != "" { | ||
| color.Cyan("Your application can be reached at: %s", siteURL) |
There was a problem hiding this comment.
Another cmd.Success() opportunity.
| name := fmt.Sprintf("%[2]s-%[1]s.tar.gz", l.Name, l.Environment) | ||
| basePath := path.Dir(l.AbsPath()) | ||
| archive := path.Join(basePath, name) | ||
| name := fmt.Sprintf("production-%s.tar.gz", l.Name) |
There was a problem hiding this comment.
This "production" is just temporary? If so, that's OK. I'd like to lose those things completely pretty quickly.
There was a problem hiding this comment.
yep, that should go once we get the real import functionality sorted out
| // Stop initiates docker-compose stop | ||
| func (l LocalApp) Stop() error { | ||
| composePath := path.Join(l.AbsPath(), "docker-compose.yaml") | ||
| composePath := path.Join(l.AbsPath(), ".ddev", "docker-compose.yaml") |
There was a problem hiding this comment.
Need to refactor this into getComposePath() or something, no need to repeat these lines of code all the time.
There was a problem hiding this comment.
It's debatable over where this should go, but this exists in the PR I am working on. https://github.com/drud/ddev/pull/63/files#diff-6b915643e9cbdc33eb603fff31b61280R156
If we're happy with it at the appconfig level, we can just wait on it and make the change after rebasing that PR. We'd have to export the function, of course.
There was a problem hiding this comment.
I would be down with a follow-up to leverage that function. We may want to consider a docker pkg for this as well as docker-related functionality currently dumped in platform/utils.go, but ultimately i'm not opposed to this being in appconfig either.
| ".ddev/data", | ||
| } | ||
| for _, d := range dirs { | ||
| dirPath := path.Join(base, d) |
There was a problem hiding this comment.
Don't we still need to create these directories? And if we mkdir them, we don't have to both with the base, right?
| basePath := app.AbsPath() | ||
|
|
||
| f, err := os.Create(path.Join(basePath, "docker-compose.yaml")) | ||
| f, err := os.Create(path.Join(basePath, ".ddev", "docker-compose.yaml")) |
There was a problem hiding this comment.
Again, need function to build path for docker-compose.yaml
|
|
||
| // PrepLocalSiteDirs creates a site's directories for local dev in ~/.drud/client/site | ||
| func PrepLocalSiteDirs(base string) error { | ||
| err := os.MkdirAll(base, os.FileMode(int(0774))) |
There was a problem hiding this comment.
This becomes irrelevant since we're creating the subdirs below right? Can just use os.MkDirAll on them? Doesn't do any harm here though.
| var LocalDevExecCmd = &cobra.Command{ | ||
| Use: "exec [app_name] [environment_name] '[cmd]'", | ||
| Use: "exec '[cmd]'", | ||
| Short: "run a command in an app container.", |
There was a problem hiding this comment.
Suggest: "Execute a Linux command in the nginx container"
| opts := platform.AppOptions{ | ||
| Name: activeApp, | ||
| Environment: activeDeploy, | ||
| Name: activeApp, |
There was a problem hiding this comment.
I'm assuming the long-term goal is probably to get rid of this? once the config work is done the name should probably come from there.
There was a problem hiding this comment.
I would actually think it remains, as we will still need a way to determine the config file to read in, which means we would likely still need a function like setActiveApp.
There was a problem hiding this comment.
Sort of. We'll need to determine the application root. From there we can read the config and get things like the site name. So we actually need something close to an ActiveSiteRoot (or perhaps l.AbsPath() from the local plugin). Happy to tackle that in my PR, though.
| } | ||
| app.SetOpts(opts) | ||
|
|
||
| nameContainer := fmt.Sprintf("%s-%s", app.ContainerName(), serviceType) |
There was a problem hiding this comment.
I'd recommend moving that to a label. Feels unnecessary to cram it in here, though.
|
|
||
| cmdArgs := []string{ | ||
| "-f", path.Join(app.AbsPath(), "docker-compose.yaml"), | ||
| "-f", path.Join(app.AbsPath(), ".ddev", "docker-compose.yaml"), |
There was a problem hiding this comment.
This probably requires more thought moving forward. Any package we bring in to deal with this would also bring in a whole ton of dependencies. In that respect, having binaries as boundaries is nice. It does break portability, though.
| } | ||
|
|
||
| Failed("Invalid arguments detected. Please use a command in the form of: exec [app_name] [environment_name] '[cmd]'") | ||
| Failed("Invalid arguments detected. Please use a command in the form of: ddev exec '[cmd]'") |
There was a problem hiding this comment.
Shouldn't this prerun actually be adjusted to ensure there's a ddev.yaml in the current or parent path? And then this specific warning changed to warn if there's not?
There was a problem hiding this comment.
There is a PersistentPreRun that satisfies the need you described. I think this PreRun should just go away at this point actually.
| SkipYAML: skipYAML, | ||
| CFG: cfg, | ||
| Name: activeApp, | ||
| SkipYAML: skipYAML, |
There was a problem hiding this comment.
I can probably live without doing it this second, but I don't believe skipYaml has a purpose anymore.
There was a problem hiding this comment.
Also OK to get rid of it now while it's in front of us.
|
|
||
| if !platform.ComposeFileExists(app) { | ||
| Failed("No docker-compose yaml for this site. Try `dev add`.") | ||
| Failed("No docker-compose yaml for this site. Try `ddev start`.") |
There was a problem hiding this comment.
I realize you inherited this and it already had this output/behavior, but as a followup we may want to consider fixing the messaging here. If a user is trying to remove something and no docker-compose.yaml exists, telling them to run ddev start might be bad advice :)
| // LocalDevSSHCmd represents the ssh command. | ||
| var LocalDevSSHCmd = &cobra.Command{ | ||
| Use: "ssh [app_name] [environment_name]", | ||
| Use: "ssh", |
There was a problem hiding this comment.
I also see the validity of this.
| if err != nil { | ||
| log.Println(err) | ||
| Failed("Failed to stop containers for %s. Run 'drud legacy list' to ensure your site exists.", app.ContainerName()) | ||
| Failed("Failed to stop containers for %s. Run `ddev list` to ensure your site exists.", app.ContainerName()) |
There was a problem hiding this comment.
Suggestion: perhaps get a list of container IDs still running (based on the name label) and give them the correct docker rm command?
| } | ||
| if activeApp == "" { | ||
| log.Fatalln("No app name found. app_name and deploy_name are expected as arguments.") | ||
| func setActiveApp() { |
There was a problem hiding this comment.
This is probably fine for now, but very very soon we're going to need a utility function which can be imported from our other packages to get the absolute path for the application.
| color.Cyan("Your application can be reached at: %s", siteURL) | ||
| Success("Your application can be reached at: %s", siteURL) | ||
| } | ||
| }, |
There was a problem hiding this comment.
So if siteURL is "" ... doesn't that mean we have a problem? Would there be a case where we had an empty siteURL that we wouldn't want to report?
The Problem:
Currently, ddev uses a predefined workspace location that it manages all sites in. We want end users to control their source checkouts, so ddev should work in a way that uses the current working directory to determine the application that commands should be run against.
The Fix:
This PR introduces the changes necessary for ddev to work in the manner described above:
.ddevfolder that is created per-site at the top-level of repo. This is where the docker-compose.yml and import-related directories now reside for a site.$HOME/.ddevfolder that contains the router's docker-compose.ymlddev.yamlfile, if it is not found it will check the parent directories until one is found or fail.The Test:
To test this change, I suggest using the following repos, or at least a repo whose codebase is contained within 'docroot' folder:
Any repo you test needs to have a
ddev.yamlfile at the root of the repo, even if it's just an empty file.Clone the desired repo to your desired location, cd into the source checkout, and run ddev commands. They should work! You do not need to specify sitename or environment for
If you want to test import, you can place the newmedia archive in the site's
.ddevfolder. Please note that "production" is now hardcoded for this file lookup since environment is removed, so your archive must be "production-[sitename].tar.gz"Automation Overview:
This needs tests.
Related Issue Link(s):
#47 - Original issue report.
Release/Deployment notes:
Does this affect anything else, or are there ramifications for other code? Does anything have to be done on deployment?
This dramatically changes how ddev is used, so there could be ramifications that have not yet been discovered or considered.