Ask A Question

Notifications

You’re not receiving notifications from this thread.

Ruby issue when doing cap deploy production

Anthony Candaele asked in General

man this is hard, I put the environment variable S3_KEY and S3_SECRET in different files:

~/.bashrc
/etc/default/nginx
home/deploy/posplus/shared/config/secrets.yml

but none solved the problem, I'm stil getting this error message when I try to do 'cap production deploy':

DEBUG[ff424d92]     rake aborted!
DEBUG[ff424d92]     ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
DEBUG[ff424d92]     /home/deploy/posplus/shared/bundle/ruby/2.1.0/gems/fog-core-1.22.0/lib/fog/core/service.rb:237:in `validate_options'
Reply

Why don't you try hard coding the keys into secrets.yml just to get it working. It's not the most secure way but you will get yourself going, then you can worry about setting env vars.
Also, have you run source ~/.bashrc to reload bash and reading S3_KEY or S3_SECRET to see if it returns the key?
The following is link is pretty thorough on setting env vars:
https://www.digitalocean.com/community/tutorials/how-to-read-and-set-environmental-and-shell-variables-on-a-linux-vps

Reply

Hi James, thanks for the help,

I did put the hard coded keys in the secrets.yml file and also sourced the ~/.bashrc file. But it didn't solve the issue. Capistrano keeps giving me the error:

INFO[97d4f95a] Running ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile on 95.85.5.6
DEBUG[97d4f95a] Command: cd /home/deploy/posplus/releases/20140913135409 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2     RAILS_ENV=production ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )
DEBUG[97d4f95a]     rake aborted!
DEBUG[97d4f95a]     ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key

If this could clear things up, my config/initializers/carrier_wave.rb file looks like this:

CarrierWave.configure do |config|
  if Rails.env.staging? || Rails.env.production?
    config.storage = :fog
    config.fog_credentials = {
      :provider               => 'AWS',                        # required
      :aws_access_key_id      => ENV['S3_KEY'],                        # required
      :aws_secret_access_key  => ENV['S3_SECRET'],                        # required
    }
    config.fog_directory  = 'posplus'                     # required
  else
    config.storage = :file
    config.enable_processing = Rails.env.production?
  end
end

I always worked on Heroku, where I set the environment variables with the 'heroku set:config ....' command.

greetings,

Anthony

Reply

If you use secrets.yml, you don't access them through the ENV anymore. Instead you want to use Rails.application.secrets.key_name to retrieve your values.

Take a look here for a blog post on it: http://richonrails.com/articles/the-rails-4-1-secrets-yml-file

I'll also be sure to do a screencast on this topic because I think it's not documented too well. :)

Reply

Hi Chris, thanks, I wasn't aware of that and changed the carrier_wave.rb initializer:

CarrierWave.configure do |config|
  if Rails.env.staging? || Rails.env.production?
    config.storage = :fog
    config.fog_credentials = {
      :provider               => 'AWS',                        # required
      :aws_access_key_id      => Rails.application.secrets.S3_KEY,                        # required
      :aws_secret_access_key  => Rails.application.secrets.S3_SECRET,                        # required
    }
    config.fog_directory  = 'posplus'                     # required
  else
    config.storage = :file
    config.enable_processing = Rails.env.production?
  end
end

and my secrets.yml file looks like this:

production:
  S3_KEY: <%= ENV['S3_KEY'] %>
  S3_SECRET: <%= ENV['S3_SECRET'] %>

Then it also struck my that I working in a feature branch called 'capistrano' so I added

set :branch, 'capistrano'

to my config/deploy.rb file and I pushed the feature branch to a remote branch on Github

But I'm still getting the same error when doing 'cap production deploy':

DEBUG[e90c10e8] Command: cd /home/deploy/posplus/releases/20140914000558 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2     RAILS_ENV=production ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )
DEBUG[e90c10e8]     rake aborted!
DEBUG[e90c10e8]     ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
DEBUG[e90c10e8]     /home/deploy/posplus/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:237:in     `validate_options'

sigh : (

I don't know why Capistranno isn't picking up the changes. Right now I'm not sure if this could be related to the problems I had with the creation of a postgres user.

Maybe you guys are seeing things I don't see? My remote feature branch is at:

https://github.com/acandael/posplus-rails/tree/capistrano

greetings,

Anthony

Reply

Well, the point about using secrets.yml is that you don't need to put them in the ENV anymore. Just make sure the file is not in your repository.

Create secrets.yml on the server in the shared directory like you did with database.yml and then write your keys in it directly. Then add the file to your config/deploy.rb to make sure it gets symlinked on deploy.

After that, you can use those secrets without having to go through ENV. They did this so that you wouldn't have to deal with this annoying system configuration and you can manage it a lot easier!

Reply

Hi Chris, thanks a lot, adding the secrets.yml file to config/deploy.rb solved the issue : )

I'm still not there, as a couple of other challenges await me like dealing with these failure messages:

DEBUG[f06a4082] Finished in 0.081 seconds with exit status 1 (failed).
DEBUG[09ba02b5] Running /usr/bin/env [ -f /home/deploy/posplus/releases/20140914083548/config/database.yml ] on <my-ip>

I'm getting a couple of these error messages when deploying with Capistrano.

Also there seem to be some issues with assets:

    DEBUG[da33561d]     I, [2014-09-14T04:36:06.122787 #24469]  INFO -- : Writing           /home/deploy/posplus/releases/20140914083548/public/assets/belfort-081a4bbefd8f4ed5f27bbb624d48f379.png
   DEBUG[da33561d]  I, [2014-09-14T04:36:06.125691 #24469]  INFO -- : Writing     /home/deploy/posplus/releases/20140914083548/public/assets/jigsaw-puzzle-1c07a986767187bd9961fe69651705c8.jpg
   DEBUG[da33561d]  I, [2014-09-14T04:36:06.127459 #24469]  INFO -- : Writing /home/deploy/posplus/releases/20140914083548/public/assets/logo-posplus-72x61-c0cc65a8684ac8d9da5d402fcbc58c6e.png
   DEBUG[da33561d]  I, [2014-09-14T04:36:06.129307 #24469]  INFO -- : Writing /home/deploy/posplus/releases/20140914083548/public/assets/logo-posplus-a0276666c4cf6aaeb387a2580cdefc71.png
   DEBUG[da33561d]  I, [2014-09-14T04:36:06.139111 #24469]  INFO -- : Writing /home/deploy/posplus/releases/20140914083548/public/assets/member_placeholder-66af4d62c5dc83d72c054cf50caea6d5.png

But again I'm a step further in my quest to deploy a Rails app on a VPS

thanks for your patience,

Anthony

Reply

Hi Chris, James,

Just successfully deployed my Rails app on a Digital Ocean VPS ( a small step for mankind but a giant leap for a devops newbie):

http://95.85.5.6

thanks a lot for your help and patience,

greetings,

Anthony

Reply

Congrats Anthony!! :) After what seemed like a ton of issues, I'm glad you finally got it all running. I'm sure it will be way quicker next time!

Reply

This is awesome news! Getting that first one setup after debugging for what seems like endless amounts of time is a great feeling. Hopefully you learned quite a bit along the way.

Reply

@Chris, @James

The first deploy is a bit swimming in the ocean, lot's of new stuff, and not sure about what's going on. But I'm starting to feel more comfortable right now, and I'm glad I made the switch from Heroku to a Digital Ocean vps. The Rails Deploy Guide on GoRails was an awesome help, and I would recommend it to anybody having to deploy a Rails app for the first time.

Just a question (@Chris) about the the Rails Deploy Guide, is there a special reason that you use Passenger over Unicorn?

greetings, and again thanks a lot for your help!

Anthony

Reply

Mostly just because it's very simple and easy to get up and running. From some recent benchmarks I read, it also performs comparatively to Unicorn and some other solutions out there. Seemed to be a good mix of convenience to learn and performance.

Reply

ok, I like 'simple' : )

Reply

+1 on using Passenger over Unicorn. I've tried both but I prefer Passenger. Plus it's bundled natively with Nginx which is nice. Configuration takes 30 seconds and you're done. And Chris is right, benchmarks point out that it performs just as good as Unicorn. There is some tuning you can do to make it run even better. If you need some help let me know, I'm very familiar with Nginx/Passenger and use it on all my apps.

Reply

If ever any one comes up with an issue with activeadmin and it failing with : NameError: uninitialized constant ActiveAdmin
--- I added

require 'activeadmin'

--- to the top of the initializers/active_admin.rb file, not sure if this breaks anything else but that fixed an issue for me see post - https://github.com/activeadmin/activeadmin/issues/1992

I then ran into the javascript problem and installed nodes, as per Anthony's reply above and that worked and it seems to have finished the deployment with out any other issue.... about to restart everything and check it out....

Reply

So after my wishful thinking of everything running smoothly i've tried the command - RAILS_ENV=production bundle exec rake db:create under the /home/deploy/myapp/current folder (i changed the mayor to my app name ) but i got the error - PG::InsufficientPrivilege: ERROR: permission denied to create database

Any help on this would be great!

Reply

Gareth - It is probably because your Postgres user doesn't have create database rights. You may want to either fix permissions on the user you are connecting with, or login as the postgres user and create the db manually.

Reply

Hey Chris,

Yeah i've been googling it and came across a couple of resources, most say i should run the following command -

psql -U your_username postgres

psql postgres
ALTER ROLE that_username CREATEDB

but that didn't seem to work as i still get that error... I'm not entirely sure how to create a db manually as the postgres user.... i'll google it a bit.... so close i can smell the cogs on the server burning! haha

Reply

Hmm, not sure what's wrong exactly. Also you could just create the db after getting into the psql console by doing CREATE DATABASE your_database_name. Then you need to grant all privileges to that user on the new db.

Great reference for this stuff:
http://www.cyberciti.biz/faq/howto-add-postgresql-user-account/

Reply

ok i've followed that somewhat haha (i was actually looking at that same link before you sent it through)

so i did the following

template1=# CREATE USER deploy WITH PASSWORD 'somepassword' SUPERUSER;

then made my way over to - /home/deploy/myapp/current
and ran - RAILS_ENV=production bundle exec rake db:create

seems to have worked a treat... i'll finish off the rest of your tutorial, and fingers crossed no more errors! :)

Cheers again for all the help
Gareth

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.