我想指示Capistrano加载在远程服务器上定义的环境变量。我该怎么做呢?
似乎当我在.bashrc文件中导出我的环境变量时,Capistrano没有考虑到它们。.bashrc似乎正在执行一个/usr/bin/env来创建执行远程命令的环境,但这似乎并没有从Capistrano加载环境变量。
我还要告诉你,我也在使用rvm-capistrano (以防万一它可能会有帮助)。
有什么线索吗?
发布于 2015-03-30 19:04:37
Capistrano实际上加载了.bashrc。但在文件的顶部附近,您会发现以下行之一:
# If not running interactively, don't do anything
[ -z "$PS1" ] && return# If not running interactively, don't do anything
[[ $- != *i* ]] && return# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac如果您在上述代码行之后执行任何export操作,Capistrano将无法访问它。解决方案很简单,就是将我的设置移到这条线上-- Capistrano按照我想要的方式工作。
在this GitHub issue上也提到了这个解决方案。
发布于 2014-08-26 22:20:02
您可以使用ssh将当前环境变量传递给远程执行,方法是执行以下命令:
env | ssh user@host remote_program我也参考了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看起来您可以使用with set环境变量来执行。因此,读取当前的环境变量并使用with设置它们。
发布于 2014-08-25 15:59:04
Capistrano不会加载.bashrc,因为它不是交互式外壳。但据我所知,它确实加载了.bash_profile,所以你使用它可能会更幸运。
https://stackoverflow.com/questions/25479348
复制相似问题