
Provides an endpoint to your website to use as a webhook for git post commit hooks. When triggered the endpoint will queue a git pull to be executed by cron. This allows you to automate a deployment (plus whatever you want, e.g. Drupal cache clear), whenever you push to your repository. By leveraging cron, you can keep tight permissions and run your git pull as the cron user, not, say, apache. Intended to be used for staging websites, rather than production, where you would want to deploy manually.
Visit https://aklump.github.io/post_commit for full documentation.
cloudy pm-install aklump/post_commitSet the correct ownership and permissions on opt/post_commit/logs; they must be owned by the user that will run cron and the group must be the php user (you can see this by visiting the testing url per directions below) who will be executing scheduler.php. Owner/Group privelages must be both RW. Other needs no permissions.
drwxr-xr-x 2 aklump apache 4.0K May 28 17:02 .
drwxr-xr-x 5 aklump staff 4.0K May 28 17:01 ..
-rw-rw---- 1 aklump apache 0 May 28 17:16 complete.txt
-rw-rw---- 1 aklump apache 0 May 28 17:16 orders.txt
-rw-rw---- 1 aklump apache 0 May 28 17:16 pending.txt
Set up a cron job to execute runner.php (see below).
Compile the post commit hook url and add it to your github project. Keep the key in the url, do not use the secret textfield. Also you will want to choose the json format. Make sure to use https if you can, a self-signed cert should work fine.
https://user:password@website.com/scheduler.php?key=yourprivatekeyhere
Now make a commit to your repo and the website should update itself.
You must have Cloudy installed on your system to install this package.
Your repository may not use a passphrase, as this prevents the automatic git pull.
The installation script above will generate the following structure where . is your repository root.
.
├── bin
│ ├── post_commit -> ../opt/post_commit/post_commit.sh
│ └── config
│ ├── post_commit.yml
│ └── post_commit.local.yml
├── opt
│ ├── cloudy
│ └── aklump
│ └── post_commit
└── {public web root}
cloudy pm-update aklump/post_commit| Filename | Description | VCS |
|---|---|---|
| post_commit.yml | Configuration shared across all server environments: prod, staging, dev | yes |
| post_commit.local.yml | Configuration overrides for a single environment; not version controlled. | no |
| scheduler.php | This should be pinged by a post commit hook on the origin repo via https and including the secret key. | yes |
./bin/post_commit helpIf you find this project useful... please consider making a donation.
You can test a single repository by appending the following to the url, for the purposes of testing.
&repo=jquery.slim_time
You can trigger a single branch response by appending the following to the url, for the purposes of testing.
&branch=master
This should be the target of a frequent cron job being run by the same user that owns the website files and .git folder. This script processes any orders that were scheduled by scheduler.php. You can redirect the output to logs/cron.txt file during setup, and once all is working you should consider doing like the second example which does not capture the output.
* * * * * /usr/bin/php /home/user/mysite/opt/post_commit/runner.php >> /home/user/mysite/opt/post_commit/logs/cron.txt
Example 2, no log of cron jobs, better once all is working correctly. You might want to delete logs/cron.txt at this point.
* * * * * /usr/bin/php /home/user/mysite/opt/post_commit/runner.php > /dev/null
You can truncate all text files without messing up perms using reset.php.
A log of incoming orders post commit hooks.
A log of runner.php.
The commands that have not yet been executed by cron. This file should get emptied at each cron run.
Don't just delete the log files as permissions are bit tricky; instead use the reset script.
php reset.php
Check to make sure the the logs directory and all log files are owned by the cron user and the group is the php user and that both user and group has rw permissions.
Does the git repo require a passphrase for pulling? You will have to disable that.
Try logging in to the server as the cron user and running the command.
Make sure you can git pull manually using your ssh keys, etc.