【发布时间】:2015-11-26 05:23:52
【问题描述】:
在使用 mina 部署我的 rails 应用程序时,我遇到了类似 bash: line 82: bundle: command not found 的错误。我用谷歌搜索,但找不到任何解决方案。我该如何解决这个问题?
这是我的 deploy.rb
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
set :user, 'ubuntu'
set :domain, 'www.fuitter.com'
set :deploy_to, '/usr/share/nginx/html/fuitter'
set :repository, 'git@bitbucket.org:mc_cannibal/fuitter2.git'
set :branch, 'master'
set :forward_agent, true
set :shared_paths, ['config/database.yml', 'config/secrets.yml', 'log']
task :environment do
ruby_version = File.read('.ruby-version').strip
raise "Couldn't determine Ruby version: Do you have a file .ruby-version in your project root?" if ruby_version.empty?
queue %{
source /etc/profile.d/rvm.sh
rvm use #{ruby_version} || exit 1
}
end
task :setup => :environment do
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/log"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"]
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"]
# Add the repository server to .ssh/known_hosts
if repository
repo_host = repository.split(%r{@|://}).last.split(%r{:|\/}).first
repo_port = /:([0-9]+)/.match(repository) && /:([0-9]+)/.match(repository)[1] || '22'
queue! %[
if ! ssh-keygen -H -F #{repo_host} &>/dev/null; then
ssh-keyscan -t rsa -p #{repo_port} -H #{repo_host} >> ~/.ssh/known_hosts
fi
]
end
# Create database.yml for Postgres if it doesn't exist
path_database_yml = "#{deploy_to}/#{shared_path}/config/database.yml"
database_yml = %[production:
database: fuitter
adapter: postgresql
pool: 5
timeout: 5000]
queue! %[ test -e #{path_database_yml} || echo "#{database_yml}" > #{path_database_yml} ]
# Create secrets.yml if it doesn't exist
path_secrets_yml = "#{deploy_to}/#{shared_path}/config/secrets.yml"
secret =
secrets_yml = %[production:
secret_key_base:
#{`rake secret`.strip}]
queue! %[ test -e #{path_secrets_yml} || echo "#{secrets_yml}" > #{path_secrets_yml} ]
queue! %[chmod g+rx,u+rwx,o-rwx "#{deploy_to}/#{shared_path}/config"]
end
desc "Deploys the current version to the server."
task :deploy => :environment do
to :before_hook do
# Put things to run locally before ssh
end
deploy do
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
invoke :'deploy:cleanup'
to :launch do
#queue "service #{user} restart"
end
end
end
我应该在版本控制中推送 deploy.rb 文件吗? PS 我已经安装了 rvm。
【问题讨论】:
-
您是否在服务器上安装了您正在使用的 Ruby 版本的捆绑程序?
-
@p4sh4 是的,我已经在服务器中安装了捆绑程序。我又试了一次,错误仍然存在。
-
您确定在服务器上安装了与本地
.ruby-version中定义的相同版本的Ruby 吗? -
@p4sh4,是的。当我在本地机器上运行
cat .ruby-version时,我得到了 2.2.3。我在服务器上运行ruby -v并得到了ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]。有区别吗? -
补丁 (p173) 版本可能会有所不同,但我怀疑这是这里的问题。检查服务器上安装的 Ruby 版本,以及是否有两个或多个具有不同补丁版本的 2.2.3。当你在服务器上运行
gem list时,你看到bundler了吗?这也可能是一个 RVM gemset 问题,我建议通过不使用 RVM 而使用 rbenv 来解决这个问题:)
标签: ruby-on-rails ruby git amazon-web-services deployment