4

What is the best way to add environment variables with capistrano 3?

I've tried both

set :default_env, { 
  'MAILCHIMP' => 'verylongstring'
}

and

set :default_environment, { 
  'MAILCHIMP' => 'verylongstring',
}

but none seemed to do anything usefull.

Rudi
  • 1,577
  • 3
  • 16
  • 42

1 Answers1

5

We need to separate between environment variables that are being used when Capistrano are running its tasks (like deploying), and environment variables that Rails are using when running in production mode on the server.

If you need environment variables during a capistrano 3 session then I belive set :default_env is the way to go. (Im still on capistrano 2 myself, so Im not 100% sure).

If you need production mode specific settings and environment variables you probably want something independent of Capistrano, like Figaro or rails_config Why? Because there will likely be situations where Rails is being booted outside of capistrano. For instance, by a startup script running after a server reboot, a rails console session started on the server or a rake task running as a cron job on the server.

Arctodus
  • 5,743
  • 3
  • 32
  • 44
  • 1
    Thanks Sharagoz. The comment about starting the service without a Cap was a face palm moment. Appreciate the work and the comments, hence the award. That said, I'm satisfied with your answer but not with situation. I may be wrong, but I want secrets only in memory if I can. It seems most solutions require that if I want a remote deploy, I'll have to have secrets on disk. Granted, I can setup permissions, but what isn't there can be taken or broken into. I've heard about Figaro, but haven't looked at it. I'll keep looking for something simple, w/o another gem/dependency. Again, thanks. – codenoob Jun 21 '14 at 16:09