Goals of this tutorial:
- deploy a new Rails app with capistrano
- make it fast (total process takes less than 5 minutes)
- make it simple (no unecessary config)
- manual ssh to the server not required
Rails application stack:
- nginx
- unicorn
- postgresql
Goals of this tutorial:
Rails application stack:
require "capybara" | |
html = DATA.read | |
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] } | |
sess = Capybara::Session.new(:selenium, app) | |
sess.visit("/") | |
__END__ | |
Add necessary libs
$ su
$ apt-get install autoconf automake autotools-dev build-essential bison bzip2 curl git libreadline5 libsqlite3-0 sqlite3 libsqlite3-dev libxml2-dev libmysqlclient-dev libreadline5-dev libruby openssl libssl-dev zlib1g zlib1g-dev zlibc vim libv8-dev nodejs
Add rvm
$ \curl -L https://get.rvm.io | bash -s stable --ruby
Add rvm initializer in .bashrc
0. rails new my_store && cd my_store | |
1. to Gemfile | |
remove gem 'rais', gem 'jquery-rails' | |
and add folowing rows: | |
------------------------------------------------------------------------------------------------------- | |
gem 'liquid', :git => 'git://github.com/Shopify/liquid.git' | |
gem 'spree', :git => "git://github.com/spree/spree.git", :branch => "1-3-stable" | |
gem 'spree_i18n', :git => 'git://github.com/spree/spree_i18n.git' | |
gem 'refinerycms', :git => "git://github.com/refinery/refinerycms.git"#, :branch => "2-0-stable" |
namespace :attachments do | |
task :migrate_to_s3 => :environment do | |
require 'aws/s3' | |
# Load credentials | |
s3_options = YAML.load_file(File.join(Rails.root, 'config/s3.yml')).symbolize_keys | |
bucket = s3_options[:bucket_name] | |
# Establish S3 connection |
$ cd /usr/src | |
$ wget http://nginx.org/download/nginx-1.0.15.tar.gz | |
$ tar xzvf ./nginx-1.0.15.tar.gz | |
$ rm -f ./nginx-1.0.15.tar.gz | |
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz | |
$ tar xzf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz | |
$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz | |
$ tar xzf openssl-1.0.1c.tar.gz && rm -f openssl-1.0.1c.tar.gz |
module MyApp | |
class Application < Rails::Application | |
if Rails.env == 'test' | |
require 'diagnostic' | |
config.middleware.use(MyApp::DiagnosticMiddleware) | |
end | |
end | |
end |
# As root user | |
# Update the OS | |
sudo apt-get update | |
sudo apt-get upgrade | |
sudo apt-get dist-upgrade | |
# Setup Hostname & TimeZone | |
echo "{{HOSTNAME}}" > /etc/hostname | |
hostname -F /etc/hostname | |
dpkg-reconfigure tzdata |
__or_fn = lambda do |*scopes| | |
where = [] | |
joins = [] | |
includes = [] | |
# for some reason, flatten is actually executing the scope | |
scopes = scopes[0] if scopes.size == 1 | |
scopes.each do |s| | |
w = [] | |
s.where_clauses.each do |where_clause| |
# put in config/application.rb | |
config.to_prepare do | |
::PagesController.module_eval do | |
caches_page :show, :unless => proc {|c| c.user_signed_in? || c.flash.any? } | |
caches_page :home, :unless => proc {|c| c.user_signed_in? || c.flash.any? } | |
end | |
::Page.module_eval do | |
after_save :clear_static_caching! | |
after_destroy :clear_static_caching! |