Last active
August 29, 2015 13:56
-
-
Save bsa7/9318206 to your computer and use it in GitHub Desktop.
Worked recipe at 2014.03.09 - Rails 4.0.3 + Ruby 2.1.0 + puma 2.8.0 + capistrano 2.15.5 + nginx 1.4.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Для работы rvm | |
require 'rvm' | |
require 'rvm/capistrano' | |
require 'bundler/capistrano' | |
require 'puma/capistrano' | |
set :application, "myapp" | |
set :rails_env, "production" | |
ssh_options[:port] = 777 | |
set :port, 777 | |
set :domain, "[email protected]" | |
set :deploy_to, "/home/username/projects/#{application}" | |
set :use_sudo, false | |
set :rvm_type, :user | |
set :scm, :git | |
set :repository, "ssh://[email protected]:777/home/git/myapp.git" | |
set :branch, "master" | |
set :deploy_via, :remote_cache | |
role :web, domain | |
role :app, domain | |
role :db, domain, :primary => true | |
before 'deploy:assets:precompile', :roles => :app do | |
run "rm -f #{current_release}/config/database.yml" | |
run "rm -f #{current_release}/log" | |
run "ln -s #{current_release}/../../shared/log #{current_release}" | |
run "rm -f #{current_release}/config/database.yml" | |
run "ln -s #{current_release}/../../shared/config/database.yml #{current_release}/config/database.yml" | |
run "rm -f #{current_release}/config/environments/production.rb" | |
run "ln -s #{current_release}/../../shared/config/environments/production.rb #{current_release}/config/environments/production.rb" | |
end | |
before 'deploy:restart', 'deploy:migrate' | |
namespace :deploy do | |
task :create_db do | |
run "cd #{deploy_to}/current; bundle exec rake db:create RAILS_ENV=#{rails_env}" | |
end | |
task :symlink_config, roles: :app do | |
run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml" | |
end | |
task :assets_precompile do | |
run "cd #{current_release} && RAILS_ENV=production bundle exec rake assets:precompile" | |
run "mv #{current_release}/public/assets/glyphicons-halflings-regular-*.svg #{current_release}/public/assets/glyphicons-halflings-regular.svg" | |
run "mv #{current_release}/public/assets/glyphicons-halflings-regular-*.eot #{current_release}/public/assets/glyphicons-halflings-regular.eot" | |
run "mv #{current_release}/public/assets/glyphicons-halflings-regular-*.ttf #{current_release}/public/assets/glyphicons-halflings-regular.ttf" | |
run "mv #{current_release}/public/assets/glyphicons-halflings-regular-*.woff #{current_release}/public/assets/glyphicons-halflings-regular.woff" | |
end | |
after "deploy:finalize_update", "deploy:symlink_config" #, "deploy:assets_precompile" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env puma | |
threads 0, 32 | |
daemonize true | |
application_path = "/home/username/projects/myapp" | |
environment railsenv = File.open("#{application_path}/env", "rb").read | |
pidfile "#{application_path}/shared/sockets/puma.pid" | |
state_path "#{application_path}/shared/sockets/puma.state" | |
stdout_redirect "#{application_path}/shared/log/puma.stdout.log", "#{application_path}/shared/log/puma.stderr.log" | |
#bind "unix://#{application_path}/shared/sockets/puma.sock" | |
#preload_app! | |
#activate_control_app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load 'deploy' | |
# Uncomment if you are using Rails' asset pipeline | |
# load 'deploy/assets' | |
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } | |
load 'config/deploy' # remove this line to skip loading any of the default tasks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'inherited_resources' | |
gem 'rails', '4.0.3' | |
gem 'mysql2' | |
gem 'rvm' | |
gem 'capistrano' | |
gem 'rvm-capistrano' | |
gem 'capistrano-ext' | |
gem 'puma' | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream myapp { | |
server unix:///home/username/projects/myapp/shared/sockets/puma.sock; | |
} | |
server { | |
listen 2299; | |
server_name localhost; | |
try_files $uri/index.html $uri.html $uri @myapp; | |
location / { | |
proxy_pass http://myapp; # match the name of upstream directive which is defined above | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
location /streams { | |
proxy_pass http://myapp; | |
proxy_set_header Connection ''; | |
proxy_http_version 1.1; | |
chunked_transfer_encoding off; | |
proxy_buffering off; | |
proxy_cache off; | |
} | |
location ~* ^/assets/ { | |
root /home/username/projects/myapp/current/public; # I assume your app is located at that location | |
# Per RFC2616 - 1 year maximum expiry | |
expires 1y; | |
add_header Cache-Control public; | |
# Some browsers still send conditional-GET requests if there's a | |
# Last-Modified header or an ETag header even if they haven't | |
# reached the expiry date sent in the Expires header. | |
add_header Last-Modified ""; | |
add_header ETag ""; | |
break; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
development |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#this file for local run on development machine. | |
#remote server will start with 'cap deploy', 'cap puma:start', 'cap puma:stop' and so on | |
rm -f /home/username/projects/myapp/shared/sockets/*.* | |
puma --debug -b "unix:///home/username/projects/myapp/shared/sockets/puma.sock" --control "unix:///home/username/projects/myapp/shared/sockets/pumactl.sock" --control-token thisisatoken |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file env: contain only word of rails environment ('development' || 'production') and stored in root of app | |
folder shared: contain folders | |
log: rails and puma log files | |
sockets: puma socket files | |
after create this folder make the soft link for log folder to root of app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment