我想部署我的第一次使用Capistrano 3的EC2實例上的第一次Rails 4應用程序。我已經遵循了幾個關於如何設置與Nginx的Web服務器的教程和Ubuntu上的乘客。我也有MySQL數據庫的RDS實例。但是,當我嘗試運行cap deploy
它給了我一個錯誤的assets:precompile
階段:Capistrano Rails部署與Nginx和乘客:數據庫憑據被忽略
INFO [d5d05621] Running ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile as [email protected][EC2 PUBLIC IP]
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as [email protected][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實例?或者是別的什麼?
是的,做'回聲$ STORE_DATABASE_USERNAME'打印預期值,同樣的事情密碼。我在'.bashrc'中添加了導出,並將它們設置爲虛擬主機配置中的'passenger_env_var STORE_DATABASE_USERNAME [password];'但錯誤仍然出現。 – Johann
是否將database.yml簽入repo中,或者在部署期間是否在服務器上有一個共享副本,它們被鏈接到當前目錄中?它幾乎聽起來像文件沒有符號鏈接或共享副本安裝不正確。 – infused
在開始我使用符號鏈接選項時,我在'shared/config'目錄中手動創建了'database.yml'文件。但是,我也嘗試沒有符號鏈接選項,它是一樣的。 'database.yml'被檢入到我的git倉庫中。 – Johann