added capistrano; more production changes

This commit is contained in:
jomo
2014-06-24 23:04:24 +02:00
parent 1eecb530c3
commit a2ff7068c0
8 changed files with 177 additions and 4 deletions

3
Capfile Normal file
View File

@@ -0,0 +1,3 @@
load 'deploy'
load 'deploy/assets'
load 'config/deploy'

View File

@@ -36,7 +36,8 @@ end
gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
gem 'capistrano'
gem 'rvm-capistrano'
# To use debugger
# gem 'debugger'

View File

@@ -41,6 +41,12 @@ GEM
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
capistrano (2.15.5)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
choice (0.1.6)
coderay (1.1.0)
coffee-rails (4.0.1)
@@ -55,6 +61,7 @@ GEM
execjs (2.0.2)
highlight_js-rails (7.1.0)
rails (>= 3.1.1)
highline (1.6.21)
hike (1.2.3)
hirb (0.7.1)
i18n (0.6.9)
@@ -72,6 +79,13 @@ GEM
minitest (5.3.2)
multi_json (1.9.2)
mysql2 (0.3.15)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-sftp (2.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.9.1)
net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
polyglot (0.3.4)
@@ -106,6 +120,8 @@ GEM
rest-client (1.6.7)
mime-types (>= 1.16)
ruby-graphviz (1.0.9)
rvm-capistrano (1.5.2)
capistrano (~> 2.15.4)
sanitize (2.1.0)
nokogiri (>= 1.4.4)
sass (3.2.19)
@@ -151,6 +167,7 @@ DEPENDENCIES
bcrypt-ruby
better_errors
binding_of_caller
capistrano
coffee-rails
highlight_js-rails
hirb
@@ -161,6 +178,7 @@ DEPENDENCIES
rb-readline
redcarpet
rest-client
rvm-capistrano
sanitize
sass-rails
therubyracer

53
config/deploy.rb Normal file
View File

@@ -0,0 +1,53 @@
require "bundler/capistrano"
require "rvm/capistrano"
server "redstoner", :web, :app, :db, primary: true
set :application, "redstoner"
set :user, "www-data"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "git@bitbucket.org/redstonesheep/redstoner.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{application} #{command}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "deploy:symlink_config"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
end

99
config/nginx.conf Normal file
View File

@@ -0,0 +1,99 @@
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# (nginx-naxsi config)
# Uncomment it if you installed nginx-naxsi
#include /etc/nginx/naxsi_core.rules;
##
# (nginx-passenger config)
# Uncomment it if you installed nginx-passenger
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
upstream unicorn {
server unix:/tmp/unicorn.redstoner.sock fail_timeout=0;
}
server {
listen 5500 deferred;
server_name redstoner.com *.redstoner.com;
root /home/www-data/apps/redstoner/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
# send requests to rails if file not found
try_files $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://unicorn;
}
error_page 400 /404.html;
error_page 422 /422.html;
error_page 500 502 503 504 /500.html;
client_max_body_size 20M;
keepalive_timeout 10;
}
}

View File

@@ -1,4 +1,4 @@
root = "/var/rails_site/"
root = "/home/www-data/apps/redstoner"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"

2
config/unicorn_init.sh Normal file → Executable file
View File

@@ -12,7 +12,7 @@ set -e
# Feel free to change any of the following variables for your app:
TIMEOUT="${TIMEOUT-60}"
APP_ROOT="/var/rails_site/"
APP_ROOT="/home/www-data/apps/redstoner"
PID="$APP_ROOT/tmp/pids/unicorn.pid"
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
AS_USER="www-data"

1
pp.svg
View File

@@ -1 +0,0 @@
<svg viewBox="0 0 16 17" version="1.1" xmlns="http://www.w3.org/2000/svg" class="PPTM"><path d="m15.603 3.917c-0.264-0.505-0.651-0.917-1.155-1.231-0.025-0.016-0.055-0.029-0.081-0.044 0.004 0.007 0.009 0.014 0.013 0.021 0.265 0.506 0.396 1.135 0.396 1.891 0 1.715-0.712 3.097-2.138 4.148-1.425 1.052-3.418 1.574-5.979 1.574h-0.597c-0.45 0-0.9 0.359-1.001 0.798l-0.719 3.106c-0.101 0.438-0.552 0.797-1.002 0.797h-1.404l-0.105 0.457c-0.101 0.438 0.184 0.798 0.633 0.798h2.1c0.45 0 0.9-0.359 1.001-0.798l0.718-3.106c0.101-0.438 0.551-0.797 1.002-0.797h0.597c2.562 0 4.554-0.522 5.979-1.574 1.426-1.052 2.139-2.434 2.139-4.149 0-0.755-0.132-1.385-0.397-1.891z" fill="#0079c1" class="PPTM-btm"/><path d="m9.27 6.283c-0.63 0.46-1.511 0.691-2.641 0.691h-0.521c-0.45 0-0.736-0.359-0.635-0.797l0.628-2.72c0.101-0.438 0.552-0.797 1.002-0.797h0.686c0.802 0 1.408 0.136 1.814 0.409 0.409 0.268 0.611 0.683 0.611 1.244 0 0.852-0.315 1.507-0.944 1.97zm3.369-5.42c-0.913-0.566-2.16-0.863-4.288-0.863h-4.372c-0.449 0-0.9 0.359-1.001 0.797l-2.957 12.813c-0.101 0.439 0.185 0.798 0.634 0.798h2.099c0.45 0 0.901-0.358 1.003-0.797l0.717-3.105c0.101-0.438 0.552-0.797 1.001-0.797h0.598c2.562 0 4.554-0.524 5.979-1.575 1.427-1.051 2.139-2.433 2.139-4.148-0.001-1.365-0.439-2.425-1.552-3.123z" fill="#00457c" class="PPTM-top"/></svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB