As a thought about the post that I wrote the other day. I figured why not just turn it into a gem? This would be a good excuse for me to write my first command line gem and also learn all the intricacies involved with it. So without further ado, here it is: bam the easiest, most fastest way to deploy your project! It’s super simple to get going and use too!
Installation
gem install bam # => you might need sudo here
Usage
cd into/your/project/root
bamify
# it should generate a deploy.bam file, go ahead and open it up and update it
# do some work on your project
bam
That’s it! No DSL to learn, a minimal amount of ceremony involved with setting it up, and best of all, the deploy file just involves setting 2 variables at the minimum. Now you to can deploy your recipes, er, I mean your site or project the Emeril Lagasse style with BAM! There’s also some variables to allow you to do some pre deployment tasks and post deployment tasks that are limited to running commands locally, but most of the time I don’t need them and honestly if it gets more complicated than that, just do yourself a favor and use capistrano.
Ok enough talk, show me already!
Alright here’s a basic demo of how it works:
Get the source at http://github.com/vanntastic/bam if you want to fork it. Here’s a quick video of Emeril reminding you how fast and simple your deployments can be:
As I’ve mentioned before, I’m a huge fan of using rsync for deployment. When working on smaller sites and projects, I find that the other deployment method that I use; capistrano, is a bit of overkill, I rarely, if ever need to rollback revisions or share assets across deployments on simple websites. Since I use git, I can rollback revisions and ignore certain files using .gitignore. With that said, I think that I’ve come up with the most simple and perfect way to deploy small projects. This assumes that you use the following:
OSX or any *nix variety OS (haven’t tested it on ubuntu, but I assume this’ll work the same)
rsync / ssh
git
and of course ruby
textmate or any other editor that accepts textmate’s bundle snippet system
Add the following snippet to your bundles:
Assign the word deploy for the snippet expansion.
Add a file called deploy.rb to the root of your project, make sure and chmod 755 it.
Type deploy and expand the snippet and fill in your deployment details.
Once you are ready, just run ./deploy.rb in the terminal.
The great thing about this is that you ignore files on deployment simply by using .gitignore and rollback using git. Why attempt to re-do those things when git does such a good job of it itself? Enjoy!
Phusion Passenger Lite can listen on a Unix domain socket instead of a TCP socket, just like Thin and Unicorn. In reverse proxy setups this can yield much higher performance than TCP sockets.
# should be in Ruby Core
class String
# grab the first character
def first
self[0..0]
end
# grab the last character
def last
self[(self.length-1)..(self.length-1)]
end
end
However, I was still getting errors in that looked like:
ArgumentError (wrong number of arguments (3 for 2)):
/vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb:33:in `check_auth_args'
/vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb:33:in `do_tls_start'
/vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb:18:in `send'
/vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb:18:in `start'
/vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb:10:in `start'
/vendor/plugins/action_mailer_optional_tls/lib/action_mailer_tls.rb:9:in `perform_delivery_smtp'
Browsing through the comments in that link mentioned above reveals that you must update a call to check_auth_args at about line 33, so here’s what you do:
# go to line 33 and change:
check_auth_args user, secret, authtype if user or secret
# to this (remove authtype):
check_auth_args user, secret if user or secret
It’s a quick hack I know…, but sometimes you just need to get something working so that you can get on with your day :/
I’m a big fan of the less command, which allows you to read files similar to vim, except without the editing capability. I use it a ton to quickly scan through text files and even programmatically push text through it. When I use script/console, I sometimes find it handy to use less as a quick way to view a bunch of content or even a nice way to output arrays. Simply add the following method to ~/.irbrc :
# hook for the system's less command, allows you to pass in arrays too!
# EX :
# less "A bunch of content"
# less %w(1 2 3)
# less [1,2,3]
def less(content)
content = content.join("\n") if content.is_a?(Array)
system('echo "' << content << '"|less')
end
Using git and rails together? Need some git love in your console? Here’s a list of command git commands that I often use, abstracted into a method, just throw this in ~/.irbrc :
# git hook
def git(*args)
if args.length == 1
# EX : git :st
# git "push origin master"
cmd = "git #{args.first.to_s}"
elsif args.length > 1
# EX : git :st, :origin, :master
# git :push, :origin
cmd = args.first.to_s
args.delete_at(0)
arg = args.join(" ")
cmd = "git #{cmd} #{arg}"
elsif args.blank?
cmd = "git [*cmd] or git.[st|ci|push|config]"
end
cmd.instance_eval do
# git.st
def st
system("git st")
end
# git.ci 'msg'
def ci(msg)
system("git add .;git commit -m '#{msg}'")
end
# git.push 'args'
def push(args=nil)
args.nil? ? system("git push") : system("git push #{args}")
end
# git.url
def url
system 'cat .git/config | grep url'
end
# git.config
def config
system 'vi .git/config'
end
end
args.blank? ? cmd : system(cmd)
end
Now you can do things like:
# git status
>> git.st
>> git :st
# git push 'msg'
>> git.push 'msg'
>> git :push 'msg'
# you can even modify the config in vi from the console
>> git.config