README.md in capistrano-kyan-0.2.11 vs README.md in capistrano-kyan-0.3.0

- old
+ new

@@ -2,50 +2,150 @@ Capistrano plugin that includes a collection of tasks we find useful here at Kyan. ## Usage +### Prerequisites + +We assume you are using multi-stage environments. + ### Setup Add the library to your `Gemfile`: ```ruby group :development do gem 'capistrano-kyan' end ``` -And load it into your deployment script `config/deploy.rb`: +Update your config/deploy.rb. Here's an example one: ```ruby require 'capistrano-kyan' +require 'capistrano/ext/multistage' + +set :stages, %w(production staging) +set :default_stage, "staging" +set :application, "ournewserver.co.uk" + +set :user, "deploy" +set :use_sudo, false + +ssh_options[:forward_agent] = true +default_run_options[:pty] = true + +set :scm, :git +set :deploy_via, :copy +set :repository, "." +set :branch, "master" + +# If you are using Passenger mod_rails uncomment this: +namespace :deploy do + task :start do ; end + task :stop do ; end + task :restart, :roles => :app, :except => { :no_release => true } do + run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}" + end +end + +# these are the capistrano-kyan bits +after "deploy:setup", "kyan:vhost:setup" +after "deploy:finalize_update", "kyan:db:symlink" +after "deploy:create_symlink", "nginx:reload" ``` -Add kyan vhost task hook: +Add your vhost files: -```ruby -after "deploy:setup", "kyan:vhost:setup" ``` +# +# /config/vhosts/staging.vhost.conf.erb +# -Add kyan db task hook: +server { + listen 80; -```ruby -after "deploy:setup", "kyan:db:setup" + server_name staging.ournewserver.co.uk; + root /var/www/staging.ournewserver.co.uk/current/public; + passenger_enabled on; + rails_env staging; + client_max_body_size 4M; + + # serve static content directly + location ~* \.(ico|jpg|gif|png|swf|html)$ { + if (-f $request_filename) { + expires max; + break; + } + } +} ``` -### Test +and -First, make sure you're running the latest release: +``` +# +# /config/vhosts/production.vhost.conf.erb +# +server { + listen 80; + + server_name ournewserver.co.uk; + root /var/www/ournewserver.co.uk/current/public; + passenger_enabled on; + rails_env staging; + client_max_body_size 4M; + + # serve static content directly + location ~* \.(ico|jpg|gif|png|swf|html)$ { + if (-f $request_filename) { + expires max; + break; + } + } +} ``` -cap deploy:setup + +Now you need to update your multi-stage files to include these: + ``` +# +# config/deploy/staging.rb +# +server 'ournewserver.co.uk', :app, :web, :db, :primary => true +set :branch, "staging" +set :rails_env, 'staging' +set :deploy_to, "/var/www/staging.#{application}" +set :vhost_tmpl_name, "staging.vhost.conf.erb" +``` + +``` +# +# config/deploy/production.rb +# + +server 'ournewserver.co.uk', :app, :web, :db, :primary => true +set :branch, "staging" +set :rails_env, 'staging' +set :deploy_to, "/var/www/staging.#{application}" +set :vhost_tmpl_name, "production.vhost.conf.erb" +``` + +## Deploying + +This will create the directory structure. + + +``` +$ cap deploy:setup +``` + Then you can test each individual task: ``` -cap kyan:db:setup cap kyan:vhost:setup ``` ## Configuration @@ -53,19 +153,15 @@ - `vhost_env` - Set vhost environment. Default to `rails_env` variable. - `vhost_tmpl_path` - Set vhost template path. Default to `config/deploy`. - `vhost_tmpl_name` - Set vhost template name. Default to `vhost.conf.erb`. - `vhost_server_path` - Set vhost server path. Default to `/etc/nginx/sites-enabled`. -- `vhost_server_name` - Set vhost server name. Default to `File.basename(deploy_to)`. -I'm assuming you are using capistrano multistage. - ## Available Tasks To get a list of all capistrano tasks, run `cap -T`: ``` -cap kyan:db:setup # Creates a database.yml file in the apps shared path. cap kyan:vhost:setup # Creates and symlinks an Nginx virtualhost entry. ``` ## License \ No newline at end of file