Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Capify #1

Merged
merged 1 commit into from

1 participant

@illarionov
Owner

No description provided.

@illarionov illarionov merged commit db598f2 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 23, 2013
  1. @illarionov

    Capify

    illarionov authored
This page is out of date. Refresh to see the latest.
View
1  .rvmrc
@@ -0,0 +1 @@
+rvm ruby-1.9.3-p374
View
6 Capfile
@@ -0,0 +1,6 @@
+require "bundler/setup"
+load 'deploy'
+# Uncomment if you are using Rails' asset pipeline
+load 'deploy/assets'
+load 'config/capdeploy' # remove this line to skip loading any of the default tasks
+
View
43 Gemfile
@@ -1,44 +1,25 @@
source 'https://rubygems.org'
gem 'rails', '3.2.11'
-
-gem 'sass'
gem 'haml'
-
-gem 'sass-rails'
gem "haml-rails"
-
-# Bundle edge Rails instead:
-# gem 'rails', :git => 'git://github.com/rails/rails.git'
+gem 'jquery-rails'
+gem 'rvm'
+gem 'sass'
+gem 'sass-rails'
gem 'sqlite3'
+gem "unicorn", ">= 4.3.1", :group => :production
-
-# Gems used only for assets and not required
-# in production environments by default.
group :assets do
- gem 'coffee-rails', '~> 3.2.1'
-
- # See https://github.com/sstephenson/execjs#readme for more supported runtimes
- # gem 'therubyracer', :platforms => :ruby
-
- gem 'uglifier', '>= 1.0.3'
+ gem 'coffee-rails', '~> 3.2.1'
+ gem 'uglifier', '>= 1.0.3'
end
group :development do
- gem 'therubyracer'
- gem 'debugger'
+ gem 'capistrano'
+ gem 'capistrano-recipes0', :git => 'git://github.com/BrandyMint/capistrano-recipes0.git'
+ gem 'rvm-capistrano'
+ gem 'debugger'
+ gem "therubyracer", '~> 0.11.2', :platform => :ruby
end
-gem 'jquery-rails'
-
-# To use ActiveModel has_secure_password
-# gem 'bcrypt-ruby', '~> 3.0.0'
-
-# To use Jbuilder templates for JSON
-# gem 'jbuilder'
-
-# Use unicorn as the app server
-# gem 'unicorn'
-
-# Deploy with Capistrano
-# gem 'capistrano'
View
41 Gemfile.lock
@@ -1,3 +1,10 @@
+GIT
+ remote: git://github.com/BrandyMint/capistrano-recipes0.git
+ revision: 7dcad02f2e2a4c52f7286b9777818b8ff2609ae1
+ specs:
+ capistrano-recipes0 (1.1.2)
+ capistrano (>= 2.0.0)
+
GEM
remote: https://rubygems.org/
specs:
@@ -30,6 +37,12 @@ GEM
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.4)
+ capistrano (2.14.1)
+ highline
+ net-scp (>= 1.0.0)
+ net-sftp (>= 2.0.0)
+ net-ssh (>= 2.0.14)
+ net-ssh-gateway (>= 1.1.0)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -54,6 +67,7 @@ GEM
activesupport (>= 3.1, < 4.1)
haml (~> 3.1)
railties (>= 3.1, < 4.1)
+ highline (1.6.15)
hike (1.2.1)
i18n (0.6.1)
journey (1.0.4)
@@ -61,12 +75,21 @@ GEM
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.7.6)
+ kgio (2.8.0)
+ libv8 (3.11.8.13)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.19)
multi_json (1.5.0)
+ net-scp (1.0.4)
+ net-ssh (>= 1.99.1)
+ net-sftp (2.0.5)
+ net-ssh (>= 2.0.9)
+ net-ssh (2.6.3)
+ net-ssh-gateway (1.1.0)
+ net-ssh (>= 1.99.1)
polyglot (0.3.3)
rack (1.4.4)
rack-cache (1.2)
@@ -90,10 +113,14 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
+ raindrops (0.10.0)
rake (10.0.3)
rdoc (3.12)
json (~> 1.4)
ref (1.0.2)
+ rvm (1.11.3.5)
+ rvm-capistrano (1.2.7)
+ capistrano (>= 2.0.0)
sass (3.2.5)
sass-rails (3.2.6)
railties (~> 3.2.0)
@@ -105,7 +132,8 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.7)
- therubyracer (0.11.0)
+ therubyracer (0.11.3)
+ libv8 (~> 3.11.8.12)
ref
thor (0.16.0)
tilt (1.3.3)
@@ -116,19 +144,28 @@ GEM
uglifier (1.3.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
+ unicorn (4.5.0)
+ kgio (~> 2.6)
+ rack
+ raindrops (~> 0.7)
PLATFORMS
ruby
DEPENDENCIES
+ capistrano
+ capistrano-recipes0!
coffee-rails (~> 3.2.1)
debugger
haml
haml-rails
jquery-rails
rails (= 3.2.11)
+ rvm
+ rvm-capistrano
sass
sass-rails
sqlite3
- therubyracer
+ therubyracer (~> 0.11.2)
uglifier (>= 1.0.3)
+ unicorn (>= 4.3.1)
View
39 config/capdeploy.rb
@@ -0,0 +1,39 @@
+#Приложение
+set :application, "chart.icfdev.ru"
+
+#Репозиторий
+set :scm, :git
+set :repository, "git@github.com:BrandyMint/chart_test.git"
+set :deploy_via, :remote_cache
+set :scm_verbose, true
+ssh_options[:forward_agent] = true
+
+#Сервер
+server 'icfdev.ru', :app, :web, :db, :primary => true
+set(:current_branch) { `git branch`.match(/\* (\S+)\s/m)[1] || raise("Couldn't determine current branch") }
+set :branch, defer { current_branch } unless exists?(:branch)
+set :rails_env, "stage"
+
+#Учетные данные на сервере
+set :user, 'wwwdata'
+set :deploy_to, defer { "/home/#{user}/#{application}" }
+set :use_sudo, false
+
+#Все остальное
+set :keep_releases, 5
+set :shared_children, fetch(:shared_children) + %w(public/uploads)
+
+set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"") # Read from local system
+set :rvm_type, :user
+
+before 'deploy:setup', 'rvm:install_rvm'
+before 'deploy:setup', 'rvm:install_ruby'
+before 'deploy:restart', 'deploy:migrate'
+after 'deploy:restart', "deploy:cleanup"
+
+#RVM, Bundler
+require "rvm/capistrano"
+require "bundler/capistrano"
+require "recipes0/init_d/unicorn"
+require "recipes0/nginx"
+
View
6 config/database.yml
@@ -23,3 +23,9 @@ production:
database: db/production.sqlite3
pool: 5
timeout: 5000
+
+stage:
+ adapter: sqlite3
+ database: db/stage.sqlite3
+ pool: 5
+ timeout: 5000
View
11 config/environments/stage.rb
@@ -0,0 +1,11 @@
+ChartTest::Application.configure do
+ config.cache_classes = true
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+ config.serve_static_assets = false
+ config.assets.compress = true
+ config.assets.compile = false
+ config.assets.digest = true
+ config.i18n.fallbacks = true
+ config.active_support.deprecation = :notify
+end
View
13 config/setup_load_paths.rb
@@ -0,0 +1,13 @@
+if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
+ begin
+ gems_path = ENV['MY_RUBY_HOME'].split(/@/)[0].sub(/rubies/,'gems')
+ ENV['GEM_PATH'] = "#{gems_path}:#{gems_path}@global"
+ require 'rvm'
+ RVM.use_from_path! File.dirname(File.dirname(__FILE__))
+ rescue LoadError
+ raise "RVM gem is currently unavailable."
+ end
+end
+
+ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
+require 'bundler/setup'
View
130 config/unicorn.rb
@@ -0,0 +1,130 @@
+# Run: cd /project/; bundle exec unicorn_rails -c config/unicorn.rb -E production -D
+
+load File.expand_path('setup_load_paths.rb', File.dirname(__FILE__))
+
+ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
+require 'bundler/setup'
+
+rails_env = ENV['RACK_ENV'] || 'production'
+puts "Unicorn env: #{rails_env}"
+
+if rails_env=='production'
+ worker_processes 10
+ #TODO: избавиться от прописывания пользователя в нескольких местах
+ APP_PATH = ENV['APP_PATH'] || '/home/wwwdata/chart.icfdev.ru/'
+ working_directory APP_PATH + "current"
+
+ listen APP_PATH + "shared/pids/unicorn.sock"
+ pid APP_PATH + "shared/pids/unicorn.pid"
+ stderr_path APP_PATH + "shared/log/unicorn.stderr.log"
+ stdout_path APP_PATH + "shared/log/unicorn.stdout.log"
+elsif rails_env=='stage'
+ worker_processes 3
+ APP_PATH = ENV['APP_PATH'] || '/home/wwwdata/chart.icfdev.ru/'
+ working_directory APP_PATH + "current"
+
+ listen APP_PATH + "shared/pids/unicorn.sock"
+ pid APP_PATH + "shared/pids/unicorn.pid"
+ stderr_path APP_PATH + "shared/log/unicorn.stderr.log"
+ stdout_path APP_PATH + "shared/log/unicorn.stdout.log"
+else
+ APP_PATH = ENV['APP_PATH'] || '/home/wwwdata/chart.icfdev.ru/'
+ stderr_path "log/unicorn.stderr.log"
+ stdout_path "log/unicorn.stdout.log"
+ pid "tmp/unicorn.pid"
+
+ listen 4000, :tcp_nopush => true
+end
+
+# nuke workers after 30 seconds instead of 60 seconds (the default)
+timeout 60
+
+# combine REE with "preload_app true" for memory savings
+# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
+preload_app true
+GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true
+
+# Собираем статистику по сбору мусора на new_relic
+GC::Profiler.enable
+
+before_fork do |server, worker|
+ # the following is highly recomended for Rails + "preload_app true"
+ # as there's no need for the master process to hold a connection
+ defined?(ActiveRecord::Base) and
+ ActiveRecord::Base.connection.disconnect!
+
+ old_pid = Rails.root + '/tmp/pids/unicorn.pid.oldbin'
+ if File.exists?(old_pid) && server.pid != old_pid
+ begin
+ Process.kill("QUIT", File.read(old_pid).to_i)
+ rescue Errno::ENOENT, Errno::ESRCH
+ puts "Old master alerady dead"
+ end
+ end
+
+ # The following is only recommended for memory/DB-constrained
+ # installations. It is not needed if your system can house
+ # twice as many worker_processes as you have configured.
+ #
+ # # This allows a new master process to incrementally
+ # # phase out the old master process with SIGTTOU to avoid a
+ # # thundering herd (especially in the "preload_app false" case)
+ # # when doing a transparent upgrade. The last worker spawned
+ # # will then kill off the old master process with a SIGQUIT.
+ # old_pid = "#{server.config[:pid]}.oldbin"
+ # if old_pid != server.pid
+ # begin
+ # sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
+ # Process.kill(sig, File.read(old_pid).to_i)
+ # rescue Errno::ENOENT, Errno::ESRCH
+ # end
+ # end
+ #
+ # Throttle the master from forking too quickly by sleeping. Due
+ # to the implementation of standard Unix signal handlers, this
+ # helps (but does not completely) prevent identical, repeated signals
+ # from being lost when the receiving process is busy.
+ # sleep 1
+end
+
+after_fork do |server, worker|
+ # per-process listener ports for debugging/admin/migrations
+ # addr = "127.0.0.1:#{9293 + worker.nr}"
+ # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
+
+ # the following is *required* for Rails + "preload_app true",
+ defined?(ActiveRecord::Base) and
+ ActiveRecord::Base.establish_connection
+
+ child_pid = server.config[:pid].sub('.pid', ".#{worker.nr}.pid")
+ system("echo #{Process.pid} > #{child_pid}")
+
+ # if preload_app is true, then you may also want to check and
+ # restart any other shared sockets/descriptors such as Memcached,
+ # and Redis. TokyoCabinet file handles are safe to reuse
+ # between any number of forked children (assuming your kernel
+ # correctly implements pread()/pwrite() system calls)
+end
+
+
+
+# http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb
+# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
+# Spec's
+# http://sirupsen.com/setting-up-unicorn-with-nginx/
+# http://sleekd.com/general/configuring-nginx-and-unicorn/
+# https://gist.github.com/206253
+# https://gist.github.com/410309
+
+# nginx example:
+# https://github.com/defunkt/unicorn/blob/master/examples/nginx.conf
+# http://unicorn.bogomips.org/examples/nginx.conf
+
+
+# Examples:
+#
+# http://ariejan.net/2011/09/14/lighting-fast-zero-downtime-deployments-with-git-capistrano-nginx-and-unicorn
+#
+# upgrade + monit + rc.d:
+# http://shapeshed.com/journal/managing-unicorn-workers-with-monit/
+# https://gist.github.com/1221753
Something went wrong with that request. Please try again.