2017 © Pedro Peláez
 

library auto-git-pull

Automatically pulls a git repository when commits are pushed.

image

oxicode/auto-git-pull

Automatically pulls a git repository when commits are pushed.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 14 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

AutoGitPull

Automatically run a git pull when changes are pushed to a Git repository., (*1)

About

There are two important parts: * A PHP script which Bitbucket or Github will automatically send a request to when you push. (http://mysite/deploy.php in the examples below) * A shell script which does the actual pulling. (scripts/git-pull.sh), (*2)

The reason for the separation is so you don't need to grant the web user write permission to your files. You just need to allow it to run the one script as a user that does have write permission., (*3)

Setup

Installation

  • Install the latest version with composer require oxicode/auto-git-pull, (*4)

  • Make the pull script executable (you need to do this if you update the package as well):, (*5)

chmod +x vendor/oxicode/auto-git-pull/scripts/git-pull.sh
  • Create a publicy accessible URL on your site which will be called by Github/Bitbucket and run the deployment (e.g. http://mysite.com/deploy.php) and set the parameters as appropriate. See deploy.example.php for an example.

Example in StandAlone:, (*6)

<?php
require dirname(__DIR__) . '/Vendor/autoload.php';

$deployer = new \Tmd\AutoGitPull\Deployer(array(
        'directory' => '/var/www/my_app/',
        'logDirectory' => '/var/www/my_app/tmp/deploy/',
        'notifyEmails' => array(
            'me@gmail.com'
        )
    ));
    $deployer->deploy();
  • Add the hook on Bitbucket to run the script:

Add bitbucket deploy hook, (*7)

If the web server user does not have write permissions on the directory

  • Allow the web server user to run the pull script as a user with write permissions:
sudo visudo

# Add the line:
# (Edit users and path as appropriate)
# www-data = User the PHP script runs as
# anthony = User the shell script needs to run as to write to the directory
# /var/www/mysite/vendor/tmd/auto-git-pull/scripts/git-pull.sh = Path to shell script

www-data ALL=(anthony) NOPASSWD: /var/www/mysite/vendor/tmd/auto-git-pull/scripts/git-pull.sh
  • Set the user to run the pull as in the parameters:
$deployer = new \Tmd\AutoGitPull\Deployer(array(
    'deployUser' => 'anthony',
    // ...
));

If your repository is private

You need to setup a deployment key so the pull can happen without a password being entered., (*8)

  • Follow these instructions to add your public key to the git repository:

Bitbucket: https://confluence.atlassian.com/pages/viewpage.action?pageId=270827678 Github: https://developer.github.com/guides/managing-deploy-keys/#deploy-keys, (*9)

  • Change your git remote url from HTTP(S) to SSH if necessary:
cd /var/www/mysite
git remote -v

If your output looks like this, you're using HTTP(S):, (*10)

origin  https://bitbucket.org/me/mysite.git (fetch)
origin  https://bitbucket.org/me/mysite.git (push)

Change it to use ssh, like this:, (*11)

git remote set-url origin git:mypassword@bitbucket.org:me/mysite.git

The Versions

23/07 2015

dev-master

9999999-dev

Automatically pulls a git repository when commits are pushed.

  Sources   Download

MIT

14/03 2015

1.1.3

1.1.3.0

Automatically pulls a git repository when commits are pushed.

  Sources   Download

MIT

14/03 2015

1.1.2

1.1.2.0

Automatically pulls a git repository when commits are pushed.

  Sources   Download

MIT

14/03 2015

1.1.1

1.1.1.0

Automatically pulls a git repository when commits are pushed.

  Sources   Download

MIT

13/03 2015

1.1.0

1.1.0.0

Automatically pulls a git repository when commits are pushed.

  Sources   Download

MIT

29/11 2014

1.0.1

1.0.1.0

Automatically pulls a git repository when commits are pushed.

  Sources   Download

MIT

29/11 2014

1.0.0

1.0.0.0

Automatically pulls a git repository when commits are pushed.

  Sources   Download

MIT

13/03 2014

dev-GitDeployer

dev-GitDeployer

Hook to automatically pull git commits into production.

  Sources   Download

MIT