UWSGI configuration based on environment variable

Please help me understand the uWSGI configuration logic. I have an environment variable ENVIRONMENT. Let them say that its meanings can be either devor prod. I want to set configuration parameters based on valueENVIRONMENT

# always executes print statement, doesn't matter what ENVIRONMENT is set to
if-env= ENVIRONMENT
if-opt: %(_)=dev
print = RUNNING %(_)
endif:
endif =

# always executes print statement, doesn't matter what ENVIRONMENT is set to
running = ENVIRONMENT
if-opt: running=dev
print = RUNNING %(_)
endif:

I would suggest that if ENVIRONMENTset to prod, none of the assignments or printstatements inside the block if-optwill be executed. But this is not so.

+4
source share
1 answer

This should work:

[uwsgi]
if-env = ENVIRONMENT
env = %(_)
endif =
if-not-env = ENVIRONMENT
env = none
endif =
print = RUNNING %(env)
if-opt = env=dev
print = running dev yay
endif =

You used the YAML syntax in the INI configuration. I also had to take if-optout if-envbecause he complained about recursion. There may be a way to make it shorter, but it works.

+3
source

Source: https://habr.com/ru/post/1688662/


All Articles