【发布时间】:2015-05-04 22:23:48
【问题描述】:
我正在尝试使用 Capistrano 3 在 EC2 实例上部署我的第一个 Rails 4 应用程序。我已经学习了几个关于如何在 Ubuntu 上使用 Nginx 和Passenger 设置 Web 服务器的教程。我还有一个用于 MySQL 数据库的 RDS 实例。但是当我尝试运行cap deploy 时,它在assets:precompile 阶段给我一个错误:
INFO [d5d05621] Running ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile as deploy@[EC2 PUBLIC IP]
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@[EC2 PUBLIC IP]: rake exit status: 1
rake stdout: Nothing written
rake stderr: rake aborted!
Mysql2::Error: Access denied for user 'root'@'[EC2 PRIVATE IP]' (using password: NO)
据我了解,它正在尝试使用来自开发环境的凭据连接到本地主机上的数据库。
这是我的database.yml 文件的样子:
development:
adapter: mysql2
encoding: utf8
pool: 5
socket: /tmp/mysql.sock
username: root
password:
database: Store_development
production:
adapter: mysql2
encoding: utf8
database: Store_production
username: <%= ENV['STORE_DATABASE_USERNAME'] %>
password: <%= ENV['STORE_DATABASE_PASSWORD'] %>
host: [RDS INSTANCE ENDPOINT]
port: 3306
pool: 5
timeout: 5000
我到处寻找可以指定环境的所有地方,最后我得到了这样的东西。在我的deploy/production.rb 我有:
set :stage, :production
set :rails_env, :production
我的服务器上/etc/nginx/nginx.conf 的http 部分也有这个:
passenger_app_env production;
这在/etc/nginx/sites-available的虚拟主机配置中
passenger_enabled on;
rails_env production;
最后我在部署用户的.bashrc 中有这个:
export RAILS_ENV=production
我是否缺少使部署适用于生产环境并使用 database.yml 文件中的凭据连接到 RDS 实例的东西?还是别的什么?
【问题讨论】:
标签: ruby-on-rails nginx capistrano passenger capistrano3