-
-
Save mcavallo/b0a1eb650e31cd355dc3 to your computer and use it in GitHub Desktop.
Revisions
-
mcavallo revised this gist
Jun 5, 2015 . 1 changed file with 30 additions and 27 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,26 +1,27 @@ # WIP!! --- # Ubuntu 14.04 x64 (DigitalOcean) + Rails 4 + RVM + Nginx + Unicorn + MySQL + Capistrano 3 #### [Create a Droplet](https://www.digitalocean.com/community/tutorials/how-to-create-your-first-digitalocean-droplet-virtual-server) #### SSH into Root $ ssh [email protected] #### Change Root Password $ passwd #### Add Deploy User $ adduser deployer #### Update Sudo Privileges $ visudo username ALL=(ALL:ALL) ALL #### Configure SSH $ vi /etc/ssh/sshd_config Port 22 # Change (1025..65536) @@ -29,20 +30,20 @@ Configure SSH UseDNS no # Add AllowUsers deployer # Add #### Reload SSH $ reload ssh #### SSH with Deploy User (Don't close root) $ ssh -p 1026 [email protected] #### Install Curl $ sudo apt-get update $ sudo apt-get install curl #### Install RVM $ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 $ curl -L get.rvm.io | bash -s stable @@ -53,9 +54,10 @@ Install RVM $ rvm use 2.2.0 --default $ rvm rubygems current ### Install MySQL $ sudo apt-get install mysql-server mysql-client libmysqlclient-dev $ gem install pg -- --with-pg-config=/usr/bin/pg_config Create Postgres User @@ -65,15 +67,15 @@ Create Postgres User alter role deployer superuser createrole createdb replication; create database MYAPP_production owner deployer; #### Install Git $ sudo apt-get install git-core #### Install Bundler $ gem install bundler #### Setup Nginx $ sudo apt-get install nginx $ nginx -h @@ -114,12 +116,12 @@ Setup Nginx keepalive_timeout 10; } #### Add Unicorn $ vim Gemfile gem 'unicorn' #### Update Unicorn Config $ vim config/unicorn/production.rb @@ -162,7 +164,7 @@ Update Unicorn Config ENV['BUNDLE_GEMFILE'] = File.join(root, 'Gemfile') end #### Add Capistrano $ vim Gemfile @@ -172,11 +174,11 @@ Add Capistrano gem 'capistrano3-unicorn' end #### Install Capistrano $ bundle exec cap install #### Update Capistrano Capfile $ vim Capfile @@ -191,7 +193,7 @@ Update Capistrano Capfile # Load custom tasks from `lib/capistrano/tasks' if you have any defined Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } #### Update Capistrano Deploy Config $ vim config/deploy.rb @@ -215,7 +217,7 @@ Update Capistrano Deploy Config end end #### Update Production Deploy Config $ vim config/deploy/production.rb @@ -241,22 +243,23 @@ Update Production Deploy Config set :rails_env, :production set :conditionally_migrate, true #### Add SSH Key to DigitalOcean $ cat ~/.ssh/id_rsa.pub | ssh -p 22 [email protected] 'cat >> ~/.ssh/authorized_keys' #### Say Hi to Github # follow the steps in this guide if receive permission denied(public key) # https://help.github.com/articles/error-permission-denied-publickey $ ssh [email protected] #### Check Deployment (Commit and Push) $ cap production deploy:check #### Deploy $ cap production deploy Thanks to [James Dullaghan](https://gist.github.com/JamesDullaghan/5941259) for his help. -
mcavallo revised this gist
Jun 5, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -47,6 +47,7 @@ Install RVM $ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 $ curl -L get.rvm.io | bash -s stable $ source ~/.rvm/scripts/rvm $ echo "gem: --no-document" >> ~/.gemrc $ rvm requirements $ rvm install 2.2.0 $ rvm use 2.2.0 --default -
mcavallo revised this gist
Jun 5, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -44,6 +44,7 @@ Install Curl Install RVM $ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 $ curl -L get.rvm.io | bash -s stable $ source ~/.rvm/scripts/rvm $ rvm requirements -
mcavallo revised this gist
Jun 5, 2015 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ # WIP!! ### DigitalOcean Ubuntu 14.04 x64 + Rails 4 + RVM + Nginx + Unicorn + MySQL + Capistrano 3 #### [Create a Droplet](https://www.digitalocean.com/community/tutorials/how-to-create-your-first-digitalocean-droplet-virtual-server) -
mcavallo renamed this gist
Jun 5, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ ### DigitalOcean Ubuntu 14.04 x64 + Rails 4 + RVM + Nginx + Unicorn + PostgreSQL + Capistrano 3 #### [Create a Droplet](https://www.digitalocean.com/community/tutorials/how-to-create-your-first-digitalocean-droplet-virtual-server) -
ChuckJHardy revised this gist
Dec 30, 2014 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ ### DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3 #### [Create a Droplet](https://www.digitalocean.com/community/tutorials/how-to-create-your-first-digitalocean-droplet-virtual-server) SSH into Root $ ssh [email protected] -
ChuckJHardy revised this gist
Dec 30, 2014 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -165,7 +165,6 @@ Add Capistrano gem 'capistrano-rails' gem 'capistrano-rvm' gem 'capistrano3-unicorn' end Install Capistrano -
ChuckJHardy revised this gist
Dec 27, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ ### DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3 SSH into Root @@ -68,7 +68,7 @@ Install Bundler $ gem install bundler Setup Nginx $ sudo apt-get install nginx $ nginx -h -
ChuckJHardy revised this gist
Dec 27, 2014 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -239,20 +239,20 @@ Update Production Deploy Config Add SSH Key to DigitalOcean $ cat ~/.ssh/id_rsa.pub | ssh -p 22 [email protected] 'cat >> ~/.ssh/authorized_keys' Say Hi to Github # follow the steps in this guide if receive permission denied(public key) # https://help.github.com/articles/error-permission-denied-publickey $ ssh [email protected] Check Deployment (Commit and Push) $ cap production deploy:check Deploy $ cap production deploy Thanks to [James Dullaghan](https://gist.github.com/JamesDullaghan/5941259) for his help. -
ChuckJHardy revised this gist
Dec 27, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -159,6 +159,8 @@ Update Unicorn Config Add Capistrano $ vim Gemfile group :development do gem 'capistrano-rails' gem 'capistrano-rvm' @@ -168,7 +170,7 @@ Add Capistrano Install Capistrano $ bundle exec cap install Update Capistrano Capfile -
ChuckJHardy created this gist
Dec 27, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,256 @@ ### DigitalOcean Ubuntu 14.04 x64 + Rails 4 + NGINX + Unicorn + PostgreSQL + Capistrano 3 SSH into Root $ ssh [email protected] Change Root Password $ passwd Add Deploy User $ adduser deployer Update Sudo Privileges $ visudo username ALL=(ALL:ALL) ALL Configure SSH $ vi /etc/ssh/sshd_config Port 22 # Change (1025..65536) Protocol 2 # Change PermitRootLogin no # Change UseDNS no # Add AllowUsers deployer # Add Reload SSH $ reload ssh SSH with Deploy User (Don't close root) $ ssh -p 1026 [email protected] Install Curl $ sudo apt-get update $ sudo apt-get install curl Install RVM $ curl -L get.rvm.io | bash -s stable $ source ~/.rvm/scripts/rvm $ rvm requirements $ rvm install 2.2.0 $ rvm use 2.2.0 --default $ rvm rubygems current Install PostgreSQL $ sudo apt-get install postgresql postgresql-server-dev-9.3 $ gem install pg -- --with-pg-config=/usr/bin/pg_config Create Postgres User $ sudo -u postgres psql create user deployer with password 'password'; alter role deployer superuser createrole createdb replication; create database MYAPP_production owner deployer; Install GIT $ sudo apt-get install git-core Install Bundler $ gem install bundler Setup NGINX $ sudo apt-get install nginx $ nginx -h $ cat /etc/init.d/nginx $ /etc/init.d/nginx -h $ sudo service nginx start $ sudo vim /etc/nginx/sites-enabled/default upstream unicorn { server unix:/tmp/unicorn.MYAPP.sock fail_timeout=0; } server { listen 80 default deferred; # server_name example.com; root /home/deployer/apps/MYAPP/current/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } location ~ ^/(robots.txt|sitemap.xml.gz)/ { root /home/deployer/apps/MYAPP/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://unicorn; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; } Add Unicorn $ vim Gemfile gem 'unicorn' Update Unicorn Config $ vim config/unicorn/production.rb root = "/home/deployer/apps/MYAPP/current" working_directory root pid "#{root}/tmp/pids/unicorn.pid" stderr_path "#{root}/log/unicorn.log" stdout_path "#{root}/log/unicorn.log" worker_processes Integer(ENV['WEB_CONCURRENCY']) timeout 30 preload_app true listen '/tmp/unicorn.spui.sock', backlog: 64 before_fork do |server, worker| Signal.trap 'TERM' do puts 'Unicorn master intercepting TERM and sending myself QUIT instead' Process.kill 'QUIT', Process.pid end defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! end after_fork do |server, worker| Signal.trap 'TERM' do puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT' end defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end # Force the bundler gemfile environment variable to # reference the capistrano "current" symlink before_exec do |_| ENV['BUNDLE_GEMFILE'] = File.join(root, 'Gemfile') end Add Capistrano group :development do gem 'capistrano-rails' gem 'capistrano-rvm' gem 'capistrano3-unicorn' gem 'capistrano-sidekiq' end Install Capistrano bundle exec cap install Update Capistrano Capfile $ vim Capfile require 'capistrano/setup' require 'capistrano/deploy' require 'capistrano/rvm' require 'capistrano/bundler' require 'capistrano/rails/assets' require 'capistrano/rails/migrations' require 'capistrano3/unicorn' # Load custom tasks from `lib/capistrano/tasks' if you have any defined Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } Update Capistrano Deploy Config $ vim config/deploy.rb lock '3.3.5' set :application, 'spui' set :repo_url, '[email protected]:MYGITHUB/MYAPP.git' ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call set :use_sudo, false set :bundle_binstubs, nil set :linked_files, fetch(:linked_files, []).push('config/database.yml') set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system') after 'deploy:publishing', 'deploy:restart' namespace :deploy do task :restart do invoke 'unicorn:reload' end end Update Production Deploy Config $ vim config/deploy/production.rb set :port, 22 set :user, 'deployer' set :deploy_via, :remote_cache set :use_sudo, false server '123.333.333.333', roles: [:web, :app, :db], port: fetch(:port), user: fetch(:user), primary: true set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}" set :ssh_options, { forward_agent: true, auth_methods: %w(publickey), user: 'deployer', } set :rails_env, :production set :conditionally_migrate, true Add SSH Key to DigitalOcean cat ~/.ssh/id_rsa.pub | ssh -p 22 [email protected] 'cat >> ~/.ssh/authorized_keys' Say Hi to Github # follow the steps in this guide if receive permission denied(public key) # https://help.github.com/articles/error-permission-denied-publickey ssh [email protected] Check Deployment (Commit and Push) cap production deploy:check Deploy cap production deploy Thanks to [James Dullaghan](https://gist.github.com/JamesDullaghan/5941259) for his help.