Rake vs. Thor for automation scripts?
Asked Answered
K

4

48

I want to automate things like:

  • Creating a new Ruby on Rails application with pre-selected database, Git initialize it, create a Heroku project, commit all files, etc.
  • Upload all files in folder to another computer through SSH, but do not overwrite files.
  • Upgrade Ubuntu, install all basic packages through apt-get.

From what I understand, tools for this are Rake and Thor, however, which one should I use?

Rake seems to me more de-facto and popular. I have heard people recommending Thor.

How do these stand to each other in a rundown?

Kendrakendrah answered 19/8, 2010 at 17:8 Comment(1)
Although @derick-bailey's answer is a great explanation of Rake vs. Thor, you probably should look into a configuration management tool like Chef or puppet for most of the System installation tasks (Upgrade ubuntu, install packages, ect). You should also look at Capistrano for deploying your rails app. Rake aren't the best tools for all these tasksPolyurethane
L
100

Rake and Thor serve different purposes.

Rake is a general build script tool that is project-specific. In other words, you put your rakefile into your project folder and in your project's source control, and you can create, build and do other automation tasks that are specific to your project in that rakefile. Rake requires a rakefile to run.

Thor is a general purpose command line scripting tool that makes it very easy to re-use scripts across many projects and to do project setup, etc., like you are suggesting. Thor allows you to "install" an executable script that you can call from anywhere on your system, similar to calling "ruby", "gem" or "rake" command lines. However, Thor's scripts are more suited to general purpose, cross-application automation because the Thor script does not rely on a file sitting in your project-specific folder. A Thor script is the entire script, packed and installed for re-use anywhere.

Based on your stated needs, you are better off using Thor because you will be able to install your script in one location and have it work anywhere on your system. You will not be bound to where a Rake file is sitting or anything like that.

By the way, Rails 3 uses Thor for pretty much everything that is not project specific. You still have a Rake file and you still run things like "rake db:migrate" or "rake test:units". Thor is used for things like "rails new ...", "rails server" and "rails generate ..." The use of Thor AND Rake in Rails 3 is the perfect illustration of where each of these tools is best suited.

Legit answered 20/8, 2010 at 14:22 Comment(5)
Excellent explanation! I wished this was on some blog or on Thor's homepage =) Is the "rails" command a Thor script or does it use Thor somehow?Kendrakendrah
It's a good answer, but @Tom Corbin's answer is in some ways better. The chosen answer is the best eval of the usage of Thor vs. Rake – but in reality, the OP should use a configuration manager like Chef to perform most of* what they state. (* for the rest, Thor is better than Rake.)Jinny
ummmmm, this is thor's description "A scripting framework that replaces rake and sake". So Thor is a replacement for rake but not really?Woodard
If you have the time to learn Puppet or Chef -- learn Docker instead.Mymya
I don't think rake is only project specific, you can define global rake tasks :)Scepter
N
13

For setting up Ubuntu chores, Chef might be a better option.

From their web site:

Chef is an open source systems integration framework, built to bring the benefits of server configuration management to your entire infrastructure.

It's written in Ruby and there are tons of Chef recipes/cookbooks. Chef will handle setting up Ubuntu and installing packages, servers, etc.

I don't know if you are working with virtual machines, but Vagrant will set up a virtual machine and then use Chef to configure it.

Nathan answered 14/4, 2011 at 15:29 Comment(2)
I know this answer is old but now anyone coming here may also want to take a look at Docker!Photocompose
Itamae ( a light Chef; github.com/itamae-kitchen/itamae ) + Docker is one of choice. I'm happy on this for that kind of virtual machine + provisioning situation (even though itamae + docker has some trouble, itamae ssh + docker sshd is a workaround)Incorporation
W
1

There is something important to mention here.

http://guides.rubyonrails.org/generators.html in its section 8 Application Templates.

You can execute git commands, select gems, capify project.

And you could also execute system commands to satisfy your last point: Upgrade Ubuntu, install all basic packages through apt-get.

Wheelman answered 7/9, 2013 at 22:56 Comment(0)
U
0

I would go with puppet.

By the way, maybe vagrant is useful to you?

Unskillful answered 4/9, 2012 at 11:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.