diff --git a/Capfile b/Capfile new file mode 100644 index 0000000..11af883 --- /dev/null +++ b/Capfile @@ -0,0 +1,3 @@ +load 'deploy' +load 'deploy/assets' +load 'config/deploy' \ No newline at end of file diff --git a/Gemfile b/Gemfile index 6cdc475..e5364dd 100644 --- a/Gemfile +++ b/Gemfile @@ -36,7 +36,8 @@ end gem 'unicorn' # Deploy with Capistrano -# gem 'capistrano' +gem 'capistrano' +gem 'rvm-capistrano' # To use debugger # gem 'debugger' diff --git a/Gemfile.lock b/Gemfile.lock index 75ae489..b315e84 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/config/deploy.rb b/config/deploy.rb new file mode 100644 index 0000000..c164e0b --- /dev/null +++ b/config/deploy.rb @@ -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 \ No newline at end of file diff --git a/config/nginx.conf b/config/nginx.conf new file mode 100644 index 0000000..59527a2 --- /dev/null +++ b/config/nginx.conf @@ -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; + } +} diff --git a/config/unicorn.rb b/config/unicorn.rb index 5c8a7ab..9d4e632 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -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" diff --git a/config/unicorn_init.sh b/config/unicorn_init.sh old mode 100644 new mode 100755 index 1eaeb86..8fe49b4 --- a/config/unicorn_init.sh +++ b/config/unicorn_init.sh @@ -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" diff --git a/pp.svg b/pp.svg deleted file mode 100644 index f75eb60..0000000 --- a/pp.svg +++ /dev/null @@ -1 +0,0 @@ -