Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying target container for hook execution #1038

Closed
codemonkey1988 opened this issue Aug 7, 2018 · 5 comments · Fixed by #1634
Closed

Allow specifying target container for hook execution #1038

codemonkey1988 opened this issue Aug 7, 2018 · 5 comments · Fixed by #1634
Labels
Prioritized We expect to do this in an upcoming release

Comments

@codemonkey1988
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When you want to execute a hook in different container than the web container, you currently need to use the exec-host command an run ddev exec -s my-service my-command.

Describe the solution you'd like
It would be nice, if you could somehow specify the target container for the hook to execute.
One possible solution could be integrating the services name into the exec command.

Example:
When you got a service named node you can execute a hook in it by using exec-node. This solution would keep the current syntax. exec-host would stay as be special keyword and only exec would be the same as exec-web (it it might be an alias for compatibility.

The whole hook config could look like this:

hooks:
  post-start:
    exec: composer install -d /var/www/html
    exec-node: npm install
@rfay
Copy link
Member

rfay commented Aug 7, 2018

I think this is long-neglected but a really valid application. I wish our existing config language had a spot for the container name. It really allow something like:

hooks:
  post-start:
    exec:
      container: db
      command: mysql --version

@andrewfrench
Copy link
Contributor

This seems like a natural progression as people increasingly use custom containers, and I'd imagine there are some use cases for executing hooks on our existing non-web containers now.

On the back end, we already support exec-ing commands on arbitrary containers, but we'll need to decide on the front-end parsing and error handling specifics.

@codemonkey1988
Copy link
Contributor Author

@rfay Your solution would be the better one I think, but it would also be a breaking change for many people unless you keep the current syntax for compatibility. I don't know how you will handle breaking changes in stable releases, but this might annoy people when they have to update all their ddev projects with hooks.

@rfay rfay changed the title Allow to specify target container for hooks Allow specifying target container for hook execution Aug 9, 2018
@kristoftorfs
Copy link

@codemonkey1988 To be honest, I don't think keeping this backwards compatible is that hard. If the exec node is a string it's defined in the old way, if it's a hash it's the new way.

Is there any progress made on this? I literally have zero projects where I don't use custom services and this would be a major improvement.

@rfay rfay added the Prioritized We expect to do this in an upcoming release label Apr 26, 2019
@rfay
Copy link
Member

rfay commented Apr 26, 2019

Thanks for chiming in on this @kristoftorfs - Just an FYI about workarounds you probably already use... If the web container has access to the other service, then hooks can be executed against the web container and take action against another container. For example, since the web container has mysql access to the db container, you can add a hook that does a mysql command.

This would likely be a part of #1372, which is about the hook system in general.

rfay added a commit that referenced this issue Jun 24, 2019
…1038 (#1634)

* Switch to yaml v3
* Add composer task
* Add multiple pre- and post- hooks
* Allow exec hook to specify container to act on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Prioritized We expect to do this in an upcoming release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants