Rudi
Rudi

Reputation: 1587

environment variables with capistrano 3

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.

Upvotes: 4

Views: 1284

Answers (1)

Arctodus
Arctodus

Reputation: 5847

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.

Upvotes: 5

Related Questions