Skip to content

Remove workspace and support cmds run from current working directory - #65

Merged
tannerjfco merged 15 commits into
ddev:masterfrom
tannerjfco:workdir
Mar 14, 2017
Merged

tannerjfco merged 15 commits into
ddev:masterfrom
tannerjfco:workdir

Conversation

@tannerjfco

@tannerjfco tannerjfco commented Mar 13, 2017 •

Copy link
Copy Markdown
Contributor

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:

  • It removes the remainder of the global config functionality and concept of environment.
  • It introduces a new .ddev folder 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.
  • Introduces a new $HOME/.ddev folder that contains the router's docker-compose.yml
  • Determines activeApp by checking the current working directory for a ddev.yaml file, 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.yaml file 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 .ddev folder. 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.

@tannerjfco tannerjfco added this to the v0.1 milestone Mar 13, 2017
@rfay

rfay commented Mar 14, 2017

Copy link
Copy Markdown
Member

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
rfay requested review from beeradb and rfay March 14, 2017 18:40

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

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

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.

Comment thread cmd/ddev/cmd/dev_exec.go Outdated
var LocalDevExecCmd = &cobra.Command{
Use: "exec [app_name] [environment_name] '[cmd]'",
Use: "exec '[cmd]'",
Short: "run a command in an app container.",

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 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 :)

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.

Suggest: "Execute a Linux command in the nginx container"

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.

Slight alternate: "Execute a Linux shell command in the webserver container"

Comment thread cmd/ddev/cmd/dev_exec.go
}
app.SetOpts(opts)

nameContainer := fmt.Sprintf("%s-%s", app.ContainerName(), serviceType)

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

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.

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.

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'd recommend moving that to a label. Feels unnecessary to cram it in here, though.

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.

i'll make a follow-up ticket

Comment thread cmd/ddev/cmd/dev_exec.go

cmdArgs := []string{
"-f", path.Join(app.AbsPath(), "docker-compose.yaml"),
"-f", path.Join(app.AbsPath(), ".ddev", "docker-compose.yaml"),

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.

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.

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

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.

Comment thread cmd/ddev/cmd/dev_restart.go Outdated
}

color.Cyan("Successfully restarted %s %s", activeApp, activeDeploy)
color.Cyan("Successfully restarted %s", activeApp)

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.

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 :)

Comment thread cmd/ddev/cmd/dev_restart.go Outdated
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)

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.

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)

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 "production" is just temporary? If so, that's OK. I'd like to lose those things completely pretty quickly.

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.

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")

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.

Need to refactor this into getComposePath() or something, no need to repeat these lines of code all the time.

@beeradb beeradb Mar 14, 2017 •

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

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.

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)

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.

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"))

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.

Again, need function to build path for docker-compose.yaml

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

// 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)))

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 becomes irrelevant since we're creating the subdirs below right? Can just use os.MkDirAll on them? Doesn't do any harm here though.

Comment thread cmd/ddev/cmd/dev_exec.go Outdated
var LocalDevExecCmd = &cobra.Command{
Use: "exec [app_name] [environment_name] '[cmd]'",
Use: "exec '[cmd]'",
Short: "run a command in an app container.",

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.

Suggest: "Execute a Linux command in the nginx container"

Comment thread cmd/ddev/cmd/dev_exec.go
opts := platform.AppOptions{
Name: activeApp,
Environment: activeDeploy,
Name: activeApp,

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

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.

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.

@beeradb beeradb Mar 14, 2017 •

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.

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.

Comment thread cmd/ddev/cmd/dev_exec.go
}
app.SetOpts(opts)

nameContainer := fmt.Sprintf("%s-%s", app.ContainerName(), serviceType)

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'd recommend moving that to a label. Feels unnecessary to cram it in here, though.

Comment thread cmd/ddev/cmd/dev_exec.go

cmdArgs := []string{
"-f", path.Join(app.AbsPath(), "docker-compose.yaml"),
"-f", path.Join(app.AbsPath(), ".ddev", "docker-compose.yaml"),

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

Comment thread cmd/ddev/cmd/dev_exec.go Outdated
}

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]'")

@beeradb beeradb Mar 14, 2017 •

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.

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?

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.

There is a PersistentPreRun that satisfies the need you described. I think this PreRun should just go away at this point actually.

Comment thread cmd/ddev/cmd/dev_restart.go Outdated
SkipYAML: skipYAML,
CFG: cfg,
Name: activeApp,
SkipYAML: skipYAML,

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 can probably live without doing it this second, but I don't believe skipYaml has a purpose anymore.

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.

Also OK to get rid of it now while it's in front of us.

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

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`.")

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 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 :)

Comment thread cmd/ddev/cmd/dev_ssh.go
// LocalDevSSHCmd represents the ssh command.
var LocalDevSSHCmd = &cobra.Command{
Use: "ssh [app_name] [environment_name]",
Use: "ssh",

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 also see the validity of this.

Comment thread cmd/ddev/cmd/dev_stop.go
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())

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.

Suggestion: perhaps get a list of container IDs still running (based on the name label) and give them the correct docker rm command?

Comment thread cmd/ddev/cmd/root.go
}
if activeApp == "" {
log.Fatalln("No app name found. app_name and deploy_name are expected as arguments.")
func setActiveApp() {

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 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)
}
},

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.

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?

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