deploy files

This commit is contained in:
Nicolas Bally 2014-08-19 10:02:08 +02:00
parent dc83ace928
commit 93ed42de9c
7 changed files with 268 additions and 2 deletions

4
Capfile Normal file
View File

@ -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

View File

@ -32,10 +32,10 @@ gem 'haml-rails'
# gem 'bcrypt', '~> 3.1.7' # gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server # Use unicorn as the app server
# gem 'unicorn' gem 'unicorn'
# Use Capistrano for deployment # Use Capistrano for deployment
# gem 'capistrano-rails', group: :development gem 'capistrano-rails', group: :development
# Use debugger # Use debugger
# gem 'debugger', group: [:development, :test] # gem 'debugger', group: [:development, :test]

View File

@ -29,6 +29,16 @@ GEM
tzinfo (~> 1.1) tzinfo (~> 1.1)
arel (5.0.1.20140414130214) arel (5.0.1.20140414130214)
builder (3.2.2) builder (3.2.2)
capistrano (3.2.1)
i18n
rake (>= 10.0.0)
sshkit (~> 1.3)
capistrano-bundler (1.1.3)
capistrano (~> 3.1)
sshkit (~> 1.2)
capistrano-rails (1.1.1)
capistrano (~> 3.1)
capistrano-bundler (~> 1.1)
coffee-rails (4.0.1) coffee-rails (4.0.1)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
@ -36,6 +46,7 @@ GEM
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.7.1) coffee-script-source (1.7.1)
colorize (0.7.3)
erubis (2.7.0) erubis (2.7.0)
execjs (2.2.1) execjs (2.2.1)
haml (4.0.5) haml (4.0.5)
@ -54,12 +65,16 @@ GEM
railties (>= 3.0, < 5.0) railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (1.8.1) json (1.8.1)
kgio (2.9.2)
mail (2.5.4) mail (2.5.4)
mime-types (~> 1.16) mime-types (~> 1.16)
treetop (~> 1.4.8) treetop (~> 1.4.8)
mime-types (1.25.1) mime-types (1.25.1)
minitest (5.4.0) minitest (5.4.0)
multi_json (1.10.1) multi_json (1.10.1)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.9.1)
polyglot (0.3.5) polyglot (0.3.5)
rack (1.5.2) rack (1.5.2)
rack-test (0.6.2) rack-test (0.6.2)
@ -79,6 +94,7 @@ GEM
activesupport (= 4.1.4) activesupport (= 4.1.4)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
raindrops (0.13.0)
rake (10.3.2) rake (10.3.2)
rdoc (4.1.1) rdoc (4.1.1)
json (~> 1.4) json (~> 1.4)
@ -102,6 +118,10 @@ GEM
activesupport (>= 3.0) activesupport (>= 3.0)
sprockets (~> 2.8) sprockets (~> 2.8)
sqlite3 (1.3.9) sqlite3 (1.3.9)
sshkit (1.5.1)
colorize
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.4) thread_safe (0.3.4)
tilt (1.4.1) tilt (1.4.1)
@ -115,11 +135,16 @@ GEM
uglifier (2.5.3) uglifier (2.5.3)
execjs (>= 0.3.0) execjs (>= 0.3.0)
json (>= 1.8.0) json (>= 1.8.0)
unicorn (4.8.3)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
PLATFORMS PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
capistrano-rails
coffee-rails (~> 4.0.0) coffee-rails (~> 4.0.0)
haml-rails haml-rails
jbuilder (~> 2.0) jbuilder (~> 2.0)
@ -131,3 +156,4 @@ DEPENDENCIES
sqlite3 sqlite3
turbolinks turbolinks
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
unicorn

138
config/deploy.rb Normal file
View File

@ -0,0 +1,138 @@
set :application, 'ads_app'
set :domain, '62.210.187.249'
set :user, 'web'
set :scm_user, "git"
set :scm_host, "gitlab.bally.me"
set :rvm_ruby_string, 'ruby-2.1.2@ads'
set :rvm_autolibs_flag, "read-only"
set :bundle_cmd, "/home/#{user}/.rvm/gems/#{rvm_ruby_string}@global/bin/bundle"
set :bundle_dir, "/home/#{user}/.rvm/gems/#{rvm_ruby_string}"
set :use_sudo, false
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, "#{scm_user}@#{scm_host}:root/#{application}.git"
set :branch, "master"
default_run_options[:pty] = true
require "rvm/capistrano"
require 'bundler/capistrano'
load 'deploy/assets'
namespace :deploy do
# namespace :assets do
# task :precompile, :roles => :web, :except => { :no_release => true } do
# from = source.next_revision(current_revision)
# if releases.length <= 1 || capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
# run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
# else
# logger.info "Skipping asset pre-compilation because there were no asset changes"
# end
# end
# end
desc "Symlink shared config files"
task :symlink_config_files do
run "ln -s #{deploy_to}shared/storage/private #{current_path}/private_medias"
run "ln -s #{deploy_to}shared/storage/public #{current_path}/public/public_medias"
run "ln -s #{deploy_to}shared/production.sqlite3 #{current_path}/db/production.sqlite3"
sudo "cp #{current_path}/config/unicorn_init_d /etc/init.d/#{application}"
sudo "chmod +x /etc/init.d/#{application}"
sudo "update-rc.d #{application} defaults "
end
task :start do
sudo "service #{application} start"
end
task :stop do
run "service #{application} stop"
end
task :restart do
sudo "service #{application} restart"
end
task :reload_nginx do
sudo "rm -rf /etc/nginx/sites-enabled/#{application}"
sudo "ln -s #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application} "
sudo "service nginx reload"
end
task :seeds do
run "cd #{deploy_to}current && rake db:seed RAILS_ENV=#{rails_env}"
end
task :create_files_folders do
run "mkdir #{deploy_to}shared/storage"
run "mkdir #{deploy_to}shared/storage/private"
run "mkdir #{deploy_to}shared/storage/public"
end
end
#before 'deploy:setup', 'rvm:install_rvm' # install RVM
#before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset, OR:
#before 'deploy:setup', 'rvm:create_gemset' # only create gemset
after "deploy:setup", "deploy:create_files_folders"
#after "deploy:restart", "deploy:cleanup"
before "deploy:restart", "deploy:symlink_config_files"
after "deploy", "deploy:cleanup"

24
config/nginx.conf Normal file
View File

@ -0,0 +1,24 @@
upstream blog_eft_app_unicorn {
server unix:/home/web/ads_app/shared/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name ads.quartz.xyz;
root /home/web/ads_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://ads_app_unicorn;
proxy_read_timeout 6000;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}

10
config/unicorn.rb Normal file
View File

@ -0,0 +1,10 @@
@rails_app = "ads_app"
working_directory "/home/web/#{@rails_app}/current"
pid "/home/web/#{@rails_app}/shared/unicorn.pid"
stderr_path "/home/web/#{@rails_app}/shared/unicorn.log"
stdout_path "/home/web/#{@rails_app}/shared/unicorn.log"
listen "/home/web/#{@rails_app}/shared/unicorn.sock"
worker_processes 2
timeout 600

64
config/unicorn_init_d Normal file
View File

@ -0,0 +1,64 @@
#!/bin/bash
set -u
set -e
# Change these to match your app:
APP_NAME=ads_app
APP_RUBY=2.1.2@ads
APP_ROOT="/home/web/ads_app/current"
PID="/home/web/ads_app/shared/unicorn.pid"
ENV=production
GEM_HOME="/home/web/.rvm/gems/ruby-$APP_RUBY"
UNICORN_OPTS="-D -E $ENV -c $APP_ROOT/config/unicorn.rb"
SET_PATH="cd $APP_ROOT; rvm $APP_RUBY"
CMD="$SET_PATH; unicorn $UNICORN_OPTS"
old_pid="$PID.oldbin"
cd $APP_ROOT || exit 1
sig () {
test -s "$PID" && kill -$1 `cat $PID`
}
oldsig () {
test -s $old_pid && kill -$1 `cat $old_pid`
}
case ${1-help} in
start)
sig 0 && echo >&2 "Already running" && exit 0
su - web -c "$CMD"
;;
stop)
sig QUIT && exit 0
echo >&2 "Not running"
;;
force-stop)
sig TERM && exit 0
echo >&2 "Not running"
;;
restart|reload)
sig HUP && echo reloaded OK && exit 0
echo >&2 "Couldn't reload, starting '$CMD' instead"
su - web -c "$CMD"
;;
upgrade)
sig USR2 && exit 0
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
su - web -c "$CMD"
;;
rotate)
sig USR1 && echo rotated logs OK && exit 0
echo >&2 "Couldn't rotate logs" && exit 1
;;
*)
echo >&2 "Usage: $0 "
exit 1
;;
esac