lavmeiker / capistrano-wpcli

Provides command line tools to facilitate Wordpress deploy.
MIT License
117 stars 34 forks source link

Option to use './wp-cli.phar' instead of 'wp' command? #18

Closed ezekg closed 9 years ago

ezekg commented 9 years ago

Some of my clients use shared hosting (Godaddy), so I'm not able to install the bin/ executable, unfortunately. Is there a option I can use to execute a local ./wp-cli.phar file instead? If not, would you be interested in a pull request?

ezekg commented 9 years ago

I was able to work around it by writing a small bash script that falls back to the .phar file if available. Reason being, if you map a command for one server, it does it for all of them. This includes local dev environments.

# Use .phar file if bin/ executable is not available
#
#  This is useful whenever you're using a host that
#  doesn't let you install executables
#
{ wp: "wp-cli.phar" }.each do |cmd, exe|
    SSHKit.config.command_map[:"#{cmd}"] = "$(if [ $(which #{cmd}) ]; then echo '#{cmd}'; else echo 'php #{shared_path.join(exe)}'; fi)"
end
soullivaneuh commented 9 years ago

I did the trick with the default env:

set :default_env, {
  path: [
    "#{release_path}/bin", # Your composer bin folder
    "$PATH"
    ].join(":")
}

But works only if setted on env config file, not main deploy.rb.

davestevens commented 9 years ago

I am also having an issue with this, unfortunately it seems that the commands are only replaced at the front of the execute method, so execute :gunzip, "<", fetch(:wpcli_remote_db_file), "|", :wp, :db, :import, "-" doesn't work on my shared hosting because its not being replaced with anything.

For a workaround I can unzip the file and then import it, but that required making another file and having to clean up both the compressed and decompressed files.

soullivaneuh commented 9 years ago

Any new about this issue?

@ezekg is possible to make a PR for that?

jeremyzahner commented 9 years ago

Has anyone of you found a valuable workaround?

cibulka commented 9 years ago

Has anyone of you found a valuable workaround?

jeremyzahner commented 9 years ago

I will work on a solution to install the wp-cli.phar into the shared folder and use it from there if no wp-cli is installed on the remote system. See here: https://github.com/lavmeiker/capistrano-wpcli/milestones/LUX

cibulka commented 9 years ago

Are there any updates on this? Right now I get those errors, so it seems, that there definitely was some progress. :)

| => bundle exec cap production wpcli:db:pull
INFO[601ce078] Running /home/web720/wp-cli.phar db export - | gzip > /home/web720/capistrano-tmp/wpcli_database.sql.gz on 81.91.83.149
INFO[601ce078] Finished in 1.154 seconds with exit status 0 (successful).
INFODownloading /tmp/wpcli_database.sql.gz 50.23%
INFODownloading /tmp/wpcli_database.sql.gz 100.0%
INFO[ec51f6e9] Running /usr/bin/env rm /home/web720/capistrano-tmp/wpcli_database.sql.gz on 81.91.83.149
INFO[ec51f6e9] Finished in 0.250 seconds with exit status 0 (successful).
INFO[420060b2] Running /usr/bin/env gunzip -c /tmp/wpcli_database.sql.gz > /tmp/wpcli_database.sql on localhost
INFO[420060b2] Finished in 0.106 seconds with exit status 0 (successful).
INFO[5926342a] Running /home/web720/wp-cli.phar db import /tmp/wpcli_database.sql on localhost
cap aborted!
SSHKit::Command::Failed: wp exit status: 32512
wp stdout: Nothing written
wp stderr: sh: /home/web720/wp-cli.phar: No such file or directory
/Users/Cibulka/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in `exit_status='
/Users/Cibulka/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/local.rb:56:in `block in _execute'
/Users/Cibulka/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/local.rb:37:in `tap'
/Users/Cibulka/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/local.rb:37:in `_execute'
/Users/Cibulka/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/local.rb:26:in `execute'
/Users/Cibulka/.rvm/gems/ruby-2.1.2/bundler/gems/capistrano-wpcli-463d5e0418ba/lib/capistrano/tasks/wpdb.rake:52:in `block (4 levels) in <top (required)>'
/Users/Cibulka/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/local.rb:14:in `instance_exec'
/Users/Cibulka/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/local.rb:14:in `run'
/Users/Cibulka/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/dsl.rb:10:in `run_locally'
/Users/Cibulka/.rvm/gems/ruby-2.1.2/bundler/gems/capistrano-wpcli-463d5e0418ba/lib/capistrano/tasks/wpdb.rake:48:in `block (3 levels) in <top (required)>'
/Users/Cibulka/.rvm/gems/ruby-2.1.2/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/Users/Cibulka/.rvm/gems/ruby-2.1.2/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
/Users/Cibulka/.rvm/gems/ruby-2.1.2/bin/cap:23:in `load'
/Users/Cibulka/.rvm/gems/ruby-2.1.2/bin/cap:23:in `<main>'
Tasks: TOP => wpcli:db:pull
(See full trace by running task with --trace)

Weird thing is, that /home/web720/wp-cli.phar definitely exist on my production environment.

This is relevant part of my deploy/production.rb config file:

SSHKit.config.command_map[:wp] = "/home/web720/wp-cli.phar"

Any ideas? Thanks in advance!

jeremyzahner commented 9 years ago

This is pushed to the lux branch right now.

You are now able to easily set the location of the wp-cli.phar file via i.e.:

SSHKit.config.command_map[:wp] = "php #{shared_path}/wp-cli.phar"

Will release it shortly.

cibulka commented 9 years ago

Awesome, works for me!