我需要找到一种方法,将存储在git repo中的PHP项目部署到没有安装git 的登台和生产服务器。到目前为止我发现的脚本(即Capistrano)需要在目标服务器上使用Git。
不幸的是,我的主机不允许这样做,到目前为止唯一的方法是通过标准FTP,我不断丢失文件。这使得看起来不专业。
我希望能够从我的本地git repo进行部署,它将检查目标上的.git文件夹以查看其中的版本,然后使目标服务器备份当前版本,然后用只推送已更改的文件。
PHP中最好带有Web界面的东西。
我的要求不高;)
那里的任何人都有这样的事情吗?
答案 0 :(得分:15)
答案 1 :(得分:3)
您可以使用Fuse之类的东西将生产服务器“挂载”为本地驱动器,然后就您的git副本而言,它是本地操作。或者,rsync。
答案 2 :(得分:1)
还有一个工具调用Dandelion也可以执行此操作。从我所看到的,它与git-ftp非常相似,但它也支持sftp和Amazon S3,如果您不想仅因为更改服务器而更改部署工具,这将非常方便。它是一颗红宝石宝石,因此非常容易安装和开始使用。
答案 3 :(得分:0)
我使用ssh2和php做过类似的事情。
首先,您需要克隆服务器上的repo。克隆后,你可以使用ssh2从php进行git pull,checkout等。我找到的最实用的方法就是做。
git fetch;
git reset --hard commit_hash;
以便将提交设置为预期的提交。
要执行php-ssh2命令(假设您安装了ssh2),可以使用此方法。
public static function SSHCommmand($command,$user,$ip) {
$port = 22;
if (!function_exists("ssh2_connect"))
die("function ssh2_connect doesn't exist.");
$result['debug'] .= " -Connect- 1";
if (!($con = ssh2_connect($ip, $port, array('hostkey' => 'ssh-rsa')) )) {
die("unable to establish connection.");
} else {
// try to authenticate with username root, password secretpassword
if (!(ssh2_auth_pubkey_file($con, $user, '/home/' . $user . '/.ssh/deploy_rsa.pub', '/home/' . $user . '/.ssh/deploy_rsa'/* , 'secret' */))) {
dir("fail: unable to authenticate.");
} else {
// allright, we're in!
// execute a command
if (!($stream = ssh2_exec($con, $command))) {
die("fail: unable to execute command.");
} else {
// collect returning data from command
stream_set_blocking($stream, true);
$data = '';
while ($buf = fread($stream, 4096)) {
$data .= $buf;
}
fclose($stream);
return $data;
}
}
}
}
我正在使用ssh-rsa密钥,auth方法可能会改变。我还假设密钥位于'/home/' . $user . '/.ssh/deploy_rsa.pub'
和'/home/' . $user . '/.ssh/deploy_rsa
。
您可能会考虑的另一件事是执行远程git命令远程命令,该命令应该是:
_GIT_PATH.' --git-dir='.$path.'/.git --work-tree='.$path.' '.$command;
其中$path
是工作树的顶层。
通过使用这个和Amazon Api,我已经能够自动同时将新代码部署到多个服务器。
答案 4 :(得分:0)
我使用Beanstalkapp.com,这很棒。您可以通过FTP或SFTP进行部署。