PrunOps
Covers all Deployment and maintainance Operations in a Ruby on Rails Application server:
- DEPLOYMENT: Capistrano tasks to depoly your rails Apps.
- DIAGNOSIS: Capistrano diagnosis tools to guet your Apps status on real time.
- RELEASE: Rake tasks to manage and tag version number in your Apps (X.Y.Z).
- BACKUP: Backup policy for database and files in your Apps, using git as storage.
Based on:
Installation
Add this line to your application's Gemfile:
gem 'prun-ops'
And then execute:
$ bundle
Or install it yourself as:
$ gem install prun-ops
Usage: Day-to-day rake and capistrano tasks
Configure Capistrano
gem "capistrano-rails"
is included as prun-ops requirement. Create basic files cap install
Capfile should include these requirements:
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require "#{File.dirname(__FILE__)}/config/application"
require 'capistrano/prun-ops'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
Notice that you are adding all prun-ops tasks with the line require 'capistrano/prun-ops'
Your config/deploy/production.rb:
server "example.com", user: 'root', roles: %w{web app db}, port: 2222
Note: Remember change this line in production.rb file: config.assets.compile = true
Deployment
cap [stg] deploy:cold
first time deployment with schema:load and seeds (replacing db:migrate)cap [stg] deploy
deploy your app as usualcap [stg] deploy:restart
restart thin server of this applicationcap [stg] deploy:stop
stop thin servercap [stg] deploy:start
start thin servercap [stg] deploy:db_create
create databasecap [stg] deploy:db_reset
load schema and seeds for first DB setupcap [stg] deploy:db_seed
seeds the databasecap [stg] git:remove_repo
Removes repo (useful when repo_url changes)
Added the possibility of deploying from local repository. Add to deploy.rb
or [stg].rb
files:
before :deploy, "git:deploy_from_local_repo"
Take care to remove the previous repo if you are changing the :repo_url : cap [stg] git:remove_repo
Backup
Backups/restore database and files in your Rails app.
Configure your 'config/applciation.rb':
# Backup directories
config.backup_dirs = %w{public/ckeditor_assets public/system}
# Backup repo
config.backup_repo = "[email protected]:example/backup.git"
And
cap [stg] pull:data
: downloads DDBB and file folders from the stage you need.cap [stg] pull:db
: Hot backup, download and restore of the stage databasecap [stg] pull:files
: Hot restore of backup_filescap [stg] backup[TAG]
: Commit a backup of DDBB and files to the git repo configured. "application-YYYYMMDD" tagged if no tag is provided.cap [stg] backup:restore[TAG]
: Restore the last backup into the stage indicated, or tagged state if TAG is provided.rake backup |TAG|
: Uploads backup to git store from local, tagging with date, or with TAG if provided. Useful to backup production stage.rake backup:restore |TAG|
: Restore last backup copy, or tagged with TAG if provided.
TODO: Release
Release management
rake release |VERSION|
push forward from dev-branch to master-branch and tag the commit with VERSION name.rake release:delete |VERSION|
remove tag with VERSION name.rake git:ff
merge dev branch towards master branch without releasing (Deprecating, new version "rake tomaster[message]")
Diagnosis
Some capistrano commands useful to connect to server and help with the problem solving.
cap [stg] ssh
open a ssh connection with servercap [stg] log_tail[LOG_FILENAME]
tail all rails logs by default, or only one if LOG_FILENAME is providedcap [stg] log_patter[PATTERN]
search a pattern in all logscap [stg] c
open a rails console with servercap [stg] dbconsole
open a rails database console with servercap [stg] x[COMMAND]
execute any command in server provided as COMMAND (i.e.: cap production x['free -m'])cap [stg] rake[TASK]
execute any rake task in server provided as TASK (i.e.: cap production rake[db:version])
Monitoring
Recommend to configure your Rails server with PRUN Chef recipe.
At this moment we are implementing NewRelic monitoring, including as dependency 'newrelic_rpm' gem. To configure yourproject you just need to create an account at NewRelic and follow the instructions (creating a 'config/newrelic.yml file with your license_key).
TODO: Configuration management
configure.yml
: for variables with environment dependency
cap [stg] configure
cap [stg] configure:base
: for packages, git, time ...
cap [stg] configure:ruby
: ruby version
cap [stg] configure:pgsql
cap [stg] configure:nginx
cap [stg] configure:node
cap [stg] configure:newrelic
cap [stg] configure:jenkins
cap [stg] configure:wordpress
Contributing
- Fork it ( https://github.com/[my-github-username]/prun-ops/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
License
MIT License. Made by Lebrijo.com
Release notes
v0.0.2
- First publication
v0.0.4
- Changing homepage and License
- start|stop|restart thin server per application as Capistrano task
v0.0.5
- Removing Application server version (thin 1.6.2) dependency
v0.0.6
- Fixing DigitalOcean images error when slug is nil for client images
- Adding git:ff rake task
v0.0.8
- Adding backup[tag] capistrano task for production
v0.0.9
- Fixing Capistrano pulling tasks "pull:data"
v0.0.10
- Removing bin/ops command in order to create open-dock gem
- Remove prun-ops dependency from 'config/deployment.rb' file and ad it to 'Capfile' as
require 'capistrano/prun-ops'
v0.0.21
- Remove from your 'config/deploy.rb':
# Backup directories
require_relative "./application.rb"
set :backup_dirs, Taskboard::Application.config.backup_dirs
Also add in your Capfile:
................
require 'capistrano/rails/migrations'
require "#{File.dirname(__FILE__)}/config/application"
require 'capistrano/prun-ops'
................
v0.1.2
- Add
cap stage dbconsole
to open a database console.
v0.1.6
- Add
cap stage rake[db:create]
to execute a rake task in remote server.