articles tagged with typo

Part 2. Setup Capistrano on the Rails app and run a test deploy to your server

1 comment

Starting Point

  • You have got your Rails app under version control with SVN as described in the first tutorial
  • First make sure you have Capistrano installed, you can get it as a free Ruby gem with;
    gem install capistrano
  • ‘Apply’ capistrano to your Rails app on the dev box, this creates some config files locally for Capistrano deployment to work.
    cap --apply-to /u/apps/sitename.com sitename.com
  • Edit the Capistrano’s deploy configuration in /u/apps/sitename.com/config/deploy.rb to set the correct roles for your server;
    set :repository, "svn+ssh://matt@dagobah/svn/#{application}"
    role :web, "server"
    role :app, "server"
    role :db,  "server"
    set :deploy_to, "/u/apps/#{application}"
    
  • From within the Rails directory (/u/apps/sitename.com) run the rake ‘setup’ task to remotely setup Capistrano’s directories on your server;
    rake remote:exec ACTION=setup
  • Try a test deploy to the server (may ask for password during sudo) this will;
    • Checkout the latest revision of your application from your remote repository to the /u/apps/sitename.com/releases directory on your server
    • Update (or create) the /u/apps/sitename.com/current symlink so it points to this new revision
      rake deploy
  • If all goes well, your Rails app should be checked out under /u/apps/sitename.com/current on your remote server. Run ‘rake deploy’ again if you like and see what happens. A new ‘release’ will be checked out to /u/apps/sitename.com/releases/timestamp/ and the symlink at /u/apps/sitename.com/current will be automatically setup to point to it.

Capistrano Tips

  • Obviously with lots of deploys, you’ll start getting loads of release directories on your server, all containing your entire Rails app. You can run the ‘cleanup’ command to remove older releases. In config/deploy.rb – set the following to say how many releases you’d like to keep after a cleanup
    set :keep_releases, 3
  • Then in the Rails directory run;
    cap cleanup

So there you have it, you can now deploy using Capistrano to your server from your dev box and your Rails app is safely under SVN version control. There is loads more you can do with Capistrano (see the links below)

In the next part of this guide, I’ll go through building the hosting stack (lighttpd/pound/mongrel) on your server. And making use of Capistrano to help with deploying your versioned Rails app around an unversioned folder containing the mints/ stats package (which we’ll also get running under PHP with lighttpd)

References

Part 1. Setting up SVN on a working Typo build (or any Rails app)

no comments yet, post one now

So in this post its all about getting your existing Typo (or rails app) under version control with SVN.

Starting Point

  • Have a rails site working and using lighttpd on your local dev box under /u/apps/sitename.com
  • Your remote server has SVN installed (try svn -v) and Rails/Lighttpd installed
  • Make sure you have an ssh key setup for accessing your server from your dev box
  • If you will have multiple users checking in and out and using Capistrano/SVN – set them all up a with ssh keys and create a new ‘developer’ group on the server (that has permissions on svn repository folders and /u/apps/)
  • Note: if you make a mistake, you can use this command to clean away all svn folders from the CWD downwards
    find . -type d -name '.svn' -print0 | xargs -0 rm -rdf 

Create SVN repository on svn server, checkin all rails code, then check out a working copy again

  • Login to the server and create a top level directory svn to hold your repositories;
    mkdir /svn
  • Create a new repository in it with;
    svnadmin create /svn/sitename.com
  • On your dev box, import the entire rails app to this new repository on ‘server’ with a simple comment;
    svn import -m "initial import" /u/apps/sitename.com svn+ssh://matt@server/svn/sitename.com
  • On dev box, rename /u/apps/sitename.com to sitename.com.stepaside – you could delete it before checking out your working copy, but its safer to do this in case anything goes wrong.
    mv /u/apps/sitename.com /u/apps/sitename.com.stepaside
  • Now checkout from the new svn repository to your dev box with;
    svn co svn+ssh://matt@server/svn/sitename.com /u/apps/sitename.com/
  • If all is ok, you can now delete sitename.com.stepaside
    rm -r /u/apps/sitename.com.stepaside

SVN Tips

  • You can run svn update, to update your current working copy with the latest from the server repository;
    svn update /u/apps/sitename.com
  • You can run svn commit -m “comment” to commit all changes from your working copy to the repository on the server
    svn commit -m "your comment" /u/apps/sitename.com
  • You can run svn status to see what files have changed or are not under version control;
    svn status /u/apps/sitename.com
  • You can add files/folders to svn’s ignore list for a particular file under version control using propedit; e.g. to set whats to be ignored in the config/ folder;
    svn propedit svn:ignore config/
  • This will popup a text editor (usually vim) – allowing you to specify files/folders inside config/ to ignore – e.g. .rb or deploy etc. In vim, press I to start editing (inserting), edit the file and press Esc and ‘ZZ’ to save and exit. (easy!) – Of course for these ignores to take place you’ll have to do an svn commit.
  • IMPORTANT for these ignores to work on files/folders that are already under SVN version control, you’ll first have to un-version and delete them; So back up the file/folder first then SVN remove it with;
    svn remove /path/to/file
  • Then place the backed up file/folder into your working copy again (if its a folder, delete any .svn folders in it) (Its a real pain, but ‘svn status’ is your friend during this process)
  • You can run svn status —no-ignore to see what files you’ve added to svn’s ignore list (these don’t get version controlled
    svn status --no-ignore /u/apps/sitename.com

References

Intro. All kinds of 'newness'

1 comment

So here we are, your looking at a fresh new install of Typo 4.0, with my custom theme, migrated blog content and mint stats running on a new VPS host, all served up on a platter with a new hosting stack (Lighttpd/Pound/Mongrel) – So basically, all kinds of ‘newness’.

As I mentioned – in the next couple of posts, ill try to walk through what it took to set this up. There are lots of guides already out there that take you through parts of this process, but I am attempting to gather my entire experience together and apply it to an existing Rails application (this Typo blog) – Working with a real Rails app like this, you come across ‘gotchas’ that you wouldnt normally see with a fresh vanilla Rails.

I have taken to using a blank page on my wiki scratchpad to log what I do, when I do it. What you get below is basically a cut & paste from there. Im working with a Mac/OSX as my local development machine and a Debian Rimuhost VPS as my server. Im assuming you have root access on both boxes to do this. And while you could do all this with Windows – I choose not to (I’ve been down that road before)

Terms Used

  • server (production/svn server) – the remote box hosting the svn repository and live website, and its alias on your local dev box
  • dev box – local client machine contains working copy of site
  • sitename.com – domain name of site
  • CWD – abbreviation for current working directory
  • Rails directory – the top level Rails dir, i.e. the one containing app/ config/ public/ etc.
  • start reading PART 1

Coming soon...

no comments yet, post one now

After deciding to take a break from freelance work for the next couple of months, Ive had some time to sort a few things out here on this blog (and in doing so, learnt a thing or to).

Very soon I’ll be moving this site to my shiny new VPS server at Rimuhost, now armed with root access – all manner of crazy things can happen. Ive spent some free time over the last couple of weeks doing the following;

  • Tidied up all the CSS here
  • Moved all my Rails development from Windows to OSX
  • Setup a new VPS Debian server with Rimuhosting
  • Upgraded to Typo 4.0 and migrated this site’s theme into it
  • Switched my photos back to a Flickr Pro account from 23HQ
  • Moved this site to using SVN / Capistrano for deployment
  • Changed from using Apache FCGI, to a full Lighttpd, Pound and Mongrel stack.
  • Survived the London heat

So be prepared for all sorts of nerd like ‘how-to’ posts – as I attempt to share the knowledge and gotchas I experienced during all this (including the London heat) None of the changes to this site have been rolled out yet, its still sitting on Dreamhost running under Apache/FCGI.

Why bother? – The whole process has been a bit of learning exercise for myself and it means I can now quickly develop, deploy and host rails applications, faster and more reliably – which is good -you see.

New lick of paint

2 comments

Another month another redesign for the blog, this one I am happy with and
it will be here to stay (for a while at least) – A lot of gumpf has been
removed from the side bar, and the whole thing should be a little faster
to load.

I have also switched to FeedBurner – for all
my feed needs. Redirects are in place, but update your RSS bookmarks if
you’ve got ‘em. (see the ’feedTower’ at the bottom of every page)

I’ve even created a little css block to publish up conversations from
IRC

Somethings up with submitting comments and (as usual) there is one
annoying CSS bug I still have to iron out in IE – but thats life.

Anyone like/dislike the new look, comments appreciated.

May 11, 2006 13:00 by

Redesign

3 comments

After weeks of dilberating and few hours of work, Ive managed to finish building a new Typo theme for this site. Ive left announcing it here until now, because im still not happy with it. Part of me wants to remove all images (header, icon etc.) and go for something plainer and quicker. So i’ll probably do that – I actually prefer the look of the footer to the header which is really just a grungy placeholder image for now.

Theres a little bit of AJAX and some moo.fx in the sidebar now – which should speed loading times up a little on the homepage which used to use the rather heavier scriptaculous – and all entries and comments are now using Textile (instead of Markdown)

February 17, 2006 04:02 by

Typo Review

no comments yet, post one now

In part of our new re-think in developing Skribe we have decided to evaluate a bunch of blogging applications and services on the web. For anyone who might be interested here is my (positive) review of Typo – which i’ve been happily using here for a few months now. Its not a complete review by any means, and i’ve really only highlighted points that are relevant to our development and planning work. But read on if you like;

What is Typo ?

‘Typo is a lean engine that makes blogging easy’. Its an open source web application for a personal blog site, that can be installed (i.e. just unzipped and configured) on your web server. Its free and can be downloaded from here – the source files are also available in a public subversion repository. The latest version (as of Jan 06) is 2.6.0 (released Nov 05)

The first revision of Typo was written to power too biased, Tobias Luetke’s web blog. While he was waiting for a client at Starbucks he wrote down the wrong time for the appointment so naming it Typo seemed quite fitting. It was also one of the first open source Rails Blogging applications on the web – and perhaps still is.


What technology/software does it use ?

Typo is proudly powered by Ruby On Rails, and can be configured to link to either a MySQL or Postgres database. The server must support Rails, Ruby, and CGI. FastCGI is recommended for better performance. The blog can run on any HTTP server supporting Rails, including, WebBrick (Ruby web server), Apache (& Apache2) or Lighttpd


How is the database structured ?

After unpacking the release, you use a .sql file included in the release to generate a blank set of tables in the database. Installing Typo (although simple enough) is NOT for non-techies. Your expected to have a little knowledge of mySQL and FTP’ing files.

The db includes the following key tables; (there are 15 tables in all, but I’m only summarizing these important ones)

  • articles – created by the blog author(s), this holds the main content, title, author and id of each article. Body of the article is stored in 2 fields, one with the html encoded text, the other with the plain text with the markdown syntax. This means that the html parsing engine (e.g. markdown) is only used when articles are added/edited and not on the fly when rendering pages. The table also includes a permalink field – for direct url linking to the article page. And allow comments/trackbacks for individual articles.
  • comments – linked to an article_id, stores the actual comment (and the comment html in a separate field) – includes IP address, date/time, author, email, and url. Only author and comment are required. Note that IP logging is only done on comments, since you obviously need to be logged in to post articles.
  • categories – Categorisation on articles is achieved using this table and the following fields, id, name, position, permalink. A separate articles_categories mapping table simply maps articles to these categories. Any article can belong in none or more categories.
  • page_caches – contains a unique id and url to all pages (XML and html) cached by typo – I assume ruby caches pages frequently, you are given no control of this process in the admin, except clearing the cache. I haven’t looked into how typo caches pages – but in general use I have found it to be a little biased in caching, and sometimes I find myself clearing the cache in the admin to see immediate changes in my published site.
  • sessions – instead of using a temp session file, sessions (for the admin) are stored in this db table. Using a db table for session data is proven to be more secure than a file – especially on a shared hosting environment.
  • settings – general blog settings are stored here in a name/value arrangement – this is good for 2 reasons; it means settings aren’t stored in a hard to reach file – AND using name value pairs, more settings can easily be added to the table – should newer versions of typo require them.
  • trackbacksTrackbacks to your blog articles are stored here. Trackback is a mechanism used in a blog to show, around an entry, a list of other blogs that refer to it. I haven’t used it much, but it seems straightforward enough. Warning most of the trackbacks on my blog are from spam sites. So I’ve disabled them for now. I don’t think typo has very good (or any) spam protection on trackbacks.
  • sidebars – used by typo to keep track of what sidebar components are installed on the blog, their order and when they were last updated. Typo allows you to easily drag and add sidebar components like, Flickr images feed, delicious link feed, your blog article archive, plain html box, standard RSS feeds etc. Its a powerful feature that’s easy to use and is one thing typo does very well.

What templating system does it use ? – if any

Typo uses the Rails, MVC approach, with templates clearly separated in the view from the rest of the application. Typo allows ‘themes’ to be easily applied using the admin. Download and unzip the theme (which contains graphics, rhtml, javascript files etc.) – then use the admin to simply activate it.

Typo takes care of the rest – copying the necessary files from the theme to the public/ and views folders. I’m in the process of re-skinning typo right now, so I’ll know more about this whole process soon.

How does it perform ?

Lots of blogs including my own use Typo with no problems. The main issues with performance arise with the hosting environment and how they have configured their web server running Rails and FastCGI. I found that on Dreamhost, I had to write a cronscript to kill wandering FastCGI processes when Typo was used by more than a couple of users. It turns out this is not Typo’s fault, but Dreamhost’s. Generally page loading speed is very good and the application runs smoothly.

What does it do well ?

To summarise – Typo is very good at the following;

  • Importing RSS feed data from other web apps
  • Spam protection on comments
  • Applying Themes
  • Using html parsing engines (like markdown and textile)
  • Caching html and XML
  • Easy to use admin – very simple
  • Keeping things simple – db structure is straight forward
  • Easy to extend features and develop for the blog
  • Compatible with desktop blog clients like "MarsEdit"http://ranchero.com/marsedit/ etc.

What can be improved ?

  • Spam protection on trackbacks
  • No image/file uploading features
  • Admin is completely separate from the published website, tighter integration could help when making quick changes
  • Hard to install/configure for non tech users
  • More control over caching or better choice of caching periods
  • HTML parsing engines (markdown/textile) may be complicated for non web savvy users to learn
  • No formal migration process – to pull entries/comments from another blog, like MoveableType etc.
  • No backup or content extraction process – i.e. theres no way to download a copy of your Typo content.

What, if anything, may be of use in Skribe ?

Its hard to compare Typo directly to Skribe, given that Typo is a standalone blogging application that must be installed – opposed to Skribe, a web application offering a blogging service to a large number of interconnected users. To summarise then – the following points and features should be considered in planning Skribe development.

  • Uploading Images, Files, Resources for use in Blog entries
  • Importing and displaying of external feed data – e.g. standard RSS and additional extra support for Flickr and other services
  • Good Page caching for speed, more control over your own page cache options
  • Spam protection via a bad IP list and online spam listing (and spam protection on trackbacks)
  • Commenting and Trackbacks on/off on individual entries
  • Easier UI for content editing
  • Use of Textile/Markdown for advanced editing
  • Storing both parsed xHTML and non-parsed body text (again for speed)
  • Tighter integration of admin features with published content, e.g. in-place editing
  • Themes – not sure we want to go with this in Skribe, as an alternative, I suggest we create a simple API that will allow developers to hook into Skribe and get Skribe content out.
  • Skribe must be compatible with desktop blogging clients in one form or another
January 18, 2006 09:50 by

Blog Facelift

no comments yet, post one now

Although im not overly bored with this Scribbish Typo theme, I think its a good starting point for my own design which will be appearing soon.

I’ll be launching a full facelift for the whole blog; and will be trying to stick to some new basic design principles for blogs; (possibly introducing a few small flash movies too)…

November 24, 2005 16:35 by

Scribbish

no comments yet, post one now

Although its really only a very good starting point, I rather like this minimalist theme (scribbish) – bar a few minor tweaks here and there – it’ll be staying like this for a good while – I’ve got more important things to focus on for now.

I should find just enough time to write content, post often and keep some people entertained.

For now – I have added some ‘about’ info. (and fixed an issue running Scribbish on Typo 2.6.0)

November 14, 2005 17:22 by
← (k) prev | next (j) →