2
아래 스크립트를 사용하여 GIT의 준비 서버에 CI 사이트를 자동으로 배포합니다.Git 배포 스크립트가 응답을 표시하도록합니다.
내 문제는 내가 GIT에 관해서 멍청한 데다가 리포지토리에 밀어 넣을 때 코드가 서버에 밀려 드는 것처럼 보이지 않는다는 것입니다.
어쨌든 내가 200 등의 응답 코드를주는 스크립트를 만들 수 있습니까? git 허브의 후크 설정은 JSON을 사용하도록 설정되어 있습니다.
스크립트 :
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Post-Receive Hooks API
*
* @author appleboy
* @copyright 2012 appleboy
* @link https://github.com/appleboy/PHP-Git-Deploy
* @package CodeIgniter Git Deploy
*/
class Deploy extends CI_Controller
{
/**
* Default __construct
*
* @author appleboy
*/
public function __construct()
{
parent::__construct();
$this->config->load('github');
}
/**
*
* Post-Receive Hooks
*
* @author appleboy
*/
public function receive()
{
// receive git payload
$payload = $this->input->get_post('payload');
// load git command path config
$git_config = $this->config->item('github');
$git_path = $this->config->item('git_path');
if ($payload and is_array($git_config)) {
$payload = json_decode($payload);
log_message('debug', 'Post-receive hook initial');
foreach ($git_config as $key => $val) {
// check repository name exist in config
$repository_name = strtolower($payload->repository->name);
if ($repository_name != strtolower($key)) {
continue;
}
foreach ($val as $k => $v) {
// check if match payload ref branch
$head = 'refs/heads/' . $k;
if ($payload->ref != $head) {
continue;
}
// git reset head and pull origin branch
if (isset($v['base_path']) and !empty($v['base_path'])) {
$base_path = realpath($v['base_path']) . '/';
$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" reset --hard HEAD',
$git_path, $base_path, $base_path);
log_message('debug', '$shell value ' . $shell);
$output = shell_exec(escapeshellcmd($shell));
$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" clean -f',
$git_path, $base_path, $base_path);
log_message('debug', '$shell value ' . $shell);
$output = shell_exec(escapeshellcmd($shell));
$shell = sprintf('%s --git-dir="%s.git" --work-tree="%s" pull origin %s',
$git_path, $base_path, $base_path, $k);
log_message('debug', '$shell value ' . $shell);
$output = shell_exec(escapeshellcmd($shell));
}
}
}
}
}
}
고마워요. 서버에서 실행중인 것은 git pull이며 로그인 세부 정보를 묻는 것입니다. https://github.com/appleboy/PHP-Git-Deploy/blob/master/codeigniter/config/github.php –
github에서 자격 증명을 가져올 수 없으므로 https : // 키를 사용해야합니다. github.com/settings/ssh https://help.github.com/articles/managing-deploy-keys#deploy-keys이 서버에 대해 아직 키를 설정하지 않았다면 문제가 될 수 있습니다. – stormdrain