My stack is Puma + Nginx + PostgreSQL, on AWS EC2. I'm using Capistrano 3.4 to deploy a Rails 4.2.4 app. I've been stabbing in the dark trying to solve this for a while now so thought I'd see if I can get some help to shed some light on this issue. It's not conceptually difficult, I just don't know why what I've tried doesn't work.
Here's what the Capistrano output says:
...
DEBUG [f85d7a84] Command: cd /home/deploy/my_app/releases/20151210184710 && ( export RVM_BIN_PATH="~/.rvm/bin" aws_access_key_id="<MY_AWS_ACCESS_KEY_ID>" aws_secret_access_key="<MY_AWS_SECRET_ACCESS_KEY>" RAILS_ENV="production" ; ~/.rvm/bin/rvm default do bundle exec rake assets:precompile )
DEBUG [f85d7a84] RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
DEBUG [f85d7a84]
DEBUG [f85d7a84] you can ignore these warnings with 'rvm rvmrc warning ignore /home/deploy/my_app/releases/20151210184710/Gemfile'.
DEBUG [f85d7a84]
DEBUG [f85d7a84] To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.
DEBUG [f85d7a84]
DEBUG [f85d7a84]
DEBUG [f85d7a84]
DEBUG [f85d7a84] rake aborted!
DEBUG [f85d7a84]
DEBUG [f85d7a84] ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
...
Notice in the first line there has been some attempt in the Bash command to set the required arguments, but clearly they can't be accessed in the rake assets:precompile
. So my problem is how to set the 'required arguments' aws_access_key_id and aws_secret_access_key correctly.
What I've tried:
1) Setting them in config/deploy.rb (inspired by this)
To do this I used:
set :default_env, {
rvm_bin_path: '~/.rvm/bin',
'aws_access_key_id' => '<MY_AWS_ACCESS_KEY_ID>',
'aws_secret_access_key' => '<MY_AWS_SECRET_ACCESS_KEY>'
}
2) Setting them on my EC2 server in shared/secrets.yml: (Inspired by this)
aws_access_key_id: '<MY_AWS_ACCESS_KEY_ID>',
aws_secret_access_key: '<MY_AWS_SECRET_ACCESS_KEY>'
I linked to these in config/deploy.rb as
set :linked_files, %w{config/database.yml config/application.yml secrets.yml}
Currently this is how I'm trying to input the keys in config/initializers/carrierwave.rb:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
#:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'], # I still get the same error when I use these two lines instead
#:aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
:aws_access_key_id => Rails.application.secrets.aws_access_key_id,
:aws_secret_access_key => Rails.application.secrets.aws_secret_access_key
}
config.fog_directory = ENV['AWS_S3_BUCKET']
end
3) Setting them in config/application.yml (inspired by this) as
aws_access_key_id: "<MY_AWS_ACCESS_KEY_ID>"
aws_secret_access_key: "<MY_AWS_SECRET_ACCESS_KEY>"
So why aren't any of these methods working? I'm not very experienced at setting environment variables let alone on a remote server but I've seen threads/blog posts where each of these seem to work.
Thanks for your help everyone. Feel free to ask questions or for more info!