From 769756176a6a03d257af5e99cbc8d8b3d0bfcf08 Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 7 Feb 2013 14:59:46 +0100 Subject: [PATCH] deploy --- Capfile | 4 ++ config/deploy.rb | 109 ++++++++++++++++++++++++++++++++++++++++++++++ config/nginx.conf | 21 +++++++++ config/unicorn.rb | 10 +++++ 4 files changed, 144 insertions(+) create mode 100644 Capfile create mode 100644 config/deploy.rb create mode 100644 config/nginx.conf create mode 100644 config/unicorn.rb diff --git a/Capfile b/Capfile new file mode 100644 index 0000000..d04de11 --- /dev/null +++ b/Capfile @@ -0,0 +1,4 @@ +load 'deploy' if respond_to?(:namespace) # cap2 differentiator +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 \ No newline at end of file diff --git a/config/deploy.rb b/config/deploy.rb new file mode 100644 index 0000000..3a900df --- /dev/null +++ b/config/deploy.rb @@ -0,0 +1,109 @@ +set :application, 'site_perso_app' + set :domain, 'new.nicolasbally.com' + + + + + + + require "rvm/capistrano" + + set :rvm_ruby_string, 'ruby-1.9.3-p0' + set :rvm_type, :user + + set :user, 'web' + + + + set :deploy_to, "/home/#{user}/#{application}/" + set :deploy_via, :remote_cache + + set :normalize_asset_timestamps, false + + + set :rails_env, "production" + + + + role :app, domain + role :web, domain + role :db, domain, :primary => true + + set :scm, :git + set :repository, "git@gitlab.bally.me:root/site-perso.git" + set :branch, "master" + + default_run_options[:pty] = true + + + + before "deploy:symlink", "deploy:bundle_gems" + after "deploy:bundle_gems", "deploy:make_simlinks" + after "deploy:make_simlinks", "assets:precompile" + + + + # after "deploy", "deploy:restart" + after "deploy:restart", "deploy:cleanup" + + + #after "deploy", "deploy:bundle_gems" + #after "deploy:bundle_gems", "deploy:make_simlinks" + #after "deploy:make_simlinks", "assets:precompile" + #after "assets:precompile", "deploy:restart" + #after "deploy:restart", "deploy:cleanup" + + + namespace :assets do + task :precompile, :roles => :web do + run "rm -rf #{release_path}/public/assets" + run "ln -s #{deploy_to}shared/assets #{release_path}/public/assets" + + + run "cd #{release_path} && bundle exec rake assets:precompile --trace" + end + + task :cleanup, :roles => :web do + run "cd #{current_path} && RAILS_ENV=production bundle exec rake assets:clean" + end + end + + + + + + namespace :deploy do + task :bundle_gems do + run "cd #{release_path} && bundle install" + end + + task :make_simlinks do + run "rm -rf #{release_path}/private_medias" + run "ln -s #{deploy_to}shared/storage/private #{release_path}/private_medias" + run "rm -rf #{release_path}/public/public_medias" + run "ln -s #{deploy_to}shared/storage/public #{release_path}/public/public_medias" + + run "rm -rf #{release_path}/db/production.sqlite3" + run "ln -s #{deploy_to}shared/production.sqlite3 #{release_path}/db/production.sqlite3" + end + + task :start do + sudo "service #{application} start" + end + task :stop do + run "service #{application} stop" + end + task :restart, :roles => :app, :except => { :no_release => true } do + sudo "service #{application} restart" + end + task :migrate do + run "cd #{deploy_to}current && rake db:migrate RAILS_ENV=#{rails_env}" + + end + + task :seeds do + run "cd #{deploy_to}current && rake db:seeds RAILS_ENV=#{rails_env}" + + end + end + \ No newline at end of file diff --git a/config/nginx.conf b/config/nginx.conf new file mode 100644 index 0000000..84dc4c7 --- /dev/null +++ b/config/nginx.conf @@ -0,0 +1,21 @@ +upstream site_perso_app_unicorn { + server unix:/home/web/site_perso_app/shared/tmp/unicorn.sock fail_timeout=0; +} + +server { + listen 80; + server_name new.nicolasbally.com; + root /home/web/site_perso_app/current/public; + try_files $uri/index.html $uri @unicorn; + + location @unicorn { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://site_perso_app_unicorn; + } + + error_page 500 502 503 504 /500.html; + client_max_body_size 4G; + keepalive_timeout 10; +} \ No newline at end of file diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 0000000..c654685 --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,10 @@ +@rails_app = "site_perso_app" + +working_directory "/home/web/#{@rails_app}/current" +pid "/home/web/#{@rails_app}/shared/unicorn.pid" +stderr_path "/home/web/#{@rails_app}/shared/log/unicorn.log" +stdout_path "/home/web/#{@rails_app}/shared/log/unicorn.log" + +listen "/home/web/#{@rails_app}/shared/tmp/unicorn.sock" +worker_processes 2 +timeout 30 \ No newline at end of file