Capistrano で bundle コマンドと rake コマンドを実行できません。次のようなデバッグ ログを取得します。
DEBUG [0f557e7e] /usr/bin/env: bundle
DEBUG [0f557e7e] : No such file or directory
すべてのmaコンピューター(開発および本番)にRVMがあります
これが私の設定です:
deploy.rb
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
production.rb
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 してそのコマンドをコピーして貼り付けると、正常に動作します。(そして、のような take コマンドでも同じことが起こります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: ""
編集:
また、すべてのパスを削除してPermitUserEnvironment
、 ~/.ssh/environment で使用してみました
タスクをトイレに変更
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
そしてそれは動作します。問題は実際にはパスにありましたが、シンボルを使用して and の使用を避ける方法はsource
ありcd
ますか?