0

I have finished Michael Hartl tutorial and I'm trying to deploy it with https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-puma-and-nginx-on-ubuntu-14-04. Unfortunately I'm stuck with RAILS_ENV=production rake db:migrate because it's generating following error:

ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key

/home/me/simpleapp/config/initializers/carrier_wave.rb:3:in `block in <top (required)>'

/home/me/simpleapp/config/initializers/carrier_wave.rb:2:in `<top (required)>'

/home/me/simpleapp/config/environment.rb:5:in `<top (required)>

'

I have even copied those files 1:1 and still this error persists. Any idea how could I solve it? I really am tired with trying to fix it with different solutions from web. Thanks

edit: I am adding my carrier_wave file:

if Rails.env.production?
  CarrierWave.configure do |config|
    config.fog_credentials = {
      # Configuration for Amazon S3
      :provider              => 'AWS',
      :aws_access_key_id     => ENV['S3_ACCESS_KEY'],
      :aws_secret_access_key => ENV['S3_SECRET_KEY']
    }
    config.fog_directory     =  ENV['S3_BUCKET']
  end
end
Artur
  • 3
  • 3
  • 2
    You need to set your AWS environment variables in production. Probably your initializer (`carrier_wave.rb`) is expecting `ENV['aws_access_key_id']` and `ENV['aws_secret_access_key']` or something like that to be set in your production environment. – steve klein May 21 '15 at 19:12
  • at some stage I tried to set it everywhere -> I got advice to set it in secrets.yml. But it does not work :/ – Artur May 21 '15 at 19:17
  • Can you update your post with the first 10 lines of your carrier wave initializer? – steve klein May 21 '15 at 19:18
  • I have updated my first post. What I have tried: Adding these values straight into the file Adding values to secrets.yml Adding values to .bashrc – Artur May 21 '15 at 19:26
  • On your prod machine, try `printenv | grep 'S3'`. Do you see those three S3 environment variables (`S3_ACCESS_KEY`, `S3_SECRET_KEY`, `S3_BUCKET`)? – steve klein May 21 '15 at 19:29
  • artur@vps:~/simpleapp$ printenv | grep 'S3' gives me nothing – Artur May 21 '15 at 19:33
  • OK I just hit Post Answer on the answer I wrote, anticipating this. There are several ways to skin this cat but `dotenv` is pretty slick. As a stop gap, you can just set these variables locally on your prod server. – steve klein May 21 '15 at 19:35

1 Answers1

0

The root issue is that Carrier Wave is expecting your AWS environment variables to be populated but they are not set in your production environment.

I would recommend you look at something like the dotenv gem which can find here. Environment variable housekeeping in multiple environments can be a real pain so it helps to have a tool to facilitate. Dotenv (and others like it) provides more of a turn key approach to this.

Note that the recently introduced secrets.yml for Rails secret management is a nice step in the right direction, but still requires a bit of code/know how to utilize.

In any event, be very careful about how you manage any files with secrets. At a minimum, the file should be in your .gitignore so that you aren't potentially broadcasting your secrets.

steve klein
  • 2,566
  • 1
  • 14
  • 27
  • Ok. I think I got it now. I have to set .env file (env.production?) in root folder of app?. And then from there set all the keys. I added Dotenv::Railtie.load to config/application.rb. I'm reading their webpage and that's what's a little bit unclear to me. – Artur May 21 '15 at 19:48
  • Install the gem. Create `~/.env` (yes in the root folder) and set your environment variables there (e.g. S3_ACCESS_KEY=12ABC...). Restart Rails. You should still read the doc to understand how you can create separate `.env` files for each environment. – steve klein May 21 '15 at 19:53
  • Yes! I got it in the mean time! Thank you! It's pretty good lesson for me! – Artur May 21 '15 at 19:56