Deploy Sinatra Application with Capistrano
MAY
25
2010
Step 0: Vendor the sinatra gem (optional).
mkdir vendor cd vendor gem unpack sinatra mv sinatra-* sinatra
Step 1. Create a config.ru Rack file in your project's root directory.
require 'rubygems' require 'vendor/sinatra/lib/sinatra.rb' set :public, File.expand_path(File.dirname(__FILE__) + '/public') # Include your public folder set :views, File.expand_path(File.dirname(__FILE__) + '/views') # Include the views set :environment, :production disable :run, :reload require 'app_file' # replace this with your sinatra app file run Sinatra::Application
Step 2. Create a Capistrano deploy file.
set :domain, "yourdomain.com"
set :application, "app_name"
set :deploy_to, "/var/www/apps/#{domain}"
set :user, "your_deploy_user"
set :use_sudo, false
set :scm, :git
set :repository, "git@github.com:you/application.git"
set :branch, 'master'
set :git_shallow_clone, 1
role :web, domain
role :app, domain
role :db, domain, :primary => true
set :deploy_via, :remote_cache
namespace :deploy do
task :start do ; end
task :stop do ; end
# Assumes you are using Passenger
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
task :finalize_update, :except => { :no_release => true } do
run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
# mkdir -p is making sure that the directories are there for some SCM's that don't save empty folders
run <<-CMD
rm -rf #{latest_release}/log &&
mkdir -p #{latest_release}/public &&
mkdir -p #{latest_release}/tmp &&
ln -s #{shared_path}/log #{latest_release}/log
CMD
if fetch(:normalize_asset_timestamps, true)
stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
asset_paths = %w(images css).map { |p| "#{latest_release}/public/#{p}" }.join(" ")
run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
end
end
end
Step 3: Deploy the app.
cap deploy:setup cap deploy
Step 4: Get a beer, you're done!
Tagged: capistrano, sinatra
Nashville Rails Meetup Presentation - "Capistrano"
APR
24
2010
Here is the presentation I gave at the April 2010 Nashville Ruby on Rails Meetup.
Tagged: capistrano, ruby on rails, rails
Nashville Rails Meetup Presentation - "Rails Page Caching"
FEB
19
2010
Here is the presentation I gave at the February 2010 Nashville Ruby on Rails Meetup.
Tagged: rails, ruby on rails, caching
Download Files with Ruby
FEB
17
2010
This weekend, I remembered an old podcast I used to listen to that I wanted to hear again. It wasn't available on iTunes anymore, so I did a Google search for it. I found the show's Web site, and saw that they had a complete archive of all four seasons of the podcast (20 episodes per season). The problem was, each episode was on it's own page, with a separate page to access the download link. I started to manually try to download each episode, but that got old REALLY quickly. Why not write a simple script to do the work for me?
Here's the Ruby script I whipped up in about 15 minutes:
require 'net/http'
1.upto(4) do |season|
1.upto(20) do |episode|
episode = '%02d' % episode
puts "Downloading Season ##{season}, Episode ##{episode}"
Net::HTTP.start("website.com") do |http|
resp = http.get("/episode_archive/s#{season}ep#{episode}.mp3")
open("s#{season}ep#{episode}.mp3", "w") do |file|
file.write(resp.body)
end
end
puts "Episode downloaded!"
puts
end
end
puts "All files downloaded!!"
An explanation of what's going on here:
Lines #3-4: There are 4 seasons and 20 episodes per season, so iterate through them.
Line #5: We need to left pad the episode numbers, because that's how the files are named.
Line #7: Connect to the host.
Line #8: Get the episode (named like "s1ep05.mp3").
Lines #9-11: Save the file using the same name.
URL ABC
JAN
20
2010
Idea taken from http://2009.maxvoltar.com/articles/url-abc.
- A: http://www.amazon.com/
- B: http://blog.us.playstation.com/
- C: http://code.google.com/apis/chart/
- D: http://www.drupal.org/
- E: http://www.etsy.com/
- F: http://www.flickr.com/
- G: http://www.google.com
- H: http://www.hulu.com/
- I: http://www.imdb.com/
- J: http://www.johnnycache.net/
- K: http://www.kbb.com/
- L: http://listode.com
- M: http://malsup.com/jquery/cycle/
- N: http://www.netflix.com/
- O: http://oceanfutures.org/
- P: http://www.pandora.com/
- Q: http://qbnz.com/highlighter/
- R: http://revision3.com/
- S: http://www.singerco.com/
- T: http://twitter.com/
- U: http://us1.admin.mailchimp.com/
- V: http://vampireweekend.com/
- W: http://www.wikipedia.org/
- X:
- Y: http://www.youtube.com/
- Z: http://www.zumba.com/us/
Tagged: fun
Popular Posts
Search
Tags
actionmailer activerecord ajax apache apple barcamp caching capistrano centos code golf css db delete eager loading ebay email attachment erb flash ftp fun generators get haml helpers ie sucks javascript jquery lightbox lost merb net ftp paperclip passenger php plexus post presentation rails rails machine railsconf redesign rest rjs routes rss ruby ruby on rails safari script sinatra symfony text replacement tips tutorial twitter xhtml
Projects
© 2010 Travis Roberts. All rights reserved.