我无法让Capistrano运行bundle命令和rake命令。 我得到这样的调试日志:
DEBUG [0f557e7e] /usr/bin/env: bundle
DEBUG [0f557e7e] : No such file or directory
我在所有计算机上都有RVM(开发和生产)
这是我的配置:
lock '3.1.0'
set :application, 'blog'
set :repo_url, 'git@github.com:xxx/yyyy.git'
set :deploy_to, '/home/joel/apps/blog'
set :deploy_via, :copy
set :rvm_ruby_version, '2.1.0p0'
set :default_env, { rvm_bin_path: '/home/joel/.rvm/bin:$PATH' }
SSHKit.config.command_map[:rake] = "#{fetch(:default_env)[:rvm_bin_path]}/rvm ruby-#{fetch(:rvm_ruby_version)} do bundle exec rake"
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
execute :touch, release_path.join('tmp/restart.txt')
end
end
desc 'Migrate db'
task :migrate do
on primary :db do
within release_path do
execute :rake, 'db:migrate'
end
end
end
desc 'Bundle install'
task :bundle do
on primary :app do
within release_path do
execute :bundle, 'install'
end
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
role :app, %w{xxx@yyy.com}
role :web, %w{xxx@yyy.com}
role :db, %w{xxx@yyy.com}
server 'yyy.com', user: 'xxx', roles: %w{web app}, my_property: :my_value
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
当我试着打电话
cap production deploy:bundle
如果我想在生产服务器上调用bundle:install
,这就是我得到的:
INFO [0f557e7e] Running /usr/bin/env bundle install on yyy.com
DEBUG [0f557e7e] Command: cd /home/joel/apps/blog/current && ( RVM_BIN_PATH=/home/joel/.rvm/bin:$PATH /usr/bin/env bundle install )
DEBUG [0f557e7e] /usr/bin/env: bundle
DEBUG [0f557e7e] : No such file or directory
虽然,如果我ssh到服务器并复制粘贴该命令,它可以正常工作。 (和rake db:migrate
)等命令一样,也会发生同样的事情。我很确定它与路径有关,所以这是我的
rvm info
ruby-2.1.0:
system:
uname: "Linux li101-172 3.12.6-x86_64-linode36 #2 SMP Mon Jan 13 18:54:10 EST 2014 x86_64 x86_64 x86_64 GNU/Linux"
system: "ubuntu/12.04/x86_64"
bash: "/bin/bash => GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)"
zsh: "/usr/bin/zsh => zsh 4.3.17 (x86_64-unknown-linux-gnu)"
rvm:
version: "rvm 1.25.14 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
updated: "15 days 19 hours 42 minutes 40 seconds ago"
path: "/home/joel/.rvm"
ruby:
interpreter: "ruby"
version: "2.1.0p0"
date: "2013-12-25"
platform: "x86_64-linux"
patchlevel: "2013-12-25 revision 44422"
full_version: "ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]"
homes:
gem: "/home/joel/.rvm/gems/ruby-2.1.0"
ruby: "/home/joel/.rvm/rubies/ruby-2.1.0"
binaries:
ruby: "/home/joel/.rvm/rubies/ruby-2.1.0/bin/ruby"
irb: "/home/joel/.rvm/rubies/ruby-2.1.0/bin/irb"
gem: "/home/joel/.rvm/rubies/ruby-2.1.0/bin/gem"
rake: "/home/joel/.rvm/rubies/ruby-2.1.0/bin/rake"
environment:
PATH: "/home/joel/.rvm/gems/ruby-2.1.0/bin:/home/joel/.rvm/gems/ruby-2.1.0@global/bin:/home/joel/.rvm/rubies/ruby-2.1.0/bin:/home/joel/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
GEM_HOME: "/home/joel/.rvm/gems/ruby-2.1.0"
GEM_PATH: "/home/joel/.rvm/gems/ruby-2.1.0:/home/joel/.rvm/gems/ruby-2.1.0@global"
MY_RUBY_HOME: "/home/joel/.rvm/rubies/ruby-2.1.0"
IRBRC: "/home/joel/.rvm/rubies/ruby-2.1.0/.irbrc"
RUBYOPT: ""
gemset: ""
我还尝试删除所有路径,并在〜/ .ssh / environment
中使用PermitUserEnvironment
将我的任务改为厕所
desc 'Bundle install'
task :bundle do
on primary :app do
within release_path do
execute 'source ~/.zshrc && cd ~/apps/blog/current/ && bundle install'
execute 'source ~/.zshrc && cd ~/apps/blog/current/ && RAILS_ENV=production rake db:migrate'
execute 'source ~/.zshrc && cd ~/apps/blog/current/ && RAILS_ENV=production rake assets:precompile'
end
end
end
它有效。所以问题实际上是路径,但有没有办法使用符号来避免使用source
和cd
?
答案 0 :(得分:0)
我最终重新安装了RVM,我的路径问题也解决了。我仍然不知道它为什么会起作用,但它确实有效。