Intermediate
(This describes a pretty standard apache setup on Redhat / Ubuntu / CentOS / Amazon AMI etc) you should be able to do the same with Java, Perl, RoR, JSP etc. however you'll need to recreate the (rather simple) PHP script.
git
, rsync
, and tar
binaries are required on the server that's running the script (server machine).
Also, the system user that's running PHP needs to have the right ssh keys to access the remote repository (If it's a private repo) and have the required permissions to update the files on the server machine.
Here we add the deployment script and push it to the origin, the deployment script runs git commands to PULL from the origin thus updating your server
git add deploy.php
git commit -m 'Added the git deployment script'
git push -u origin master
Here we install and setup git on the server, we also create an SSH key so the server can talk to the origin without using passwords etc
After you've installed git, make sure it's a relatively new version - old scripts quickly become problematic as github / bitbucket / whatever will have the latests and greatest, if you don't have a recent version you'll need to figure out how to upgrade it :-)
git --version
# Add a nice repo
rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
# Install git
yum install --enablerepo=webtatic git-all
sudo yum install git-core
git config --global user.name "Server"
git config --global user.email "server@server.com"
sudo mkdir /var/www/.ssh
sudo chown -R apache:apache /var/www/.ssh/
sudo -Hu apache ssh-keygen -t rsa # choose "no passphrase"
sudo cat /var/www/.ssh/id_rsa.pub
Here we add the SSH key to the origin to allow your server to talk without passwords. In the case of GitHub we also setup a post-receive hook which will automatically call the deploy URL thus triggering a PULL request from the server to the origin
https://github.com/USERNAME/REPOSITORY/settings/keys
and add your server SSH key (only needed for private repositories)https://github.com/USERNAME/REPOSITORY/admin/hooks
http://example.com/deploy.php?sat=YourSecretAccessTokenFromDeployFile
https://bitbucket.org/USERNAME/REPOSITORY/admin/deploy-keys
and add your server SSH key (only needed for private repositories)https://bitbucket.org/USERNAME/REPOSITORY/admin/services
http://example.com/deploy.php?sat=YourSecretAccessTokenFromDeployFile
.git/hooks/post_receive
script that calls the script e.g.#!/bin/sh
echo "Triggering the code deployment ..."
wget -q -O /dev/null http://example.com/deploy.php?sat=YourSecretAccessTokenFromDeployFile
Here we clone the origin repo into a chmodded /var/www/html folder
sudo chown -R apache:apache /var/www/html
sudo -Hu apache git clone git@github.com:you/server.git /var/www/html
Now you're ready to go :-)
Here are more guides from me