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:
#!/bin/bash | |
# Fail if any commands fail | |
set -e | |
set -o pipefail | |
# These are ec2 tags from which we will determine where to deploy | |
ec2_stage=$DEPLOY_STAGE | |
ec2_app="core" | |
ec2_role="app" |
images = @album.image_assignments | |
changed = Array.new | |
# Get the images that changed order | |
for image in images | |
order = params["order_#{image.image_id}".to_sym] | |
if !order.blank? && order =~ /^\d+$/ && image.position.to_i != order.to_i | |
image.position = order.to_i | |
changed << image |
# 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! |
__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| |
# 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 |
module MyApp | |
class Application < Rails::Application | |
if Rails.env == 'test' | |
require 'diagnostic' | |
config.middleware.use(MyApp::DiagnosticMiddleware) | |
end | |
end | |
end |
$ 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 |
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 |
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" |