PHPackages                             techsemicolon/gitdeployer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. techsemicolon/gitdeployer

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

techsemicolon/gitdeployer
=========================

Git webhook deployer package for laravel currently integrated with bitbucket

1.0.0(7y ago)13.6kMITPHPPHP &gt;=5.4.0

Since Apr 9Pushed 7y agoCompare

[ Source](https://github.com/techsemicolon/gitdeployer)[ Packagist](https://packagist.org/packages/techsemicolon/gitdeployer)[ RSS](/packages/techsemicolon-gitdeployer/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Laravel Git Deployer
====================

[](#laravel-git-deployer)

Git webhook deployer package for laravel currently integrated with bitbucket.

Introduction :
--------------

[](#introduction-)

When you push new releases or hotfixes to your production branch, it's a hassle to everytime login to the live server and do git pull manually. That is why webhook is a crutial part. There are many tools available which gives you CICD options and automated git deployments. However, I have opinion that not all projects need that level of criticality and complications. I had a very simple application with only 1 server running. I was looking for a very plug and play type of webhook package for laravel, I did not find one with my expectations and hence this is the one I built.

How it works :
--------------

[](#how-it-works-)

Currently it integrates just with Bitbucket and not github(will add that as well soon). This package once installed gives you a url `www.your-url.com/git/webhook` which you can add into the bitbucket webhook configurations. Then whenever the webhook is triggered, this url gets the webhook payload via POST request to your server.

Once the server gets the payload it does following checks :

1. Validating request IP :

Before taking any actions on webhooks, we need to make sure the request payload is actually coming from bitbucket and not falsely sent by any other unknwon servers. The package whitelists bitbucket's IP addresses virtually so that only valid payloads from bitbucket are handled.

2. Checking repository :

If the repository in the bitbucket's webhook payload is the one which is currently active in the laravel project, then only take further steps. Otherwise do nothing.

3. Checking if the current active branch is updated :

If you have `production` branch active on your live instance and the payload has changes in some `hotfix` branch, we do not need to run webhook scripts on the live server. The package only takes further actions if the payload has any new changes for the currently active branch.

4. Running the webhook actions :

If the all the above checks are passed, webhooks actions are taken in form of scripts running one after another. The package is flexible to give you entire control of the scripts and commands which will be run once webhook is triggered.

Prerequisites :
---------------

[](#prerequisites-)

1. The bitbucket repo origin set on the live server has to be using `ssh` so that it does not require password to be entered when you do git pull.
2. The user and group running as web server and the file permissions of laravel files should to be same. For example, if you have `www-data` running as web server and the laravel files are having permissions `ubuntu.ubuntu`, its going to create permission problems.

Installation :
--------------

[](#installation-)

To install the package using composer :

```
composer require techsemicolon/gitdeployer
```

Once installed, you can add service provider in `config/app.php` file for laravel version &lt;= 5.2. For later versions the service provider will be automatically included.

```
Techsemicolon\Gitdeployer\GitdeployerServiceProvider::class,
```

Now, you can publish the vendor files for the package :

```
php artisan vendor:publish --provider="Techsemicolon\Gitdeployer\GitdeployerServiceProvider"
```

This will add a config file `git.php` and a folder for scripts in app root called `webhookscripts`.

Importantly, you need to add the `/git/webhook` url which route to avoid csrf verification so bitbucket's post requests are not rejected. For that, you need to add following inside `App\Http\Middleware\VerifyCsrfToken.php` file :

```
/**
 * The URIs that should be excluded from CSRF verification.
 *
 * @var array
    */
protected $except = [
    '/git/webhook'
];
```

Workflow :
----------

[](#workflow-)

Apart from the 4 steps mentioned in `how it works` section, the package follows a simplw workflow. The `webhookscripts` folder is the key of this package.

When you run vendor publish, it will automatically create a file `deploy.sh` for you. This contains the main deployment bash script. Anytime webhook is triggered then this bash script will be run.

Additionally and optionally, the package gives you ability yo specify 2 more script files with the name you like, which will run before and after the main `deploy.sh` bash script. This is to give you control over what to do prior to pulling the latest release and what to do after it.

You can have those files stored in the `webhookscripts` folder with the name you want. That name you can specify in the `config/git.php` file. More configuration options are mentioned below.

Configurations :
----------------

[](#configurations-)

The file `config/git.php` has following configurations :

```
