我正在尝试为生产网站设置一个post-receive挂钩。代码似乎部分工作,但文件不会被复制。在这个目录中,我设置了一个裸存储库:
public_html/deploy-dir
在hooks / post-receive中有以下代码:
#!/usr/bin/env ruby
# post-receive
# 1. Read STDIN (Format: "from_commit to_commit branch_name")
from, to, branch = ARGF.read.split " "
# 2. Only deploy if master branch was pushed
if (branch =~ /master$/) == nil
puts "Received branch #{branch}, not deploying."
exit
end
# 3. Copy files to deploy directory
deploy_to_dir = File.expand_path('../')
`GIT_WORK_TREE="#{deploy_to_dir}" git checkout -f master`
puts "DEPLOY: master(#{to}) copied to '#{deploy_to_dir}'"
远程网址是这样的:
ssh://username@thesite.org/home/username/public_html/deploy-dir
执行'git push production master'时,我在终端中得到以下输出:
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 300 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: /usr/bin/env: ruby: No such file or directory
To ssh://username@thesite.org/home/username/public_html/deploy-dir
3a5ab4d..6c49ce0 master -> master
我认为'没有这样的文件或目录'错误与后接收挂钩的第1行有关。那里缺少一些东西,我不知道应该是什么。此后接收代码适用于另一台服务器。
或者,我的deploy-to-dir路径可能不正确?应该是:
deploy_to_dir = File.expand_path('../')
或
deploy_to_dir = File.expand_path('..')
答案 0 :(得分:1)
正如您在评论中指出的那样,env
的输出表明ruby
在远程端的PATH中不可用。
您拥有git
,这意味着您拥有perl
。你会考虑以下几点吗?
#!/usr/bin/env perl
# post-receive
use warnings;
use strict;
use Cwd 'abs_path';
# 1. Read STDIN (Format: "from_commit to_commit branch_name")
my($from,$to,$branch) = split " ", scalar <STDIN>;
# 2. Only deploy if master branch was pushed
if ($branch ne "master") {
warn "Received branch $branch, not deploying.\n";
exit 0;
}
# 3. Copy files to deploy directory
my $deploy_to_dir = abs_path('../');
$ENV{GIT_WORK_TREE} = $deploy_to_dir;
if (system("git checkout -f master") == 0) {
print "DEPLOY: master($to) copied to '$deploy_to_dir'\n";
}
else {
warn "DEPLOY: checkout failed\n";
exit 1;
}
答案 1 :(得分:0)
这是一个简单的问题,没有安装在服务器上的ruby。支持安装ruby并解决问题。