Hello! ☞ This is an archived version of Al Shaw's personal website. The current site is http://shaw.al.


MT-GitPub: A Tool to Deploy MT Templates from Git

Movable Type, code, software, workflow

Since I last wrote about this, I’ve been digging more into the problem of deploying Movable Type template changes in the most efficient and elegant way. Since I’m keeping all my original files in Git repositories, the templates I want to publish will necessarily be files I have either recently committed (usually live site deployment), or recently modified (usually iterative testing on a staging site). And because I do most of my work on extremely large installs (TPM has over 15,000 blogs in its MT database), it is important to be incisive with publishing. Therefore, in devising a perfect MT deployment system, the primary goal is to only publish exactly what I need to see changed. The secondary goal is to do it without touching the MT app, and eventually without touching anything, as the entire process could run as a post-commit or post-merge hook.

Self Operating Napkin Today, I have a partial solution. Though it’s nowhere close to usable in a production environment, it’s “functional” enough to be released as an open source project. I’m calling it MT-GitPub, a bridge between Git and Tim Appnel’s command line template rebuilder mt-rebuild. MT-GitPub will query your MT database and generate config files for as many blogs as you’d like, and it has options to publish either last committed or last modified files in a given blog. More installation and usage details are in the readme on GitHub.

MT-GitPub is a good scaffolding, though it still has a lot of limitations, the biggest being that, for now, it only publishes index templates. This is because mt-rebuild doesn’t allow fine enough tuning for archive template rebuilding. I don’t want to rebuild 8 years of archives if I’m just iterating on an entry or category page design. Eventually I’m going to have to bite the bullet and learn some Perl in order to do something like only publishing the last n archive pages to work out changes. For the time being, I’ll continue building in archive publishing functionality to the extent that mt-rebuild’s CLI supports it, though probably just for the sake of completeness and personal blog use.

Of course, if anyone wants to pick up my slack and help out with some of this stuff, by all means please fork!

$ git clone git://github.com/ashaw/MT-GitPub.git

One more wrinkle on deploying MT templates from Git— Git retains file permissions for whatever user is pulling a repo down. If this isn’t apache, MT might throw you a permission denied error when you try to republish linked files in your production repo. I solved this by putting a post-merge hook in GIT_DIR/hooks/ like so:


chown -R apache /path/to/production_gitdir

I’m still learning the ropes, both with shell scripting and Git. Most of the configfile string parsing to pass template names to mt-rebuild is done with awk which, I’ve found, is surprisingly powerful (though probably wouldn’t be necessary if BASH had associative arrays). Anyway, please clone it, try it out and drop me a line.