Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved support for github private repositories #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
1 change: 1 addition & 0 deletions deploy-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
15 changes: 12 additions & 3 deletions inc/class.deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,27 @@ 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' );

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 );
}
}
}
Expand Down