Доброго времени суток. Есть проблема с деплоем Ruby on Rails приложения. В целом проблемы две:
- 1 - проблема с хуками, before\after
- 2 - если временно исключить хуки, то при cap deploy: «undefined local variable or method `tasks_without_stage_dependecy`»
И так к нашим кроликам: Файл Capfile
#load 'deploy'
# Uncomment if you are using Rails' asset pipeline
# load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy.rb' # remove this line to skip loading any of the default tasks
Файл deploy.rb:
hz_config =
{:name => "www.example.com",
:domain => "www.example.com",
:path => "www.example.com",
:gitname => "example.git",
:shared_paths => {"import" => "tmp/import"}}
set :application, hz_config[:name]
# set :default_environment, {
# 'PATH' => "/usr/local/rvm/gems/ruby-1.9.3-p194/bin:$PATH",
# 'RUBY_VERSION' => 'ruby 1.9.3',
# 'GEM_HOME' => '/usr/local/rvm/gems/ruby-1.9.3-p194/',
# 'GEM_PATH' => '/usr/local/rvm/gems/ruby-1.9.3-p194/',
# 'BUNDLE_PATH' => '/usr/local/rvm/gems/ruby-1.9.3-p194/' # If you are using bundler.
# }
set :rvm_ruby_string, '1.9.3' # you probably have this already
set :rvm_type, :system # this is the money config, it defaults to :system
# Deploy to & branch
#set :deploy_to, "/home/webmaster/#{hz_config[:path]}/rails"
#set :branch, "master"
set :deploy_to, "/home/webmaster/#{hz_config[:path]}/test"
set :branch, "development"
# Path settings
set :mongrel_conf, "#{current_path}/config/thin_cluster.yml"
# SSH and Network settings
#default_run_options[:pty] = true
set :ssh_options, { :forward_agent => true, :port => '1234' }
set :user, "webmaster1234"
set :use_sudo, false
#role :app, %w{example.com}
#role :web, %w{example.com}
#role :db, %w{example.com}
after 'deploy:setup', 'custom:create_shared_directories'
namespace :deploy do
task :start do
run "thin start -C#{mongrel_conf}"
end
task :stop do
run "thin start -C#{mongrel_conf}"
end
task :restart do
run "thin restart -C#{mongrel_conf} --onebyone"
end
end
namespace :customs do
task :setup do
end
# create directories for images
desc "Create directories for images"
task :create_shared_directories do
on roles(:all) do |host|
hz_config[:shared_paths].each do |shared, real|
mkdir "-p #{shared_path}/#{shared}"
end
end
end
# make the symlink for public/uploads
desc "Make the symlink for public/uploads"
task :make_public_images_files do
on roles(:all) do |host|
hz_config[:shared_paths].each do |shared, real|
rm "-rf #{release_path}/#{real}"
ln "-fs #{shared_path}/#{shared} #{release_path}/#{real}"
end
end
end
desc "Copy config cluster files"
task :copy_configs do
on roles(:all) do |host|
cp "#{shared_path}/config/database.yml #{release_path}/config"
cp "#{shared_path}/config/thin_cluster.yml #{release_path}/config"
end
end
#after "deploy:update_code", :copy_configs
desc "Compile assets"
task :pipeline_precompile do
on roles(:all) do |host|
cd '#{release_path}' && "#{rake} assets:precompile RAILS_ENV=#{rails_env}"
end
end
end
Файл deploy/staging.rb:
server 'example.com', roles: [:web, :app, :db]
# GIT
set :scm, "git"
set :repository, "user@host.com/~/git/#{hz_config[:gitname]}"
set :deploy_via, :remote_cache
set :git_shallow_clone, 1
set :copy_exclude, [".git", ".gitignore"]
set :keep_releases, 3
Вывод команд:
rails -v
Rails 3.2.3
gem list
...
capistrano (3.0.0)
capistrano-ext (1.2.1)
...
Проблема в том что если использовать хуки, при cap deploy жалуется «Dont know how to build task %hook name%. Если же закомментировать строчки с вызовом хуков - „undefined local variable or method `tasks_without_stage_dependecy`“
Все это безобразие настраивается на Windows 7 к сожалению, ну тут уж корпоративная политика, поделать ничего не могу. Работает в рамках RailsInstaller.
Вот такая вот проблема. Заранее спасибо за помощь.