我正在尝试将我的ruby on rails 4项目部署到带有capistrano 3的服务器中,但是出现一些错误。
首先,当我这样做
cap production deploy:check
一切看起来都不错!但是当我这样做
cap production deploy
我有两个错误:
DEBUG [e3cf53e3] Running [ -L /var/www/myapp/releases/20131026111326/public/assets ] on mydomain.com
DEBUG [e3cf53e3] Command: [ -L /var/www/myapp/releases/20131026111326/public/assets ]
DEBUG [e3cf53e3] Finished in 0.104 seconds with exit status 1 (failed).
DEBUG [304388e5] Running [ -d /var/www/myapp/releases/20131026111326/public/assets ] on mydomain.com
DEBUG [304388e5] Command: [ -d /var/www/myapp/releases/20131026111326/public/assets ]
DEBUG [304388e5] Finished in 0.104 seconds with exit status 1 (failed).
我得到的最后一个错误是:
DEBUG [4e4c65ef] rake aborted!
DEBUG [4e4c65ef] Unknown database 'myapp_production'
所以我认为我应该做
cap production deploy:migrate
但是我遇到了另一个错误:当前目录不存在...
我很迷路。我的配置文件是这些:
production.rb
set :stage, :production
role :all, %w{myuser@mydomain.com}
server 'mydomain.com', user: 'myuser', roles: %w{web app db}
set :ssh_options, {
keys: %w(/path/mykey.pem),
forward_agent: true,
auth_methods: %w(publickey)
}
fetch(:default_env).merge!(rails_env: :production)
set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.0.0-p247'
set :rake, "rake"
set :rails_env, "production"
set :migrate_env, ""
set :migrate_target, :latest
Capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/rvm'
require 'capistrano/bundler'
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
我在Gemfile中使用capistrano-bundler,capistrano-rvm和capistrano-rails
非常感谢你。
最佳答案
Capistrano无法为您创建数据库,因为您尚未完成部署,所以永远不会创建current
符号链接。
您看到的错误是因为数据库服务器上不存在该数据库,它完全取决于您的服务器(PostgreSQL,mysql等),但是您需要进入数据库服务器并运行以下命令:
CREATE DATABASE myapp;
# Something else, too you'll need to GRANT permissions
# in the sql server for your production database user,
# or change the database ownership.
然后,您应该能够完成部署。