diff --git a/README.md b/README.md index ee6e7c3..f5fd687 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,21 @@ More: https://confluence.atlassian.com/pages/viewpage.action?pageId=271943168 ## Usage * commit and push +## Common Issues + +### Not able to pull from a private github repository +In order to be able to pull from a github repository, this script has to connect using a public key, you have to add the key to the .ssh folder of the user who is running the git-deploy script. And server has to trust on github authenticity without interactive prompt, you can fix this creating a .php file with this content and running only once, you should see a succesfully authentication message with some debug information. + +```php +error_reporting(E_ALL); +header('Content-type: text/plain'); +ini_set('display_errors',1); +ini_set('display_startup_errors',1); +echo system( 'ssh -v -o "StrictHostKeyChecking no" git@github.com 2>&1' ); +// Uncomment this lines to also check that pull is working +//chdir('/path/to/repository/'); +//echo system('git pull origin master 2>&1'); // change master for your branch if needed +``` # More information http://lkwdwrd.com/git-auto-deployment/ diff --git a/deploy-config.php b/deploy-config.php index 5a149d6..1d87a88 100644 --- a/deploy-config.php +++ b/deploy-config.php @@ -40,6 +40,7 @@ * Sets the deploy log directory */ define( 'DEPLOY_LOG_DIR', dirname( __FILE__ ) ); +define( 'DEPLOY_FULL_OUTPUT', true ); /* Do not edit below this line */ require_once 'inc/class.deploy.php'; diff --git a/inc/class.deploy.php b/inc/class.deploy.php index ac122d2..d00e231 100644 --- a/inc/class.deploy.php +++ b/inc/class.deploy.php @@ -210,7 +210,10 @@ private function execute() { exec( 'git reset --hard HEAD', $output ); // Update the local repository - exec( 'git pull ' . $this->_remote . ' ' . $this->_branch, $output ); + exec( 'git pull ' . $this->_remote . ' ' . $this->_branch . ' 2>&1', $output, $return_var ); + + if ($return_var != 0) + throw new Exception("Git pull failed", 1); // Secure the .git directory echo exec( 'chmod -R og-rx .git' ); @@ -218,10 +221,16 @@ private function execute() { if ( is_callable( $this->_post_deploy ) ) call_user_func( $this->_post_deploy ); - $this->log( '[SHA: ' . $this->_commit . '] Deployment of ' . $this->_name . ' from branch ' . $this->_branch . ' successful' ); - echo( '[SHA: ' . $this->_commit . '] Deployment of ' . $this->_name . ' from branch ' . $this->_branch . ' successful' ); + $log_msg = "[SHA: {$this->_commit} Deployment of {$this->_name} from branch {$this->_branch} successful". + $this->log( $log_msg ); + echo $log_msg; + + if (DEPLOY_FULL_OUTPUT) + $this->log( $output ); + } catch ( Exception $e ) { $this->log( $e, 'ERROR' ); + $this->log( $output ); } } }