Capify The Pony
作者:gugod 發佈於:I managed to deploy Jifty apps with Capistrano.
Capistrano is a tool for deploying Rails apps, however, with some small tweaks, it can be used to deploy Jifty apps.
Install it:
gem install capistrano
The first step is to capify
your Jifty app:
cd /path/to/AwesomeJiftyApp
mkdir config
capify .
It generates a config/deploy.rb
file, which we modify it to satisfy what we need. Here's an example that deploys to example.com
:
set :application, "AwesomeJiftyApp"
set :repository, "git@git.example.com/awesome.git"
set :deploy_to, "/home/apps/awesome"
set :scm, :git
set :use_sudo, false
set :deploy_via, :remote_cache
role :app, "example.com"
role :web, "example.com"
role :db, "example.com", :primary => true
namespace :deploy do
desc "Create database.yml and asset packages for production"
task :after_update_code, :roles => [:web] do
run "cp -r #{shared_path}/etc/* #{latest_release}/etc/"
end
desc "Restart the app is undefined to be a no-op."
task :restart, :roles => :app, :except => { :no_release => true } do
end
task :migrate, :roles => :app do
run "cd #{latest_release}; bin/jifty schema --setup"
end
# Un-define some rails-specific tasks.
[:start, :stop, :finalize_update].each do |t|
desc "#{t} task is a no-op."
task t, :roles => :app do ; end
end
end
It's pure ruby code. For those Perl programmers who wonder what the do...end
means, it mean a code ref like sub { ... }
.
Run the setup task. This will create the required directories on the remote host example.com:
cap deploy:setup
In my case, I put site_config.yml
, which contains the database username/password setting, to /home/apps/awesome/shared/etc
, and copy it over to the latest app dir every time.
Then, run a "cold" start, this will prepare the directory structure and run database migration:
cap deploy:cold
Afterwards, you just git push
your code and then run:
cap deploy
Then the latest code will be re-deployed.
The example deploy.rb
undefined several rails-specific steps. Including the restart of the server. That will certainly depends on how you config it. You might be able to put:
run "sudo apache2ctl restart"
... in there. If you config your app to be instantiated with apache2 + fastcgi.
Definitely check the Capistrano documentation for more tweaks in deploy.rb
setting. This is a practically useful tool, and it shouldn't be difficult to play with.