Capistrano 和环境变量 [英] Capistrano and environment variables

查看:33
本文介绍了Capistrano 和环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经切换到使用 环境变量进行配置 并且效果很好 - 除非我必须部署或使用 capistrano 运行任务.

I've switched to using environment variables for configuration and it works very well - except when I have to deploy or run tasks with capistrano.

Capistrano 3 似乎会执行以 /usr/bin/env 为前缀的每个命令,这会清除我通过 .bashrc 设置的所有环境变量.

Capistrano 3 seems to execute each command prefixed with /usr/bin/env which erases any environment variables I've set through .bashrc.

编辑 - 在进行更多研究时,这可能不是问题,问题可能是因为 capistrano 作为非登录、非交互式 shell 执行并且不加载 .bashrc.bash_profile.不过还是卡住了.

EDIT - on doing some more reasearch, this might not be the issue, the issue might be because capistrano executes as a non-login, non-interactive shell and does not load .bashrc or .bash_profile. Still stuck, though.

在 capistrano 执行其任务时确保设置环境变量的最佳方法是什么?

What would be the best way of making sure the environment vars are set when capistrano executes its tasks?

推荐答案

你最好看看 ENVIRONMENT VARIABLESSHELL VARIABLES

You might be best looking at the difference between ENVIRONMENT VARIABLES and SHELL VARIABLES

当您启动 SSH 时,您的应用将加载在您的 .bashrc 文件中定义的 SHELL 变量.它们只存在于 shell 的生命周期中,因此,我们不像 ENV vars

When you fire SSH, your app will load the SHELL variables which are defined in your .bashrc file. These only exist for the life of the shell, and therefore, we don't use them as much as ENV vars

您最好将 ENV 变量放入:

You may be better putting the ENV vars in:

/etc/environment

像这样:

export ENVIRONMENT_VAR=value

这将使变量在整个系统中可用,而不仅仅是在不同的 shell 会话中

This will make the variables available throughout the system, not just in different shell sessions

更新

你试过了吗

Capistrano:我可以设置吗整个 cap 会话的环境变量?

set :default_env, { 
  'env_var1' => 'value1',
  'env_var2' => 'value2'
}

这篇关于Capistrano 和环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆