Commit b03a0e45b13fb95bb79587c4b97a7843aefb3001

Authored by Stephen Crosby
1 parent 0d02c7cc
Exists in master and in 1 other branch production

update deployment docs with env-config instructions

config/deploy.example.rb
@@ -2,9 +2,9 @@ @@ -2,9 +2,9 @@
2 # ============= 2 # =============
3 # 3 #
4 # Copy this file to config/deploy.rb and customize it as needed. 4 # Copy this file to config/deploy.rb and customize it as needed.
5 -# Then run `cap deploy:setup` to set up your server and finally 5 +# Then run `cap errbit:setup` to set up your server and finally
6 # `cap deploy` whenever you would like to deploy Errbit. Refer 6 # `cap deploy` whenever you would like to deploy Errbit. Refer
7 -# to the Readme for more information. 7 +# to ./docs/deployment/capistrano.md for more info
8 8
9 # config valid only for current version of Capistrano 9 # config valid only for current version of Capistrano
10 lock '3.3.5' 10 lock '3.3.5'
@@ -20,9 +20,8 @@ set :ssh_options, forward_agent: true @@ -20,9 +20,8 @@ set :ssh_options, forward_agent: true
20 20
21 set :linked_files, fetch(:linked_files, []) + %w( 21 set :linked_files, fetch(:linked_files, []) + %w(
22 .env 22 .env
23 - config/config.yml  
24 - config/mongoid.yml  
25 config/newrelic.yml 23 config/newrelic.yml
  24 + config/unicorn.rb
26 ) 25 )
27 26
28 set :linked_dirs, fetch(:linked_dirs, []) + %w( 27 set :linked_dirs, fetch(:linked_dirs, []) + %w(
@@ -38,36 +37,51 @@ set :linked_dirs, fetch(:linked_dirs, []) + %w( @@ -38,36 +37,51 @@ set :linked_dirs, fetch(:linked_dirs, []) + %w(
38 # set :rbenv_roles, :all 37 # set :rbenv_roles, :all
39 38
40 namespace :errbit do 39 namespace :errbit do
41 - task :setup_configs do 40 + desc "Setup config files (first time setup)"
  41 + task :setup do
42 on roles(:app) do 42 on roles(:app) do
43 execute "mkdir -p #{shared_path}/config" 43 execute "mkdir -p #{shared_path}/config"
  44 + execute "mkdir -p #{shared_path}/pids"
  45 + execute "touch #{shared_path}/.env"
  46 +
44 { 47 {
45 - 'config/config.example.yml' => 'config/config.yml',  
46 - 'config/mongoid.example.yml' => 'config/mongoid.yml',  
47 - 'config/newrelic.example.yml' => 'config/newrelic.yml' 48 + 'config/newrelic.example.yml' => 'config/newrelic.yml',
  49 + 'config/unicorn.default.rb' => 'config/unicorn.rb',
48 }.each do |src, target| 50 }.each do |src, target|
49 - execute "if [ ! -f #{shared_path}/#{target} ]; then cp #{current_path}/#{src} #{shared_path}/#{target}; fi" 51 + unless test("[ -f #{shared_path}/#{target} ]")
  52 + upload! src, "#{shared_path}/#{target}"
  53 + end
50 end 54 end
51 end 55 end
52 end 56 end
53 end 57 end
54 58
55 namespace :db do 59 namespace :db do
56 - desc "Create the indexes defined on your mongoid models"  
57 - task :create_mongoid_indexes do 60 + desc "Create and setup the mongo db"
  61 + task :setup do
58 on roles(:db) do 62 on roles(:db) do
59 within current_path do 63 within current_path do
60 with rails_env: fetch(:rails_env) do 64 with rails_env: fetch(:rails_env) do
61 - execute :rake, 'db:mongoid:create_indexes' 65 + execute :rake, 'errbit:bootstrap'
62 end 66 end
63 end 67 end
64 end 68 end
65 end 69 end
66 end 70 end
67 71
68 -set :unicorn_pid, "`cat #{"#{fetch(:deploy_to)}/shared/pids"}/unicorn.pid`" 72 +set :unicorn_pidfile, "#{fetch(:deploy_to)}/shared/pids/unicorn.pid"
  73 +set :unicorn_pid, "`cat #{fetch(:unicorn_pidfile)}`"
69 74
70 namespace :unicorn do 75 namespace :unicorn do
  76 + desc 'Start unicorn'
  77 + task :start do
  78 + on roles(:app) do
  79 + within current_path do
  80 + execute "UNICORN_PID=\"#{fetch(:unicorn_pidfile)}\"", "bundle exec unicorn -D -c ./config/unicorn.rb"
  81 + end
  82 + end
  83 + end
  84 +
71 desc 'Reload unicorn' 85 desc 'Reload unicorn'
72 task :reload do 86 task :reload do
73 on roles(:app) do 87 on roles(:app) do
config/unicorn.default.rb
@@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
3 worker_processes 3 # amount of unicorn workers to spin up 3 worker_processes 3 # amount of unicorn workers to spin up
4 timeout 30 # restarts workers that hang for 30 seconds 4 timeout 30 # restarts workers that hang for 30 seconds
5 preload_app true 5 preload_app true
  6 +listen 8080
  7 +pid ENV['UNICORN_PID'] if ENV['UNICORN_PID']
6 8
7 # Taken from github: https://github.com/blog/517-unicorn 9 # Taken from github: https://github.com/blog/517-unicorn
8 # Though everyone uses pretty miuch the same code 10 # Though everyone uses pretty miuch the same code
@@ -17,7 +19,7 @@ before_fork do |server, worker| @@ -17,7 +19,7 @@ before_fork do |server, worker|
17 # we send it a QUIT. 19 # we send it a QUIT.
18 # 20 #
19 # Using this method we get 0 downtime deploys. 21 # Using this method we get 0 downtime deploys.
20 - 22 +
21 old_pid = "#{server.config[:pid]}.oldbin" 23 old_pid = "#{server.config[:pid]}.oldbin"
22 if File.exists?(old_pid) && server.pid != old_pid 24 if File.exists?(old_pid) && server.pid != old_pid
23 begin 25 begin
@@ -27,3 +29,4 @@ before_fork do |server, worker| @@ -27,3 +29,4 @@ before_fork do |server, worker|
27 end 29 end
28 end 30 end
29 end 31 end
  32 +
docs/deployment/capistrano.md
1 # Deploy with Capistrano 1 # Deploy with Capistrano
2 These instructions should be good enough to get you started deploying 2 These instructions should be good enough to get you started deploying
3 -capistrano with Errbit. More than likely, you'll have to adjust some things to  
4 -suit your needs, so you should understand how to use capistrano before you  
5 -continue. 3 +capistrano with Errbit. More than likely, you'll have to adjust some
  4 +things to suit your needs, so you should understand how to use
  5 +capistrano before you continue.
6 6
7 ## Clone and prepare the source code repository 7 ## Clone and prepare the source code repository
8 8
@@ -18,20 +18,48 @@ $EDITOR config/deploy.rb @@ -18,20 +18,48 @@ $EDITOR config/deploy.rb
18 cp config/deploy/production.example.rb config/deploy/production.rb 18 cp config/deploy/production.example.rb config/deploy/production.rb
19 $EDITOR config/deploy/production.rb 19 $EDITOR config/deploy/production.rb
20 20
21 -# Create required directories.  
22 -# It will print out what files are missing.  
23 -# Create them manually or use errbit:setup_configs task after first deploy 21 +# Check to make sure configs exist
24 bundle exec cap production deploy:check 22 bundle exec cap production deploy:check
  23 +
  24 +# Create the configs yourself, or run errbit:setup_configs to upload the
  25 +# defaults
  26 +bundle exec cap production errbit:setup_configs
  27 +
  28 +# Deploy
  29 +bundle exec cap production deploy
  30 +
  31 +# Setup the remote DB if you haven't already
  32 +bundle exec cap production db:setup
25 ``` 33 ```
26 34
  35 +## Static Assets
  36 +For a deployment of any real size, you'll probably want to set up a web
  37 +server for efficiently serving static assets. If you choose to go this
  38 +route, just map all requests for /assets/.\* to
  39 +/deploy/path/shared/public/assets
  40 +
  41 +## Starting Errbit
  42 +Errbit comes with some capistrano tasks to manage running Errbit under
  43 +unicorn.
  44 +To start Errbit, you can run:
  45 +```bash
  46 +bundle exec cap production unicorn:start
  47 +```
  48 +
  49 +Supervising and monitoring Errbit is beyond the scope of this
  50 +documentation.
  51 +
  52 +
27 ### rbenv support 53 ### rbenv support
28 54
29 -Pass `rbenv` environment when running `cap` to use rbenv. 55 +Pass `rbenv` environment when running `cap` to use rbenv. See
  56 +[capistrano/rbenv](https://github.com/capistrano/rbenv) for more
  57 +information.
30 58
31 ```bash 59 ```bash
32 rbenv=1 bundle exec cap production deploy 60 rbenv=1 bundle exec cap production deploy
33 ``` 61 ```
34 62
35 ## Schedule recurring tasks 63 ## Schedule recurring tasks
36 -You may want to periodically clear resolved errors to free up space. Schedule  
37 -the ```rake errbit:db:clear_resolved``` rake task to run every day or so. 64 +You may want to periodically clear resolved errors to free up space.
  65 +Schedule ```rake errbit:db:clear_resolved``` to run every day or so.
docs/deployment/heroku.md
@@ -23,19 +23,17 @@ git commit -m "Update db/seeds.rb with initial login" @@ -23,19 +23,17 @@ git commit -m "Update db/seeds.rb with initial login"
23 heroku apps:create 23 heroku apps:create
24 heroku addons:add mongolab:sandbox 24 heroku addons:add mongolab:sandbox
25 heroku addons:add sendgrid:starter 25 heroku addons:add sendgrid:starter
26 -heroku config:add HEROKU=true  
27 -heroku config:add SECRET_TOKEN="$(bundle exec rake secret)" 26 +heroku config:add GEMFILE_RUBY_VERSION=2.2.0
  27 +heroku config:add SECRET_KEY_BASE="$(bundle exec rake secret)"
28 heroku config:add ERRBIT_HOST=some-hostname.example.com 28 heroku config:add ERRBIT_HOST=some-hostname.example.com
29 heroku config:add ERRBIT_EMAIL_FROM=example@example.com 29 heroku config:add ERRBIT_EMAIL_FROM=example@example.com
30 git push heroku master 30 git push heroku master
31 ``` 31 ```
32 32
33 ## Prepare the DB 33 ## Prepare the DB
34 -No bootstrap task is used on Heroku!  
35 34
36 ```bash 35 ```bash
37 -heroku run rake db:seed  
38 -heroku run rake db:mongoid:create_indexes 36 +heroku run rake errbit:bootstrap
39 ``` 37 ```
40 38
41 ## Schedule recurring tasks 39 ## Schedule recurring tasks