我有一个环境变量DEBUG。它的值可以是 true 也可以是 false。我想根据它的值设置一些配置。
[uwsgi]
if-opt = $(DEBUG)=true
print = Inside if condition
endif =
Print 语句未执行。 DEBUG 在 kubernetes 部署中设置
- name: DEBUG
value: "true"
您的方法的问题是
if-opt
检查是否设置了给定的uWSGI选项,它不检查环境变量。
我不确定这是否是最好的方法,但一种解决方法是定义一个自定义选项,将环境变量加载到其中,然后使用
if-opt
:
declare-option = my-debug=false
if-env = DEBUG
my-debug = %(_)
endif =
if-opt = my-debug=true
print = Inside if condition
endif =
如果您可以使用空字符串/非空字符串值而不是使用真/假值,这可能会简单得多:
if-env = DEBUG
print = Inside if condition
endif =