I had started talking about setting up a development and production environment with git for Typo in this post. Because of this new version of Typo, I have finally had a very good reason to change the set up of this blog and to migrate to git. Installing Typo from its git repository, I have had the opportunity to use the git submodules. That is why in this post I will use the Typo blog engine to make a case study for the use of git with:
- Several repos for development, production and deployment
- Several repos for open source development
- Use of submodules for plugin management and development
Indeed, my own aims for this new setup are to:
- Have a test environment and a production environment for this blog
- Be able to update the blog engine from its main repository
- Be able to contribute to this open source blog engine
- Manage properly rails plugins
- Be able to contribute to these plugins
The final setup is as following, represented on the figure below:
- I have a repository where I develop and test Typo. This repo is first created by cloning Typo’s repo. From my point of view this is the main repo. Indeed I can pull from Typo’s repo or push to it. in the same way I can push to the production repo, to deploy. Deployment can be managed easily by Capistrano in this configuration. Notice that several branches can be contained in the repo (public branch pushed to the main repo, private production branch, etc.)
- Production repo. The actual production code is a checkout from this repo.
- My public dev repo. It contains the changes I can propose to Typo’s dev team through a ‘pull request’.
- Main repo. Currently it is Fred’s repo but thanks to git architecture it could be as well the public repo of who you want.
- Fred’s private repo. He may have several dev repos, with plenty of branches, on several computers .
- Cyril’s public repo.
- Cyril’s private repo
For each repo, the plugins are put in subrepo and managed through git submodules. That is, each plugin has its own repo and is not included in Typo’s repo. However, the beauty of the submodules is that you can really easily develop and update your plugins.
Now let’s go for a detailed tutorial to set this up.
This setup is for people willing to have a full development environment. However, if you just want to install Typo, you simply need to skip the first step, the creation of the public repo. And in this case you can consider that your public user name is ‘fdv’ but you will not be able to push to the repos.
Create your dev repo
Then, clone the Typo repo from your public repo. Type this command in the local directory of your choice. Replace the user name harryseldon by your name.
git clone git://github.com/harryseldon/typo.git
To be able to update your dev repo with the latest changes, add the address of the main repo:
git remote add main_typo git://github.com/fdv/typo.git
Then to update your copy, you simply need to pull the changes:
git pull main_typo master
NB. The repo you clone from will be called ‘origin’ in your local copy. If you prefer you can initially clone from the main repo and then add the address of your github repo.
In order to run, like every Rails app, Typo requires some plugins. They are managed through the git submodules. So you just need to run:
[EDIT 3/8/2009] Typo plugins are now managed using gems, check this post.
git submodule update --init
With this command the plugins will be pulled from the addresses written in the .gitmodules file which looks like this:
[submodule "vendor/rails"] path = vendor/rails url = git://github.com/rails/rails [submodule "vendor/actionwebservice"] path = vendor/actionwebservice url = git://github.com/datanoise/actionwebservice.git [submodule "vendor/plugins/rspec"] path = vendor/plugins/rspec url = git://github.com/dchelimsky/rspec.git [submodule "vendor/plugins/rspec-rails"] path = vendor/plugins/rspec-rails url = git://github.com/dchelimsky/rspec-rails.git [submodule "vendor/plugins/will_paginate"] path = vendor/plugins/will_paginate url = git://github.com/mislav/will_paginate.git
If you have your dev version of one of these plugins, do not hesitate to change the address to point to your public repo.
Then you may want to install your preferred Typo plugins. The ones you have just forked on github.
git submodule add git://github.com/harryseldon/typo_related_posts.git vendor/plugins/typo_related_posts git submodule add git://github.com/harryseldon/recentposts_sidebar.git vendor/plugins/recentposts_sidebar git submodule add git://github.com/harryseldon/recent_comments_sidebar.git vendor/plugins/recent_comments_sidebar
git submodule update --init
To use Typo in your dev environment, you finally need to configure your database. Use your usual settings and run the migrations. Typo will work like any other Rails app.
Like any other git repo, feel free to create as many branches as you like. For instance you can create a production branch:
git branch typo_production
You would typically set the environment to production in environment.rb.
Create your production repo
Assuming an ssh connection, you create the repo on your host in a ~/git/Typo directory.
You add the address of this repo to your dev repo:
git remote add production_repo ssh://firstname.lastname@example.org/home/user/www/git/typo/.git
Now you can push your code to production. Let us say you created a special production branch,
git push production_repo typo_production
This step could be done using Capistrano and pushing the development branch. Capistrano would be typically in charge of making the changes in environment.rb.
Assuming you made some changes in your dev repo. You commit them:
git commit -a -m "my changes"
Then you can push them to your public repo:
Accordingly with the previous NB, this is equivalent to:
git push origin master
Then from your github account, you can send a “pull request” to Typo maintainers if you would like to see your changes included in the official Typo code.
As far as the plugins are concerned, the process is similar. You cd to your plugin folder which is under a git version control and you can push, just like for the Typo repo.
Following this tutorial, you have installed a typical environment for a Rails application under git version control.
Feel free to leave comments about the git environment or the Typo installation.
Use the following link to trackback from your own site:
For some time, I have wanted to post about "crises are natural preludes to wars". I am definitely not that qualified to say that, so [I am glad these guys (LEAP experts) are](http://www.leap2020.eu/English_r25.html). They predicted quite well the ...
I have updated this blog engine in order to install the recently added Feedburner support. My recent post about [Rails heroes RSS feeds](http://harryseldon.thinkosphere.com/2009/02/03/read-your-rails-heroes) clearly showed me that feedburner was a...