wp-cli / ideas

💡 Ideas and feature requests are collected here
40 stars 1 forks source link

Use `mysql` through SSH #52

Open schlessera opened 7 years ago

schlessera commented 7 years ago

Right now, people using Docker have trouble setting up WP-CLI correctly. They either need to install the mysql on their web server as well (instead of only on their database server), or use a separate WP-CLI container altogether.

I was now thinking that it might be possible to allow for a configuration setting that defines an SSH connection to use for the mysql binary. So, instead of blindly running mysql locally, WP-CLI could check whether there's such a configuration setting, and then first log into the actual database server that the SSH settings are pointing to and then run the mysql binary from that database server.

I'm not 100% clear on whether this would all techincally work, but it would certainly be worth some time to investigate.

schlessera commented 7 years ago

The real fix would be to replace the mysql binary with mysqli or PDO, of course, but for some of the commands we're using, this is not a small task.

danielbachhuber commented 7 years ago

So, instead of blindly running mysql locally, WP-CLI could check whether there's such a configuration setting, and then first log into the actual database server that the SSH settings are pointing to and then run the mysql binary from that database server.

A couple of questions:

  1. Does Docker typically permit SSH connections to database containers? And, how is this less-complex of a solution than installing mysql on the web container?
  2. Could the same solution be achieved by aliasing mysql to a SSH connection string?
miya0001 commented 7 years ago

how is this less-complex of a solution than installing mysql on the web container?

I read those issues but I have same question. If I want to use wp-cli in a docker container, I always write dockerfile like following.

RUN apt-get update -y && apt install mysql -y \
         su -l ubuntu bash -lc 'wp core download ...' \
         su -l ubuntu bash -lc 'wp config create ...' \

Or run

$ docker run -idt -p 80:80 -p 443:443 ...
$ docker exec --user ubuntu --tty example.com env TERM=xterm apt install xxxx"

It looks easier than refactoring wp-cli.

I don't have many experience with docker, so I want to know the problem if we install mysql client into docker container.

schlessera commented 7 years ago

Does Docker typically permit SSH connections to database containers?

I'm not sure, that's why I wanted to investigate this.

how is this less-complex of a solution than installing mysql on the web container?

It's not so much about complexity, but more about the principles behind containers. If you install database drivers on your web server container, it partially defeats the purpose of using containers in the first place. So, while there are working solutions right now, none of them really fits within the way containers should work.

Could the same solution be achieved by aliasing mysql to a SSH connection string?

I guess if the first question can be answered with "yes", then this one will be the same.

roopemerikukka commented 7 years ago

If you are running the wp-cli inside alpine container you only need to install mysql-client which only takes 4kB when installed.