<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Passing Curiosity: Posts tagged platforms</title>
    <link href="https://passingcuriosity.com/tags/platforms/platforms.xml" rel="self" />
    <link href="https://passingcuriosity.com" />
    <id>https://passingcuriosity.com/tags/platforms/platforms.xml</id>
    <author>
        <name>Thomas Sutton</name>
        
        <email>me@thomas-sutton.id.au</email>
        
    </author>
    <updated>2011-08-31T00:00:00Z</updated>
    <entry>
    <title>Using git repositories for platform versioning</title>
    <link href="https://passingcuriosity.com/2011/git-repositories-for-platform-versioning/" />
    <id>https://passingcuriosity.com/2011/git-repositories-for-platform-versioning/</id>
    <published>2011-08-31T00:00:00Z</published>
    <updated>2011-08-31T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>I’m not sure how widely this might be applicable but I’ve found it an
interesting problem to think about and it’s going to help iron out some
wrinkles in our workflow.</p>
<p>We have a standard platform that does a great deal of the scutwork required of
a generic CMS based on Drupal. What’s included in it doesn’t really matter
(it’s an install profile that does a bunch of stuff), just that it’s the base
of many of our projects and it is maintained as a unit and upgraded as a whole
on individual sites.</p>
<p>I currently maintain this using a bunch of git repos, a custom feature server
(which uses <code>ssh</code> tunnels to access the git repos), <code>drush make</code> and about a
dozen other moving parts which produce a new build of the platform in a
tarball. Needless to say this is tedious, error prone, and means new releases
are slower than they should be. Git to the rescue!</p>
<p>Rather than building tarballs of platform releases manually I’ll be
maintaining canonical versions in repositories and using git to manage
applying upgrades to individual projects.</p>
<h3 id="creating-a-platform">Creating a platform</h3>
<p>This first step is creating my “blessed” platform repository. To keep things
simple I’ll describe managing two platforms:</p>
<ul>
<li><p><code>6.x</code> is the current release of Drupal 6; and</p></li>
<li><p><code>7.x</code> is the current release of Drupal 7.</p></li>
</ul>
<p>As this repo is somewhat special I’m going to take some pains to make sure
it’s structured exactly as I want it. In particular, I want every branch to be
correspond to one of my platforms. This is a little tricky but it only happens
once so don’t worry too much if you find it confusing.</p>
<pre><code># Initialise a new empty repo and add the origin I'll push the result to
mkdir platform
cd platform
git init
git remote add origin git@gorilla:/platforms/drupal.git

# First, let's create the Drupal 6 branch.
git symbolic-ref HEAD refs/heads/6.x
rm .git/index
git clean -fdx
drush dl --yes --drupal-project-rename=htdocs drupal-6
git add htdocs
git commit -m 'drupal-6'
git push origin 6.x

# Now, let's take care of the Drupal 7 branch.
git symbolic-ref HEAD refs/heads/7.x
rm .git/index
git clean -fdx
drush dl --yes --drupal-project-rename=htdocs drupal-7
git add htdocs
git commit -m 'drupal-7'
git push origin 7.x</code></pre>
<p>This sequence is a little verbose (the <code>rm</code> and <code>git clean</code> for Drupal 6
aren’t strictly necessary) but it should be obvious how I can add additional
platforms.</p>
<p>Assuming that the repo at <code>git@gorilla:/platforms/drupal.git</code> was newly
<code>init</code>ed, it should now contain a <code>6.x</code> branch containing Drupal 6 and a <code>7.x</code>
branch containing Drupal 7.</p>
<p>For safety’s sake, it’d probably be a good idea to have push restrictions on
the platform repository to prevent accidental and illicit modifications
flowing back from projects into platforms. It’s outside the scope of this
document to describe how to do this but you probably want to use <code>gitolite</code> or
something else with fine-grained access control (i.e. not gitosis).</p>
<h3 id="starting-a-project">Starting a project</h3>
<p>Now that my platforms are available in git I can use them as the starting
point for a new project. I just clone the right branch from the platform repo
and I’m off!</p>
<pre><code>git clone --origin platform --branch 6.x git@gorilla:/platforms/drupal example.com
cd example.com
git checkout -b master</code></pre>
<p>It’s a bit confusing at first glance, so I’ll break that down a bit. First I
clone the platform repository with the <code>git clone</code> command. Instead of letting
it use default values I’m telling it what to call the <em>origin</em> remote in the
new repository (<code>platform</code> instead of <code>origin</code>) and which branch to clone
(<code>6.x</code> instead of the default <code>HEAD</code> in the remote). Running this command will
create a new repository in <code>example.com/</code> with a remote called <code>platform</code> and
a single branch called <code>6.x</code> (based on the <code>6.x</code> in <code>platform</code>).</p>
<p>I recommend using the <code>6.x</code> branch exclusively for pulling in new releases of
the platform so I also create a <code>master</code> branch to work on with the next git
command does.</p>
<p>Now <code>example.com</code> has two branches: <code>6.x</code> where I can pull in new releases of
the platform, and <code>master</code> where I’ll be working on the <em>example.com</em> site.</p>
<h3 id="upgrading-a-project">Upgrading a project</h3>
<p>Upgrading a project to run on the latest version of it’s platform should be a
simple matter of pulling the appropriate branch and merging the changes into
<code>master</code>.</p>
<pre><code>cd example.com
git checkout 6.x
git pull
git checkout master
git merge 6.x</code></pre>
<p>Here I checkout the “platform” branch (<code>6.x</code> as in the example above) and pull
in any remote changes. Then I checkout the <code>master</code> branch and merge the
changes in the updated <code>6.x</code> branch.</p>
<p>Unless I’ve been a naughty boy and modified files that are “owned” by the
platform this shouldn’t result in so much as a merge conflict.</p>
<h3 id="conclusion">Conclusion</h3>
<p>I haven’t rolled this new method out at work yet but it’s in the pipeline. I’m
quite excited by it and I think it’ll help make what’s currently tedious and
error prone into something of a NOOP. Hopefully the rest of the team agrees!</p>
<p>Have you done something similar? Have I missed some serious consideration? Is
this all old hat and I should get with the programme? I’d love to hear any
comments or feedback on the approach I’ve described.</p>]]></summary>
</entry>

</feed>
