Ahem. As the kids say, “do-over!”
Really, what we’ve been repeating is “Don’t repeat yourself without automating the repetitive task.” We try to automate everything we do more than once, and as a busy agency, one of the things we do more than once is bootstrap new Rails applications. And we do pretty much the same things every time: we create a new Rails application, we install a few favorite gems and plugins, and we check the lot into a freshly-created Git or Subversion repository. It’s ripe for automation, not just because we repeatedly do it, but because we want to repeat it. We want the same setup every time, so that we know we’re starting from the same base on every project.
Rails application templates arrived as part of Rails 2.3, and they go a long way towards automating the new-Rails-app process. Spend a little time crafting your ideal template, and you can use it to stamp out identical Rails skeletons, ready for development. If you write more than one or two Rails applications a year, and you haven’t written a template yet, you really should.
But what about the other step we mentioned above - setting up our new SCM repository? Surely we could automate that process as well. Several of the popular code-hosting sites have APIs to manipulate repositories. Why not programatically set up our SCM and check in the fruits of our templating labor?
That’s why we wrote Provisional. It picks up where the Rails application generator leaves off, setting up a Git or Subversion repository and putting your code in. It’s one less thing to do by hand, and that’s always a good thing.
Let’s take a peek. Go ahead and
gem install provisional, then run
provisional --help to check out the options:
$ provisional --help Options: --name, -n <s>: Name of the project --scm, -s <s>: SCM to use --template, -t <s>: Rails template to use --domain, -d <s>: Domain (for some SCMs, see documentation) --username, -u <s>: Username (for some SCMs, see documentation) --password, -p <s>: Password (for some SCMs, see documentation) --id, -i <s>: Id (for some SCMs, see documentation) --config, -c <s>: Config file (optional) --help, -h: Show this message
The three most important options are at the top: a name for your application; an SCM system to use; and the Rails template to apply. (The other options are used for identifying, and authenticating to, code hosting services. See the README for more information on how to use these.)
By default, Provisional will create a Git repository on your local system, ready to push out to wherever you’d like. If you’re hosting on GitHub, you can specify that, and Provisional will create a new repository on GitHub, set it as origin, and push out to master. Likewise for Unfuddle, a project-management site that can host both Git and SVN repositories; Provisional supports them both. (Have you got your own Git or SVN server inside your firewall? I’ll come back to you later.)
You can specify any Rails application template you like. As with running the generator directly, you can use a local template file, or a URL to a remote file. If you don’t choose, you’ll get the default template we use at Viget, which is a busy template indeed; it:
- freezes Rails from your currently installed gems
- installs one of our favorite testing stacks: Shoulda, Factory Girl and Mocha
- installs the Hoptoad notifier, so we can keep a handle on exceptions
- installs jRails, since we roll with jQuery these days
- installs our model generator with Factory Girl support
- installs our standard Capistrano setup
- installs our coverage enforcement plugin
- cleans up various things we don’t use, like the default
(You’ll find it under
lib/provisional/templates/viget.rb in the gem, if you’d like to fork it and write your own.)
And that’s pretty much it. There are some other things it could do, but currently doesn’t. It won’t set up your production server for you; Sprinkle’s got that market covered. It’d be nice if it set up continuous integration, but we haven’t settled on our one true CI server yet. Maybe that’ll be a future add-on. For now, that’s it for Provisional; go forth and bootstrap!
“Hey, wait!” you say. “I’m hosting my own Git or SVN server inside my firewall. You said you’d come back to me later.” We haven’t forgotten you. Actually, at Viget, we’ve had Git and SVN inside our firewall for years. Since we use Provisional for our own projects, we need to handle this kind of setup. Before Provisional, we had a couple of shell scripts on our Git/SVN server that we used to create new, empty repositories with access for everyone in the company. They were handy, and worked well, but weren’t that easy to automate.
So we wrote Repo Man, a very simple (perhaps too simple) Rails application to create repositories. Originally, we had written Repo Man to let our design staff create repositories for non-code purposes. All we had to do is add some controller logic to respond to Active Resource calls, and it became API-capable just like the code hosting sites. And with that, the Provisional-Repo Man bridge was a snap to create.
Repo Man can work with your internal SCM setup if it runs on a Linux or UNIX-like system. You’ll just need to create some scripts like the ones we wrote in the beginning (which are provided with Repo Man as examples.) And you’ll probably want to add some support for your local authentication scheme. But Repo Man will get you pretty close to what you need to work with Provisional.
And there you have it - a complete system for automating those crucial early bootstrapping tests. It’s just one more step in our ongoing quest to automate everything we do more than once. (Except writing these blog posts, of course. That still requires a human touch…)