-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Feature request: Add docker exec to aliases remote #1910
Comments
you can connect via ssh-options. see http://wadmiraal.net/lore/2015/03/27/use-docker-to-kickstart-your-drupal-development/ and https://www.chapterthree.com/blog/drupal-development-docker-compose |
Running SSH server inside Docker container for using it’s shell is Jan Pobořil 2016-01-13 18:26 GMT+01:00 Moshe Weitzman [email protected]:
|
If you don't want to run SSH, then I suggest you put your alias file into the container and run |
Strongest use case for this feature request is sql-sync between containers. Jan Pobořil 2016-01-13 23:53 GMT+01:00 Moshe Weitzman [email protected]:
|
Yeah, its kind of hard to transfer data between environments that are deliberately so isolated from one another. Note that sql-sync has options available that you can use to script partial operations. See --no-dump --no-sync. With those, and drush_invoke_process() you can potentially compose a new command. |
Btw, it should be possible to do something like:
But it will be much harder to do it if containers are on different machines. |
Is this something like a Bastion server with docker being run inside a remote host accessed via ssh? Drush has commands for that, if that is indeed the case. Remote Operations on Drupal Sites via a Bastion Server |
sql-sync across containers is an interesting challenge. would love to see some discussion and/or code. |
This feels like a really easy thing to add which would reduce pain for people trying to use drush in docker based setups. We already have site aliases, so why not allow them to work with Docker, which is increasingly the direction infrastructure is moving? |
What exactly feels easy? I'm not sure what precisely is being requested. Is sql-sync across containers really the pain point? |
I apologize, Moshe. I should not have used the word easy, it was a poor word choice that likely belittles the work that would actually be involved. With that said, here is the use case I'm trying to solve. I've got a docker-compose based local development environment with (typically) two containers, nginx/php-fpm, and mysql. Because of the way docker-compose networking works, the DB URL/port is different from within the docker container and the host machine (db:3306 vs 127.0.0.1:32801, for example). If these were just local dev containers, I might just bite the bullet and break best practices by installing a SSH daemon within our containers. I wouldn't love it, but I'd probably live with it. In this case though, the nginx container being used is the same container as prod, so that's a non-starter. My best workaround right now is to check $_SERVER['argv'] and include a conditional drush.settings.php file which overrides the $databases variable (yuck) when drush is invoked. I could also (and do) include drush in the container, but the reality is that eventually, people are going to find something that causes them to want to change version of drush or upgrade faster than I can keep up, so at least being able to support native usage of drush would be a big win. I'd much prefer to do this with aliases over my fix. I realize most of what is being asked here is working around docker idiosyncracies, but at the same time, drupal sites are increasingly being ran in containers for both production and dev, and it feels like allowing that workflow to be a first class citizen for aliases would be a nice win. |
In the case I'm currently looking at, drupal is running under docker, which is managed by kubernetes. Ssh is nowhere in the command I want to run to fire drush remotely. I don't know which host(s) drupal is running on, and that will vary dynamically. Still, I can provide a command prefix that can be put before the drush command, and the remote drush will get run, with all the usual I/O streams hooked up. The parts of remote drush functionality I want most would be covered by being able to specify such a command prefix in a drush @alias. Being able to specify a wrapper script could probably do the same thing.
The value of 'remote-command' can be prepended to 'drush [drush args]' and most stuff will work fine. If support for setting environment variables was not there, I could use a wrapper script to get that, and call it in the same manner. I understand that there are some file copying operations that might not work this way. That's not an issue for me. I really want to be able to specify my manner if connection from within the alias, so I can have a heterogeneous collection of drupal instances accessed different ways, and still be able to do things like loop over aliases, connect to each drupal instance, and return info on outstanding security issues. |
I know this doesn't fix the aliasing problems, but if you're just tired of running |
Greg sketched out custom transports at #3017 (comment) |
I rather like the tiny shell script from @mortenson. Its not a replacement for transports, but it can be extended easily. |
As @mortenson says, it doesn't solve the alias problem. But lets get creative... maybe instead of putting an alternative Or instead of parsing the drushrc files, the ssh replacement/wrapper could recognise an extra option that we could pass via drush's ssh-options facility, and use that to substitute a different transport. hmm, actually that sounds like it might be what @greg-1-anderson was talking about with Drupal Console in #3017 (comment) |
We added a layer called 'Transports' No support for Docker yet but its getting closer if anyone is motivated. |
We'd need a docker transport to supplement the existing ssh transport; that would handle docker containers on the local machine. Then we'd also need another transport that would use the ssh transport and the docker transport to make an ssh+docker transport. |
@frederickjh This is good for a bastion, but it doesn't yet have instructions for a docker container running inside the destination host (after the bastion). From what I am reading, there isn't a solution to sync from a remote that is a container inside that host (even a workaround). Is that correct? My use case is trying to get a |
I'd be interested in working on this if you would want to mentor me in a video conference (which we could record and post back here) for 30-60 minutes giving me some direction and more understanding on what needs to be added to the Transport layer. I have a pressing need for this right now, and thus some motivation. |
The most important part of this is deciding how to extend transports. At the moment, the implementation is hardcoded to only allow local and ssh transports -- that is, if the alias is not local, then the ssh transport is hardcoded. See: https://github.com/consolidation/site-process/blob/master/src/SiteProcess.php#L97 The next level of goodness here would be to add a couple more transports (as suggested above), and use them if certain attributes exist in the alias. We'll want to consider this implementation carefully to ensure that we don't build anything too limiting. I've seen your name on a number of related ssh issues, so I think you'd be a good person to advise here. I have not designed a solution yet. A transport is just a class that wraps a commandline in some other commandline, e.g. making To implement a transport, just look at the existing one: https://github.com/consolidation/site-process/blob/master/src/Transport/SshTransport.php Not sure when I could hack on this, but please give it a try and ping me in slack if you get stuck. We can jump on a quick ad-hoc call if I have time. |
Thanks @greg-1-anderson, my immediate tasks have changed a bit to get something working for now, I'll reach out to you on Slack when I get to this. |
Hi @greg-1-anderson, are there any plans to rewrite RsyncCommands to use the TransportInterface? Currently the remote shell (-e / --rsh) option is hardcoded set to ssh and the ssh options. |
TransportInterface is for building commandlines for starting processes. ssh is one way to start a process. Rsync might also use ssh when copying files; however, the way that works is unrelated to TransportInterface. It's not a bad idea to allow rsync to use other options besides just ssh; however, that would be a separate effort. |
I will soon have a for for this issue.
|
Lets continue in #3835 |
…ainer (#3835) * Add support for site aliases that point into a Docker container * Update Composer for site-process and site-alias * Some infra for sql:sync under Docker transport * Update docs for new namespacing * Fix typo in docs. * React to slight change in AliasRecord::isRemote(). * Back out the sql:sync experiment. * Update composer/scenario files for consolidation releases
Currently it is able to execute remote drush by alias like this:
But today we run Drupal also in Docker container, so it is good to run Drush commands also inside it. It could be configured like this:
And also conbined to connect to server and there into container:
So we will be able to use it intuitively like this:
Workaround (how we have to to it today to sync into container):
The text was updated successfully, but these errors were encountered: