2014-02-25 4 views
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)); 
        } 
       } 
      } 
     } 
    } 
} 

답변

0

나는 아래의 스크립트가

header("HTTP/1.1 200 OK"); 

200 OK하지만을 방출한다 등 (200) 등의 응답 코드를 제공 할 수 있다는 것을 어쨌든 거기 코드가 서버로 전달된다는 의미는 아닙니다.

Github 후크가 서버에 푸시되지 않습니다. Github의 새로운 코드 pull을 실행하기 위해 무언가를 실행하는 서버가 단순히 "ping"됩니다.

pull 코드를 확인하십시오.

IMO bash 스크립트는 이와 같은 경우 때때로 더 직관적 일 수 있습니다.

+0

고마워요. 서버에서 실행중인 것은 git pull이며 로그인 세부 정보를 묻는 것입니다. https://github.com/appleboy/PHP-Git-Deploy/blob/master/codeigniter/config/github.php –

+0

github에서 자격 증명을 가져올 수 없으므로 https : // 키를 사용해야합니다. github.com/settings/ssh https://help.github.com/articles/managing-deploy-keys#deploy-keys이 서버에 대해 아직 키를 설정하지 않았다면 문제가 될 수 있습니다. – stormdrain

관련 문제