Infinitas Cms is a open source content management system that is designed to be fast and user friendly, with all the features you need.

Simple deployments with Git

Taken from this blog post by Max Tsepkov, a simple way to deploy code using git.

Normally for deploying updates to small sites GIT is pretty good. It is far better than using FTP, that is for sure. The normal process is as follows:

  • Change code locally, commit and push to GitHub / BitBucket
  • SSH to remote server
  • cd to remote code dir
  • pull from GitHub / BitBucket
  • clear cache etc

That is not a very complicated process, but there is a lot of repetition. Especially when you have a number of updates / sites to do every day. With a few changes to the git config we can reduce this to a single command (after the changes have been made and commited)

First you need to set up the remote repo to allow receiving code. This is done via a single git command that only needs to be run once. From inside the root of the repository run:

git config receive.denyCurrentBranch ignore

This will allow the repo to have code pushed to it. Its best if you do not ever commit code on a production repo, especially not after you have done this.

The next thing to do is add a small post-receive hook to the remote git repo. This will be coded to sort out the repo once any new code has been pushed to it. You can also use this hook to do other tasks such as clear cache or restart services.

Inside the repo, add or edit the file .git/hooks/post-receive with the following:

#!/bin/sh
cd ..
env -i git reset --hard
env -i git submodule update --recursive
env -i Console/cake data.clear_cache

# other commands here

The commands are pretty simple. Change back to the main repository, clear up any changes and update any sub modules. With a bit of imagination and bash code you could have the hook email other developers about the update, run cache warmup scripts or anything else you may require.

Finally add the remote server as a remote on your local copy of the repo. This can be done with the following command. You will need to have the full path to the repo from your remote server.

git remote add production username@hostname:/full/path/to/repo

Make sure the user you have put in the new remote will have permission to execute the new / modified git hook that was created above. From now on the deploy process is as follows:

  • Change code locally, commit and push to GitHub / BitBucket
  • Push to production

Simple.

For anyone wondering how they are going to push to the new remote, that is pretty similar to how you normally push code to GitHub for example.

git push production

You can also include the branch if required.

git push production your-branch