Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set environment variable on capistrano deploy?

In my rails app, i set response header from env:

response.headers['application-version'] = ENV["APPLICATION_VERSION"]

I try set env variable in capistrano deploy file, but this don't work.

set :default_environment, {
    'APPLICATION_VERSION' => Time.now.strftime('%Y%m%d%H%M%S%L')
}

How i set env variable on deploy?

like image 907
Kroid Avatar asked Oct 25 '25 15:10

Kroid


2 Answers

Setting default_environment (or default_env for Capistrano 3.x) will only set the variables during deploy commands. From the docs:

A hash that can be used to set environment variables that should be present for all commands that are executed.

If you want to set environment variables to be used by your rails server---which is another process, another vm instance, in another login session---you need to set the env variables for the session its being executed, e.g. via .bashrc, .profile, .zshrc or whatever shell you're using. You can also use some environment variable manager like direnv, rbenv-vars, etc.

Hope that helps.

like image 123
wicz Avatar answered Oct 28 '25 06:10

wicz


In one Rails app, I use Capistrano 3. I set my variables with default_env

set :default_env, {
  'APPLICATION_VERSION' => Time.now.strftime('%Y%m%d%H%M%S%L')
}

For another Rails app, I use Capistrano 2. There I use :default_environment to set variables.

like image 29
Bjoernsen Avatar answered Oct 28 '25 06:10

Bjoernsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!