I want to instruct Capistrano to load environment variables that are defined on remote server. How can I do that?
我想指示Capistrano加载在远程服务器上定义的环境变量。我怎样才能做到这一点?
It seems that when I export my environment variables inside .bashrc
file, they are not taken into account by Capistrano. Capistrano seems to be executing a /usr/bin/env
to create the environment for executing remote commands, but this does not seem to be loading the environment variables from .bashrc
.
似乎当我在.bashrc文件中导出我的环境变量时,Capistrano不会考虑它们。 Capistrano似乎正在执行/ usr / bin / env来创建执行远程命令的环境,但这似乎并没有从.bashrc加载环境变量。
Let me tell you also that I am using rvm-capistrano
too (just in case it might help).
我也告诉你,我也在使用rvm-capistrano(以防它可能有所帮助)。
Any clue?
任何线索?
4 个解决方案
#1
26
Although this question is over six months old now, I'll leave this here in case anyone is facing this same problem.
虽然这个问题已经超过六个月了,但我会留在这里以防万一有人面临同样的问题。
Capistrano actually does load .bashrc
. But near the top of the file you will find:
Capistrano实际上加载了.bashrc。但是在文件顶部附近你会发现:
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
If you do any export
ing after that line, it will not be reached by Capistrano. The solution was simply to put my setup above this and Capistrano works how I want.
如果您在该行之后进行任何导出,Capistrano将无法访问。解决方案只是将我的设置置于此之上,而Capistrano就是我想要的。
This solution was also noted at this GitHub issue.
在这个GitHub问题上也注意到了这个解决方案。
#2
0
Capistrano doesn't load .bashrc
since it's not interactive shell. As far as I remember though it does load .bash_profile
though so you will probably have better luck using that.
Capistrano不加载.bashrc,因为它不是交互式shell。据我记得虽然它确实加载了.bash_profile但是你可能会有更好的运气使用它。
#3
0
You can pass your current environment variables to a remote execution with ssh by issuing:
您可以通过发出以下命令将当前环境变量传递给使用ssh的远程执行:
env | ssh user@host remote_program
Also taken the example from here
也从这里举了例子
on roles(:app), in: :sequence, wait: 5 do
within "/opt/sites/example.com" do
# commands in this block execute in the
# directory: /opt/sites/example.com
as :deploy do
# commands in this block execute as the "deploy" user.
with rails_env: :production do
# commands in this block execute with the environment
# variable RAILS_ENV=production
rake "assets:precompile"
runner "S3::Sync.notify"
end
end
end
end
looks like you can use with
set environment variables for your execution. So read your current environment variables and set them using with
.
看起来你可以使用set环境变量来执行。因此,请阅读当前的环境变量并使用with进行设置。
#4
-1
In Capistrano 3 it's set :default_env, { ... }
在Capistrano 3中设置:default_env,{...}
Like here:
像这儿:
set :default_environment, {
'env_var1' => 'value1',
'env_var2' => 'value2'
}
You can refer to this: Previous post..
你可以参考这个:上一篇文章..
#1
26
Although this question is over six months old now, I'll leave this here in case anyone is facing this same problem.
虽然这个问题已经超过六个月了,但我会留在这里以防万一有人面临同样的问题。
Capistrano actually does load .bashrc
. But near the top of the file you will find:
Capistrano实际上加载了.bashrc。但是在文件顶部附近你会发现:
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
If you do any export
ing after that line, it will not be reached by Capistrano. The solution was simply to put my setup above this and Capistrano works how I want.
如果您在该行之后进行任何导出,Capistrano将无法访问。解决方案只是将我的设置置于此之上,而Capistrano就是我想要的。
This solution was also noted at this GitHub issue.
在这个GitHub问题上也注意到了这个解决方案。
#2
0
Capistrano doesn't load .bashrc
since it's not interactive shell. As far as I remember though it does load .bash_profile
though so you will probably have better luck using that.
Capistrano不加载.bashrc,因为它不是交互式shell。据我记得虽然它确实加载了.bash_profile但是你可能会有更好的运气使用它。
#3
0
You can pass your current environment variables to a remote execution with ssh by issuing:
您可以通过发出以下命令将当前环境变量传递给使用ssh的远程执行:
env | ssh user@host remote_program
Also taken the example from here
也从这里举了例子
on roles(:app), in: :sequence, wait: 5 do
within "/opt/sites/example.com" do
# commands in this block execute in the
# directory: /opt/sites/example.com
as :deploy do
# commands in this block execute as the "deploy" user.
with rails_env: :production do
# commands in this block execute with the environment
# variable RAILS_ENV=production
rake "assets:precompile"
runner "S3::Sync.notify"
end
end
end
end
looks like you can use with
set environment variables for your execution. So read your current environment variables and set them using with
.
看起来你可以使用set环境变量来执行。因此,请阅读当前的环境变量并使用with进行设置。
#4
-1
In Capistrano 3 it's set :default_env, { ... }
在Capistrano 3中设置:default_env,{...}
Like here:
像这儿:
set :default_environment, {
'env_var1' => 'value1',
'env_var2' => 'value2'
}
You can refer to this: Previous post..
你可以参考这个:上一篇文章..