Using capistrano when remote git is on a non-stand

2019-06-19 01:36发布

问题:

My shared host did not provide git, so I built and installed it into ~/bin. When I ran it, I got the following error on most commands, although they were successful.

stdin: is not a tty

I can solve that problem by adding:

default_run_options[:pty] = true

to my deploy.rb, but then I get this error, which blocks deployment:

sh: git: command not found

How can I resolve both errors?

I tried adding a ~/.ssh/environment file with "PATH=$PATH:$HOME/bin" (and changing sshd_config to use it) but it did nothing.

It seems whatever shell is being used by capistrano is not using the ~/.bashrc or ~/.bash_profile on the remote server.

Any ideas how to set the path on the remote machine?

other info: I'm using OS X locally, and the shared server is linux on Site5.

回答1:

Thanks, Chu - you put me on the right path.

just using: set :scm_command, "~/bin/git"
still gave me errors, since my local git is not in that place.

However, the following seems to work, and to solve my issues:
set :scm_command, "~/bin/git"
set :local_scm_command, "/usr/local/bin/git"



回答2:

The problem is that you've set

default_run_options[:pty] = true

which means that your .bash_profile or your usual shell init file won't be run, which is not the case when you set it to false -- but then you'll have issues when it wants to ask you for the password.

To get around this problem, you can manually set your PATH environment variable in your deploy file:

default_environment['PATH'] = "/your/path/to/git:/and/any/other/path/you/need"


回答3:

You should be able to specify the full path to git like so:

set :scm_command, "/home/your_cap_runner_user/bin/git"

I haven't tried this out for myself - found it in the documentation in the source code for git.rb in Capistrano itself.



回答4:

stdin: is not a tty

This is probably because of CPanel installed on your shared host. It executes "mesg y" in global /etc/.bashrc file that is included in your ~/.bashrc one. So you can just comment-out the inclusion.

Here’s the source: http://webhostingneeds.com/Git_stdin_is_not_a_tty



回答5:

A quick workaround is to set the following in your deploy.rb file:

set :deploy_via, :copy

This will cause the checkout to occur on your own machine and then be copied to the deployment server.



回答6:

This is a great help, as I was running into the same issue as the original poster.

"Before" symptoms:

  • run cap deploy:setup (successful)
  • ran cap deploy:check (fails, with 'git command not found')

I now added set :scm_command, "~/bin/git" to my deploy.rb file.

  • ran cap deploy:setup (successful)
  • ran cap deploy:check (successful)
  • ran cap deploy:cold (fails, with the following error)

    :97:in ``': No such file or directory - ~/bin/git info git@github.com:quintar/eu reka.git -rHEAD (Errno::ENOENT)

So it looks like 'git' is recognized, but the repository I included in my deploy.rb is bypassed?



回答7:

The ~/.ssh/environment file is not executed by a shell. It's a hardcoded environment file. If you want to set the path this way, you'll need to hardcode it instead of appending to $PATH. The other answers are possibly more correct, but setting ~/.ssh/environment correctly is a reliable fallback if all else fails.