简体   繁体   English

是否可以使用环境变量覆盖uwsgi ini-file

[英]Is it possible to override uwsgi ini-file with environment variables

I'm trying to build a "base" docker image for running a python framework with uwsgi. 我正在尝试构建一个“基础”docker镜像,用于运行带有uwsgi的python框架。 The goal is to have others build their own docker images where they dump their application logic and any configuration overrides they need. 目标是让其他人构建他们自己的docker镜像,在这里他们转储他们的应用程序逻辑和他们需要的任何配置覆盖。

I thought it might be nice to be able to override any default settings from a uwsgi.ini file by supplying UWSGI_* environment variables passed to uwsgi at startup. 我认为能够通过提供在启动时传递给UWSGI_*环境变量来覆盖uwsgi.ini文件中的任何默认设置可能会很好。

I've tried this approach, and setting a value via env var works if it's not in the ini-file at all (eg UWSGI_WORKERS=4 ). 我尝试过这种方法,并且如果它根本不在ini文件中(例如UWSGI_WORKERS=4 ),则通过env var设置一个值。 But if I put a workers=1 line in the ini-file, it seems to override the env var. 但是如果我在ini文件中放置一个workers=1行,它似乎会覆盖env var。

Is this expected behaviour? 这是预期的行为吗? I'm having trouble finding anything about config resolution order in the docs. 我无法在文档中找到有关配置解析顺序的任何内容。 Do I have to resort to something like this? 我必须诉诸这样的事吗? Using env vars seems so much cleaner. 使用env vars似乎更清洁。

if-exists = ./override.ini
include = %(_)
endif =

First, make all environment variables in the .ini file refer to the environment variables like below: 首先,使.ini文件中的所有环境变量引用如下的环境变量:

[uwsgi]
http = $(HTTP_PORT)
processes = $(UWSGI_WORKERS)
threads = $(UWSGI_THREADS)
...

Then set whatever default values you want for these environment variables inside the Dockerfile. 然后在Dockerfile中为这些环境变量设置所需的默认值。

Now, anyone using your base image can overwrite any config by setting the specific env variable. 现在,任何使用基本映像的人都可以通过设置特定的env变量来覆盖任何配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM