【发布时间】:2019-06-21 21:24:01
【问题描述】:
使用 laravel 5.6。我正在尝试在 gitlab 上设置一个 webhook,以便在推送事件上创建一个 git pull。我创建了一个 post 路由,添加了控制器和方法,它启动了一个 shell 脚本:
use Symfony\Component\Process\Process;
class WebhookController extends Controller
{
public function handle(Request $request) {
$root_path = base_path();
$process = Process::fromShellCommandline('cd ' . $root_path . '; ./deploy.sh');
$process->run(function($type, $buffer) {
echo $buffer;
});
}
}
Shell 脚本本身只包含一行:
#!/bin/sh
git pull
但在 gitlab 的请求详细信息中,我在推送后看到错误:
error: cannot open .git/FETCH_HEAD: Permission denied
我已经chmod 777 deploy.sh,但我猜它试图从不同的用户启动该脚本?如果我从我的用户启动脚本,它就可以工作(我正在使用没有密码的 ssh 密钥)。
更新
我做了sudo chown -R $USER:www-data . - 现在它没有显示权限错误,除了一个:
Could not create directory '/var/www/.ssh'.
Host key verification failed.
fatal: Could not read from remote repository.
它正在尝试使用 www-data 用户创建git pull(我与 whoami 核对过),所以它没有正确的 ssh 密钥,我该如何切换到我的 USERNAME?
【问题讨论】:
标签: php git laravel gitlab webhooks