2

当我尝试在我的登台机器上使用 Capistrano 进行部署时,我收到以下错误

该错误与 Gemfile.lock 的版本控制有关

     ** [out :: 192.168.1.14] The --deployment flag requires a Gemfile.lock. Please make sure you have checked your Gemfile.lock into version control before deploying.

我用来部署的命令如下:

cap deploy -S stage=staging

然后,当我执行此命令时,出现以下错误。

错误跟踪的上下文

    [192.168.1.14] executing command
 ** [192.168.1.14 :: out] Error reading response length from authentication socket.
 ** [192.168.1.14 :: out] Error reading response length from authentication socket.
 ** [192.168.1.14 :: out] HEAD is now at 09c5581 Adding RVM-capistrano to the Gemfile
    command finished in 5615ms
    copying the cached version to /home/teenscrio/releases/20121119211914
  * executing "cp -RPp /home/teenscrio/shared/cached-copy /home/teenscrio/releases/20121119211914 && (echo 09c5581d51877dea7284870c48103900624f667c > /home/teenscrio/releases/20121119211914/REVISION)"
    servers: ["192.168.1.14"]
    [192.168.1.14] executing command
    command finished in 453ms
  * executing `deploy:finalize_update'
    triggering before callbacks for `deploy:finalize_update'
  * executing `bundle:install'
  * executing "cd /home/teenscrio/releases/20121119211914 && bundle install --gemfile /home/teenscrio/releases/20121119211914/Gemfile --path /home/teenscrio/shared/bundle --deployment --quiet --without development test"
    servers: ["192.168.1.14"]
    [192.168.1.14] executing command
 ** [out :: 192.168.1.14] The --deployment flag requires a Gemfile.lock. Please make sure you have checked your Gemfile.lock into version control before deploying.
    command finished in 626ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/teenscrio/releases/20121119211914; true"
    servers: ["192.168.1.14"]
    [192.168.1.14] executing command
    command finished in 402ms
failed: "rvm_path=$HOME/.rvm/ /usr/local/rvm/bin/rvm-shell '1.8.7' -c 'cd /home/teenscrio/releases/20121119211914 && bundle install --gemfile /home/teenscrio/releases/20121119211914/Gemfile --path /home/teenscrio/shared/bundle --deployment --quiet --without development test'" on 192.168.1.14

我使用 bundle install 的 Gemfile

source 'http://rubygems.org'

gem 'rails', '3.0.6'
gem 'rake', '0.8.7'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql' #Development in windows
# Necesitamos una versión de mysql2 inferior a la 0.3 para poder trabajar con
# la última versión de REE (1.8.7-2012.02) y con Rails 3.0.x
gem 'mysql2', '< 0.3'

gem 'mongrel'
gem 'jquery-rails', '>= 0.2.7' #Replace Prototype with JQuery
gem 'active_scaffold_vho' #Used in typical CRUD interfaces
gem 'inherited_resources', '~> 1.2.1' #Used for more complex views such the home page
gem 'has_scope', '~> 0.5.0' #Used in the positions controller
gem 'json_pure' #Used to parse events
gem 'formtastic', '~> 1.2.3' #Used in forms
gem 'devise', '~> 1.3.4' #Authentication
gem 'recaptcha', :require => 'recaptcha/rails' #Captcha for register

gem 'uuidtools', '~> 2.1.2'

gem 'rvm-capistrano'
gem 'capistrano', '~> 2.6.0' #Deployments

gem 'cgi_multipart_eof_fix'
gem 'fastthread'

gem 'mongoid', "~> 2.0" #Mongoid
gem 'bson_ext', "~> 1.3" #Mongoid

gem 'redis', "~> 2.2.0"
gem 'resque'
gem 'resque-scheduler'

gem 'SystemTimer', "~> 1.2.3" #recomended by mongoid and redis

gem 'ar_mailer_rails3' #Mailer system
gem 'lazy_high_charts', "~> 1.1.1" #Dashboard charts

gem 'rails-breadcrumbs', "~> 1.0.0"

gem 'curb' #Used to send commands to terminals

gem 'geonames', "~> 0.2.2" #Used to 

gem 'activemerchant'

gem 'savon', "~> 0.9.7"

gem 'rack-ssl'
gem 'state_machine'

gem "http_accept_language", '~> 1.0.2'

gem 'recurly', '~> 2.1.0'
gem 'newrelic_rpm'

end

我从 config/deploy.rb 执行的 Capistrano 脚本

require "bundler/capistrano"

#$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'rvm/capistrano'
set :rvm_ruby_string, '1.8.7'

set :rvm_bin_path, "/usr/local/rvm/bin"

set :application, "teenscrio"
set :deploy_to, "/home/teenscrio/"

set :stage, "staging" unless variables[:stage]

case stage
when "staging"

    #set :rvm_ruby_string, '/home/teenscrio/.rvm/gems/ruby-1.8.7-p371'
    #set :rvm_type, :user  # Don't use system-wide RVM

    #set :bundle_cmd, '/usr/local/rvm/bin/bundle'

    set :cgi_files_user, "apache"
    set :cgi_files_group, "apache"


    set :restart_rails_file_user, "teenscrio"
    set :restart_rails_file_group, "development"

    default_run_options[:pty] = true
    ssh_options[:forward_agent] = true

    set :scm, "git"
    set :user, "teenscrio"  # The server's user for deploys
    set :scm_username, Capistrano::CLI.ui.ask('Introduce el usuario de git:')
    set :scm_passphrase, Capistrano::CLI.ui.ask('Introduce el password de git:')
    set :scm_verbose, true
    set :branch, "master"
    set :use_sudo, true
    set :deploy_via, :remote_cache

    set :teenscrio1, '192.168.1.14' #Teenscrio 1
    set :teenscrio2, '192.168.1.14' #Teenscrio 2

    set :frontend_machine, teenscrio2
    #FUTUROS FRONTALES DEFINIR ASI
    #set :frontend_machine2, *********
    #set :frontend_machine3, *********
    set :directory_server_machine, teenscrio1
    set :server_machine, teenscrio1

    set :repository,  "git@bitbucket.org:repo.git"  # Your clone URL
    set :local_repository, "git@bitbucket.org:repo.git"  # Your clone URL
    set :tracker_path, "tracker/url"
    set :config_file_sufix, "prd"

    role :web, server_machine
    role :app, server_machine
    role :db,  server_machine, :primary => true
    role :engine, server_machine
    role :dispatcher,  frontend_machine , directory_server_machine #FUTUROS FRONTALES AÑADIR AL ARRAY: frontend_machine, frontend_machine2, frontend_machine3, directory_server_machine
    role :listener, frontend_machine #FUTUROS FRONTALES AÑADIR AL ARRAY: frontend_machine , frontend_machine2 , frontend_machine3]
    role :directory_server, directory_server_machine

    role :directory_server_machine, directory_server_machine
    role :frontend_machine, frontend_machine
    role :server_machine, server_machine


when "production"
    set :cgi_files_user, "apache"
    set :cgi_files_group, "apache"

    set :restart_rails_file_user, "teenscrio"
    set :restart_rails_file_group, "development"

    set :user, 'teenscrio'
    set :use_sudo, true
    set :scm, :subversion

    set :deploy_via, 'export'
    default_run_options[:pty] = true
    set :usuario, Capistrano::CLI.ui.ask('Introduce el usuario de svn:')
    ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", usuario)]
    set :password, Capistrano::CLI.password_prompt('Introduce la password del usuario teenscrio de producción:')
    set :teenscrio1, '192.168.2.2' #Teenscrio 1
    set :teenscrio2, '192.168.2.3' #Teenscrio 2

    set :frontend_machine, teenscrio2
    #FUTUROS FRONTALES DEFINIR ASI
    #set :frontend_machine2, *********
    #set :frontend_machine3, *********
    set :directory_server_machine, teenscrio1
    set :server_machine, teenscrio1


    set :repository,  "svn+ssh://repo/trunk"
    set :local_repository, "svn+ssh://repo/trunk"
    set :tracker_path, "url/tracker"
    set :config_file_sufix, "prd"

    role :web, server_machine
    role :app, server_machine
    role :db,  server_machine, :primary => true
    role :engine, server_machine
    role :dispatcher,  frontend_machine , directory_server_machine #FUTUROS FRONTALES AÑADIR AL ARRAY: frontend_machine, frontend_machine2, frontend_machine3, directory_server_machine
    role :listener, frontend_machine #FUTUROS FRONTALES AÑADIR AL ARRAY: frontend_machine , frontend_machine2 , frontend_machine3]
    role :directory_server, directory_server_machine

    role :directory_server_machine, directory_server_machine
    role :frontend_machine, frontend_machine
    role :server_machine, server_machine

else
  raise "unsupported staging environment: #{stage}"
end



namespace :webapp do
  web_previous_release = "#{previous_release}/webapp"
  web_release_path = "#{release_path}/webapp"
  web_shared_path = "#{shared_path}/webapp"

  namespace :bundler do
    task :symlink_vendor_rollback, :roles => :app do
      p "********************** BUNDLER:SYMLINK_ROLLBACK ******************************"
      run("ln -sf #{web_previous_release}/Gemfile #{web_shared_path}/Gemfile")
      run("cd #{web_previous_release} && bundle install --path vendor  --without=test development")
    end
    task :symlink_vendor, :roles => :app do
      p "********************** BUNDLER:SYMLINK ******************************"
      shared_gems = File.join(web_shared_path, 'vendor/ruby')
      release_gems = "#{web_release_path}/vendor/ruby"
#      run("mkdir -p #{release_gems}")
      run("mkdir -p #{shared_gems} && ln -sfn #{shared_gems} #{release_gems}")
      run("ln -sf #{current_path}/Gemfile #{shared_path}/Gemfile") #Uncoment this if there is bug in following symlinks when running bundle install
    end

    task :run_bundle_install, :roles => :app do
      p "********************** BUNDLER:BUNDLE INSTALL ******************************"
      run("cd #{web_release_path} && bundle install --binstubs --path vendor --without=test development")
    end

    task :new_release, :roles => :app do
      bundler.symlink_vendor
      bundler.run_bundle_install
    end
  end

  namespace :other do
    task :rename_samples, :roles => :app do
      p "********************** OTHER:RENAME SAMPLES ******************************"
      run("cd #{web_release_path}/config &&
        mv database.yml.sample database.yml &&
        mv mongoid.yml.sample mongoid.yml &&
        mv resque.yml.sample resque.yml &&        
        mv resque_schedule.yml.sample resque_schedule.yml &&
        mv redis.yml.sample redis.yml")
      run("cd #{web_release_path}/script/config &&
        mv resqueRedis.conf.sample resqueRedis.conf")
    end

    task :symlink, :roles => :app do
      p "********************** OTHER:SYMLINK ******************************"
      run("ln -sfn #{web_shared_path}/videos #{web_release_path}/public/videos")
      run("ln -sfn #{shared_path}/agent #{web_release_path}/public/agent")
      run("ln -sfn #{shared_path}/paquetes #{web_release_path}/public/paquetes")
    end

  end

  namespace :ar_mailer do
    task :start, :roles => :app do
      begin
      p "********************** AR_MAILER:START ******************************"
      run("cd #{web_release_path} &&
           export PATH=/opt/ruby/bin:$PATH &&
           export BUNDLE_GEMFILE=#{web_release_path}/Gemfile &&
           ./bin/ar_sendmail_rails3 -e #{stage} -d -p #{shared_path}/pids/ar_mailer.pid")
      rescue
      end
    end

    task :stop, :roles => :app do
    p "********************** AR_MAILER:STOP ******************************"
      begin
        run(" kill -2 `cat #{shared_path}/pids/ar_mailer.pid`")
      rescue
      end
    end
  end

  namespace :resque do

    namespace :web do
      task :start, :roles => :app do
        p "********************** RESQUE:WEB:START ******************************"
        run("cd #{web_release_path} &&
             export PATH=/opt/ruby/bin:$PATH &&
             export BUNDLE_GEMFILE=#{web_release_path}/Gemfile &&
             ./bin/resque-web #{web_release_path}/script/config/resque_web.rb --pid-file #{shared_path}/pids/resque_web.pid ")
      end


      task :stop, :roles => :app do
        begin
          p "********************** RESQUE:WEB:STOP ******************************"
          run("kill -9 `cat #{shared_path}/pids/resque_web.pid`")
        rescue
          p "WARNING: Unable to kill resque web, it may wasn't running"
        end
      end

    end


    namespace :worker do
      task :start, :roles => :app do
        p "********************** RESQUE:WORKER:START ******************************"
        run("cd #{web_release_path} &&
             export PATH=/opt/ruby/bin:$PATH &&
             export BUNDLE_GEMFILE=#{web_release_path}/Gemfile &&
             nohup ./bin/rake environment resque:work QUEUE=* RAILS_ENV=#{stage} VERBOSE=1 PIDFILE=#{shared_path}/pids/resque_worker.pid &")
      end

      task :stop, :roles => :app do
        begin
          p "********************** RESQUE:WORKER:STOP ******************************"
          run("kill -9 `cat #{shared_path}/pids/resque_worker.pid`")
        rescue
          p "WARNING: Unable to kill resque worker, it may wasn't running"
        end
      end

    end

    namespace :scheduler do
      task :start, :roles => :app do
        p "********************** RESQUE:SCHEDULER:START ******************************"
        run("cd #{web_release_path} &&
             export PATH=/opt/ruby/bin:$PATH &&
             export BUNDLE_GEMFILE=#{web_release_path}/Gemfile &&
             nohup ./bin/rake resque:scheduler RAILS_ENV=#{stage} VERBOSE=1 PIDFILE=#{shared_path}/pids/resque_scheduler.pid &")
      end

      task :stop, :roles => :app do
        begin
          p "********************** RESQUE:SCHEDULER:STOP ******************************"
          run("kill -9 `cat #{shared_path}/pids/resque_scheduler.pid`")
        rescue
          p "WARNING: Unable to kill resque scheduler, it may wasn't running"
        end        
      end

    end

    namespace :redis do
      task :start, :roles => :app do
        p "********************** RESQUE:REDIS:START ******************************"
        run("cd #{web_release_path}/script && chmod 755 startResqueRedis.sh")
        run("cd #{web_release_path}/script &&
             nohup ./startResqueRedis.sh &")
      end
    end


    task :stop, :roles => :app do
      web.stop
      scheduler.stop
      worker.stop
    end

    task :start, :roles => :app do
      redis.start
#      scheduler.start
#      worker.start
#      web.start
    end

  end


end

namespace :servers do

  server_queues_path = "#{shared_path}/server/queues"

   namespace :directory_server do
    directory_server_previous_release = "#{previous_release}/server/directory_server"
    directory_server_release_path = "#{release_path}/server/directory_server"
    directory_server_shared_path = "#{shared_path}/server/directory_server"

    task :stop, :roles => :directory_server  do 
      p "********************** directory_server STOP ******************************"
      run("cd #{directory_server_release_path}/scripts && chmod 755 stopDirectoryServer.sh")
      run("cd #{directory_server_release_path}/scripts && ./stopDirectoryServer.sh")
    end

    task :rename_samples, :roles => :directory_server  do
      p "********************** directory_server RENAME SAMPLES ******************************"
      run("cd #{directory_server_release_path}/config &&
        mv config.properties.#{config_file_sufix}.sample config.properties &&
        mv log4j.properties.#{config_file_sufix}.sample log4j.properties")
    end

    task :symlinks, :roles => :directory_server  do
      p "********************** directory_server SYMLINKS ******************************"
      run("ln -sfn #{server_queues_path} #{directory_server_release_path}/scripts/queue")
    end

    task :start, :roles => :directory_server,:shell => "/bin/bash"  do
      p "********************** :directory_server START ******************************"
      run "cd #{directory_server_release_path}/scripts && nohup ./startDirectoryServer.sh #{stage}", :pty => true
      #run("cd #{engine_release_path}/scripts && nohup touch paquito.txt > foo.out 2>&1 &", :pty => true)
    end

    task :compile, :roles => :directory_server  do
      p "********************** :directory_server COMPILE ******************************"
      run("cd #{directory_server_release_path}/scripts && ./installDirectoryServer.sh")
    end

    task :new_release, :roles => :directory_server  do
      directory_server.stop
      directory_server.symlinks
      directory_server.rename_samples
      directory_server.compile
    end

  end




  namespace :engine do
    engine_previous_release = "#{previous_release}/server/engine"
    engine_release_path = "#{release_path}/server/engine"
    engine_shared_path = "#{shared_path}/server/engine"

    task :stop, :roles => :engine  do 
      p "********************** ENGINE: STOP ******************************"
      run("cd #{engine_release_path}/scripts && chmod 755 stopEngine.sh")
      run("cd #{engine_release_path}/scripts && ./stopEngine.sh")
    end

    task :rename_samples, :roles => :engine  do
      p "********************** ENGINE: RENAME SAMPLES ******************************"
      run("cd #{engine_release_path}/config &&
        mv config.properties.#{config_file_sufix}.sample config.properties &&
        mv log4j.properties.#{config_file_sufix}.sample log4j.properties")
    end

    task :symlinks, :roles => :engine  do
      p "********************** ENGINE: SYMLINKS ******************************"
      run("ln -sfn #{server_queues_path} #{engine_release_path}/scripts/queue")
    end

    task :start, :roles => :engine,:shell => "/bin/bash"  do
      p "********************** ENGINE: START ******************************"
      run "cd #{engine_release_path}/scripts && nohup ./startEngine.sh #{stage}", :pty => true
      #run("cd #{engine_release_path}/scripts && nohup touch paquito.txt > foo.out 2>&1 &", :pty => true)
    end

    task :compile, :roles => :engine  do
      p "********************** ENGINE: COMPILE ******************************"
      run("cd #{engine_release_path}/scripts && ./installEngine.sh")
    end

    task :new_release, :roles => :engine  do
      engine.stop
      engine.symlinks
      engine.rename_samples
      engine.compile
    end

  end

  namespace :dispatcher do
    dispatcher_previous_release = "#{previous_release}/server/dispatcher"
    dispatcher_release_path = "#{release_path}/server/dispatcher"
    dispatcher_shared_path = "#{shared_path}/server/dispatcher"

    task :stop, :roles => [:dispatcher] do
      p "********************** DISPATCHER: STOP ******************************"
      run("cd #{dispatcher_release_path}/scripts && chmod 755 stopDispatcher.sh")
      run("cd #{dispatcher_release_path}/scripts && ./stopDispatcher.sh")
    end

    task :start, :roles => [:dispatcher] do
      p "********************** DISPATCHER: START ******************************"      
      run("cd #{dispatcher_release_path}/scripts && nohup ./startDispatcher.sh #{stage}", :pty => true)
    end

    task :symlinks, :roles => [:dispatcher] do
      p "********************** DISPATCHER: SYMLINKS ******************************"
      run("ln -sfn #{server_queues_path} #{dispatcher_release_path}/scripts/queue")
    end

    task :rename_samples, :roles => [:dispatcher] do
      p "********************** DISPATCHER: RENAME SAMPLES ******************************"
      run("cd #{dispatcher_release_path}/config &&
        mv config.properties.#{config_file_sufix}.sample config.properties &&
        mv log4j.properties.#{config_file_sufix}.sample log4j.properties")
    end

    task :compile, :roles => [:dispatcher] do
      p "********************** DISPATCHER: COMPILE ******************************"
      run("cd #{dispatcher_release_path}/scripts && ./installDispatcher.sh")
    end

    task :restart, :roles => [:dispatcher] do

    end

    task :new_release, :roles => [:dispatcher] do
      dispatcher.stop
      dispatcher.symlinks
      dispatcher.rename_samples
      dispatcher.compile
    end

  end

  namespace :frontend do
    frontend_previous_release = "#{previous_release}/server/frontend"
    frontend_release_path = "#{release_path}/server/frontend"
    frontend_shared_path = "#{shared_path}/server/frontend"

    task :symlinks, :roles => :listener do
      p "********************** FRONTEND: SYMLINKS ******************************"
      run("ln -sfn #{server_queues_path} #{frontend_release_path}/scripts/queue")
    end

    task :rename_samples, :roles => :listener do
      p "********************** FRONTEND: RENAME SAMPLES ******************************"
      run("cd #{frontend_release_path}/config &&
        mv config.properties.#{config_file_sufix}.sample config.properties &&
        mv log4j.properties.#{config_file_sufix}.sample log4j.properties")
    end

    task :compile, :roles => :listener do
      p "********************** FRONTEND: COMPILE ******************************"
      run "cd #{frontend_release_path}/scripts && #{try_sudo} ./installFrontEnd.sh #{tracker_path}"
    end

    task :change_permissions, :roles => :listener do
      p "********************** FRONTEND: CHANGE PERMISSIONS ******************************"
      run "#{try_sudo} chown #{cgi_files_user}:#{cgi_files_group} #{tracker_path}/tracker.cgi && #{try_sudo} chmod 755 #{tracker_path}/tracker.cgi"
      run "#{try_sudo} chown #{cgi_files_user}:#{cgi_files_group} #{tracker_path}/commandServer.cgi && #{try_sudo} chmod 755 #{tracker_path}/commandServer.cgi"
    end

    task :new_release, :roles => :listener do
      frontend.symlinks
      frontend.rename_samples
      frontend.compile
      frontend.change_permissions      
    end
  end

  namespace :monit do
    task :stop, :roles => [:frontend_machine,:directory_server_machine,:server_machine] do
      p "********************** MONIT: STOP ******************************"
      run "#{try_sudo} /etc/init.d/monit stop"
    end

    task :start, :roles => [:frontend_machine,:directory_server_machine,:server_machine] do
      p "********************** MONIT: START ******************************"
      run "sleep 60"
      run "#{try_sudo} /etc/init.d/monit start"
    end

  end

  task :restart, :roles => [:frontend_machine,:directory_server_machine,:server_machine] do #En cada subtarea filtra por roles
    dispatcher.start
    engine.start    
    directory_server.start
  end

end

#AFTER SETUP
#after 'deploy:setup', 'webapp:setup'
#after 'deploy:setup', 'servers:engine:setup'
#after 'deploy:setup', 'servers:dispatcher:setup'
#after 'deploy:setup', 'servers:frontend:setup'


#AFTER UPDATE CODE
after 'deploy:update_code', 'servers:monit:stop'
after 'deploy:update_code', 'webapp:resque:stop' #Monit is supossed to restart resque
after 'deploy:update_code', 'webapp:bundler:new_release'
after 'deploy:update_code', 'webapp:other:rename_samples'
after 'deploy:update_code', 'webapp:other:symlink'
#after 'deploy:update_code', 'webapp:ar_mailer:stop'

after 'deploy:update_code', 'servers:frontend:new_release'
after 'deploy:update_code', 'servers:dispatcher:new_release'
after 'deploy:update_code', 'servers:directory_server:new_release'
after 'deploy:update_code', 'servers:engine:new_release'
#after 'deploy:update_code', 'webapp:ar_mailer:start'
after 'deploy',             'servers:restart'
after 'deploy',             'webapp:resque:redis:start'
after 'deploy',             'servers:monit:start'



# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts

# If you are using Passenger mod_rails uncomment this:
 namespace :deploy do
   task :start do  end
   task :stop do  end
   task :restart, :roles => :app, :except => { :no_release => true } do
     run "#{try_sudo} touch #{File.join(current_path,'webapp/tmp','restart.txt')}"
     run "#{try_sudo} chown #{restart_rails_file_user}:#{restart_rails_file_group} #{File.join(current_path,'webapp/tmp','restart.txt')}"
   end
 end

我需要做什么来部署代码?如何解决 Gemfile.lock 错误?

4

0 回答 0