Setting up Nesta CMS with Capistrano and nginx
I already had Passenger and nginx set up on my Linode. I'll assume that git is already installed and that the user is familiarized with its use.
Follow the very simple instructions here to set up a local installation of Nesta. Create a new remote git repository and push over your new nesta code.
In the top of your new nesta directory, install the capistrano gem, run capify and manually edit your deploy.rb. I used the config/deploy.rb file I found here as a reference. Mine looks like this:
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :domain, "scott-martin.com"
set :application, "scott-martin.com"
set :deploy_to, "/var/www/scott-martin.com"
set :user, "scott"
set :use_sudo, false
set :scm, "git"
set :repository, "git@github.com:smm/scott-martin.com.git"
set :branch, 'master'
set :git_shallow_clone, 1
role :web, domain
role :app, domain
role :db, domain, :primary => true
set :deploy_via, :remote_cache
namespace :deploy do
task :start do ; end
task :stop do ; end
# Assumes you are using Passenger
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
task :finalize_update, :except => { :no_release => true } do
run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
# mkdir -p is making sure that the directories are there for some SCM's that don't save empty folders
run <<-CMD
rm -rf #{latest_release}/log &&
mkdir -p #{latest_release}/public &&
mkdir -p #{latest_release}/tmp &&
ln -s #{shared_path}/log #{latest_release}/log
CMD
if fetch(:normalize_asset_timestamps, true)
stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
asset_paths = %w(images css).map { |p| "#{latest_release}/public/#{p}" }.join(" ")
run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
end
end
end
At this point I had to make sure my ssh public keys on all of my machines could authenticate to one another.
Now just run cap deploy and hopefully the script will pull your nesta code from your git repository and place it in the correct location on your production server.
I use sites-available and sites-enabled to manage nginx configuration for various sites hosted on this box. Here is my sites-available file:
server {
listen 80;
server_name www.scott-martin.com scott-martin.com;
access_log /var/log/nginx/scott-martin.com.access.log;
error_log /var/log/nginx/scott-martin.com.error.log;
root /var/www/scott-martin.com/current/public;
passenger_enabled on;
}
The ease with which this post was written and deployed has already justified the slight learning curve involved in getting everything set up. I look forward to using and customizing Nesta in the future.
