Git Bundle Deployment with Fabric

We rely on Git for deploying web applications where it’s an indispensable tool. Usual flow includes updating target application server code from a Git repository which is hosted on the internet. Accessing repositories requires internet access. Most of the time this is fine, but there are rare cases target hosts may not have internet access because of multiple reason including but not limited to security policy of the institute and temporary internet connection issues.

Offline deployment can be done copying files by hand but this is not ideal for a number of obvious reasons. Deployment should always be automated.

Git bundle is a very useful tool to create bundle files of any repository to be used for offline deployment. Created bundle files are similar to any regular local or remote repository. Deployment task can create bundle files beforehand and then copy and unbundle to the target hosts during deployment. Whole task is handled as if the internet connection is available.

Only problem with Git bundles is lack of submodule support. If source repository has submodules those need to be handled manually which breaks whole deployment automation. Only tool that I could find for Git bundle submodule support is git-subundle. It’s actually a bash script and appears to be handle submodules during bundling and unbundling.

Although git-subundle can be used as is, I find it more powerful when it’s implementation adapted by Fabric. Both Fabric and Python makes more practical to use the bundle deployment feature. I’ve created the fabric-bundle repository at the GitHub. The repository includes a test project and basic Fabric methods to handle bundle file creation, bundle file extraction and method to take care of bundling, unbundling and remote host deployment.