簡體   English   中英

無法使用capistrano進行部署

[英]Can't deploy with capistrano

當我嘗試使用capistrano進行部署時,出現了一個錯誤:

上限生產部署:設置

我收到此錯誤消息:

/home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano/gateway.rb:55: formal argument cannot be an instance variable (SyntaxError)
          SSH.connect(server, @options) do |@session|
                                                    ^
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano/configuration/connections.rb:1:in `<top (required)>'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano/configuration.rb:4:in `<top (required)>'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano.rb:1:in `<top (required)>'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/lib/capistrano/cli.rb:1:in `<top (required)>'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/paul/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-2.0.0/bin/cap:3:in `<top (required)>'
from /home/paul/.rbenv/versions/2.0.0-p247/bin/cap:23:in `load'
from /home/paul/.rbenv/versions/2.0.0-p247/bin/cap:23:in `<main>'

這是我的Capfile:

load 'deploy' if respond_to?(:namespace) # cap2 differentiator
load 'config/deploy'

而我的deploy.rb:

要求“捆綁商/ capistrano”

# allowing shell interactions
default_run_options[:pty] = true

# multistaging
set :stages, %w(staging production)
set :default_stage, "staging"
require 'capistrano/ext/multistage'

set :application, "myapp"
set :user, "myapp"
set :repository,  "git@gitlab.conicrea.com:conicrea/myapp.git"
set :ssh_options, { :forward_agent => true }
set :deploy_to, "/var/www/#{application}"

set :scm, :git
set :deploy_via, :remote_cache

# number of releases we want to keep
set :keep_releases, 3

set :use_sudo, false
# default rails_env, should be overrided in config/deploy/#{environnement}.rb
set :rails_env, "staging"

# unicorn informations
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{shared_path}/pids/unicorn.pid"
set :unicorn_bin, "#{current_path}/bin/unicorn"

# useful for rbenv
set :default_environment, {
  'PATH' => "/home/synbioz/.rbenv/shims:/home/synbioz/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
}

namespace :maintenance do
  task :start do
    run "ln -nfs #{shared_path}/system/_maintenance.html #{shared_path}/system/maintenance.html"
  end

  task :stop do
    run "rm -f #{shared_path}/system/maintenance.html"
  end
end

namespace :deploy do
  task :start, :roles => :app, :except => { :no_release => true } do
    run <<-CMD
      cd #{current_path} && #{unicorn_bin} -c #{unicorn_config} -E #{rails_env} -D
    CMD
  end

  task :force_stop, :roles => :app, :except => { :no_release => true } do
    run <<-CMD
      if [ -e #{unicorn_pid} ]; then
        kill -9 $(cat #{unicorn_pid});
      fi
    CMD
  end

  task :stop, :roles => :app, :except => { :no_release => true } do
    run <<-CMD
      if [ -e #{unicorn_pid} ]; then
        kill $(cat #{unicorn_pid});
      fi
    CMD
  end

  task :graceful_stop, :roles => :app, :except => { :no_release => true } do
    run <<-CMD
      if [ -e #{unicorn_pid} ]; then
        kill -s QUIT $(cat #{unicorn_pid});
      fi
    CMD
  end

  task :reload, :roles => :app, :except => { :no_release => true } do
    run <<-CMD
      if [ -e #{unicorn_pid} ]; then
        kill -s USR2 $(cat #{unicorn_pid});
      fi
    CMD
  end

  task :restart, :roles => :app, :except => { :no_release => true } do
    run <<-CMD
      if [ -e #{unicorn_pid} ]; then
        kill -9 $(cat #{unicorn_pid});
        sleep 5;
        cd #{current_path} && #{unicorn_bin} -c #{unicorn_config} -E #{rails_env} -D;
      fi
    CMD
  end
end

desc "Create shared folders."
after 'deploy:setup', :roles => :app do
  # for unicorn
  run "mkdir -p #{shared_path}/sockets"
  run "mkdir -p #{shared_path}/config"
  # only for sqlite
  run "mkdir -p #{shared_path}/db"
end

desc "Link db.yml."
after 'deploy:update_code', :roles => :app do
  run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end

desc "Seed datas when cold deploying."
after 'deploy:migrate', :roles => :app, :only => { :no_release => true } do
  run "cd #{release_path} && bin/rake db:seed RAILS_ENV=#{rails_env}"
end

desc "Link maintenance, rbenv and precompile assets."
after 'deploy:symlink', :roles => [:web, :app] do
  run "ln -nfs #{shared_path}/config/.rbenv-version #{release_path}/config/.rbenv-version"
  run "cp #{release_path}/public/_maintenance.html #{shared_path}/system/"
  run "cd #{release_path}; RAILS_ENV=#{rails_env} bin/rake assets:precompile"
end

desc "remove unused releases."
after "deploy", "deploy:cleanup"

我不知道該怎么辦 ! 有人可以幫我嗎?

非常感謝 !

那是Capistrano的一個老的版本(2.0.0是從2007年7月開始的,並且不支持Ruby 1.9 / 2.0中的更改-在這種情況下,Ruby 1.9不再允許使用實例變量作為塊的參數)。

您需要升級到最新的2.x版本(2.15.5)。

您也可以升級到Capistrano v3,但是請記住,這是一次完全的重寫,並且您的現有配置將無法與v3兼容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM