您是否遵循了每一个步骤?
cap deploy:setup
cap deploy:cold
您是否创建了符号链接?我将在这里发布我的文件的工作演示..
我的部署.rb
require 'capistrano/ext/multistage'
require "bundler/capistrano"
require "rvm/capistrano"
set :user, 'ubuntu'
set :application, "yourapp"
set :use_sudo, true
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
set :rvm_path, "/home/ubuntu/.rvm"
set :rvm_bin_path, "#{rvm_path}/bin"
set :rvm_lib_path, "#{rvm_path}/lib"
set :rvm_ruby_string, 'ruby-1.9.3-p448'
set :rvm_type, :system
set :default_environment, {
'PATH' => "/home/ubuntu/.rvm/gems/ruby-1.9.3-p448/bin:/home/ubuntu/.rvm/gems/ruby-1.9.3-p448@global/bin:$PATH",
'RUBY_VERSION' => 'ruby-1.9.3-p448',
'GEM_HOME' => "/home/ubuntu/.rvm/gems/ruby-1.9.3-p448",
'GEM_PATH' => "/home/ubuntu/.rvm/gems/ruby-1.9.3-p448:/home/ubuntu/.rvm/gems/ruby-1.9.3-p448@global",
'BUNDLE_PATH' => "/home/ubuntu/.rvm/gems/ruby-1.9.3-p448:/home/ubuntu/.rvm/gems/ruby-1.9.3-p448@global" # If you are using bundler.
}
set :scm, 'git'
# # repository to be set for gitlab
set :repository, "git@github.com:ur-repo.git"
# set :branch, "staging"
set :git_shallow_clone, 1
set :deloy_via, :remote_cache
set :keep_releases, 3
set :scm_verbose, true
set :stages, ["staging", "production"]
set :default_stage, "staging"
set :migrate_target, :latest
default_run_options[:pty] = true
ssh_options[:forward_agent] = false
ssh_options[:keys] = ["yourfile.pem"]
after "deploy:create_symlink", "deploy:bundle_install"
namespace :bundler do
task :create_symlink, roles: :app do
shared_dir = File.join(shared_path, 'bundle')
release_dir = File.join(current_release, '.bundle')
run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
end
task :bundle_new_release, roles: :app do
bundler.create_symlink
run "cd #{release_path} && source $HOME/.bash_profile && bundle install"
end
end
after 'deploy:finalize_update', 'bundler:bundle_new_release'
after 'deploy:bundle_install', 'deploy:precompile_application'
after 'deploy:restart', 'deploy:cleanup'
还有我的 staging.rb
set :domain, "yourdomain"
set :rails_env, "staging"
# roles (servers)
role :web, domain
role :app, domain
role :db, domain, :primary => true
set :deploy_to, "/var/www/#{application}"
namespace :deploy do
desc "Copy config files"
after "deploy:update_code" do
run "export RAILS_ENV=staging"
run "cp #{shared_path}/config/database.yml #{release_path}/config/"
run "cp #{shared_path}/config/environments/staging.rb #{release_path}/config/environments/"
run "mkdir -p #{release_path}/public/images/ProfilePics"
sudo "chmod -R 0777 #{release_path}/tmp/"
sudo "chmod -R 0777 #{release_path}/log/"
end
task :restart, roles: :app, except: { no_release: true } do
run "touch #{File.join(current_path,'tmp','restart.txt')}"
end
desc 'run bundle install'
task :bundle_install, roles: :app do
run "cd #{current_path} && bundle install --deployment --path #{shared_path}/bundle"
end
desc "Reset the database"
task :reset do
# on_rollback { deploy.db.restore }
run "cd #{current_path}; bundle exec rake db:reset RAILS_ENV=staging"
end
desc "Migrate the database"
task :migrate do
# on_rollback { deploy.db.restore }
run "cd #{current_path}; bundle exec rake db:migrate RAILS_ENV=staging"
end
task :seed do
run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=staging"
end
task :precompile_application do
run "cd #{current_path}; bundle exec rake assets:precompile RAILS_ENV=staging"
end
end