- Bootstrap with the attached ubuntu-bootstrap.sh
- For nginx configuration, see attached conf.d.tgz
- Generate SSL Certificates for app server and assets server
- Configure nginx to accept SSL, see reference 1 and 2
- Redirect non-ssl to ssl site.
- Enable http://127.0.0.1/nginx_status page for Linode Longview
- Install Linode Longview
- Change mongodb to have bind_ip=local/internal IP
- Create a deploy user, disallow any admin/sudo privileges, allow ssh access
- Create /home/deploy/.ssh directory with 0700 access
- Add necessary public keys for deploy users
- Create /var/www/ owned by the deploy user
- Configure logrotate with the attached config files
- Use Puma Jungle (https://github.com/puma/puma/tree/master/tools/jungle/upstart) to make puma an upstart job.
- Change /etc/init/puma.conf to point to the configuration file at ../shared/puma.rb
Deployment Steps
- Add to Gemfile in group development
- gem 'capistrano'
- gem 'capistrano3-puma'
- gem 'capistrano-bundler'
- gem 'capistrano-rails'
- bundle install
- cap install
- git rm --cached config/mongoid.yml
- echo "config/mongoid.yml" >> .gitignore
- commit your change.
- Add a script to generate the mongoid.yml in production
- In config/deploy.rb, properly configure the application details
- Make sure log, tmp/pids, tmp/sockets are included in linked_dirs
- Make sure to restart puma in the restart task. This is probably better controlled by bluepill, monit, god, or nagios.
- Optionally run tmp:cache:clear task and mongoid:index in after_restart
after :restart, :clear_cache do
on roles(:app), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
within release_path do
execute :rake, 'tmp:cache:clear'
end
end
invoke 'mongoid:index'
end
- in config/deploy/#{environment}.rb, properly set roles and hosts
- in config/environments/#{environment}.rb, properly add asset pre-compile list
- Test by running RAILS_ENV=#{environment} rake asset:precompile, make sure that all assets are compiled to Rails.root/public/assets
- Create a cap task in lib/capistrano/tasks to create mongodb index
# mongoid.cap
namespace :mongoid do
desc "Create mongodb index"
task :index do
on roles(:mongoid) do |host|
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "db:mongoid:create_indexes"
end
end
end
end
end
- enable packages in Capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/puma'
- test by running cap #{environment} deploy
- Whack the moles that show up.
Next Step
- Start automating server provisioning
- Secure the deployment process