Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

uwsgi

I'm trying to build a "base" docker image for running a python framework with uwsgi. The goal is to have others build their own docker images where they dump their application logic and any configuration overrides they need.

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.

I've tried this approach, and setting a value via env var works if it's not in the ini-file at all (e.g UWSGI_WORKERS=4). But if I put a workers=1 line in the ini-file, it seems to override the 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.

if-exists = ./override.ini
include = %(_)
endif =
like image 308
Ulrik Avatar asked Nov 13 '18 14:11

Ulrik


People also ask

What is a uWSGI ini?

INI files are a de facto standard configuration format used by many applications. It consists of [section] s and key=value pairs. An example uWSGI INI configuration: [uwsgi] socket = /tmp/uwsgi.sock socket = 127.0.0.1:8000 workers = 3 master = true.

Which Python is uWSGI using?

It's possible to compile an uWSGI plugin using the official Python 3.7 package, and we will see how to do it step by step.

Where is uWSGI config?

Configuration. Web applications served by uWSGI are configured in /etc/uwsgi/ , where each of them requires its own configuration file (ini-style). Details can be found in the uWSGI documentation. Alternatively, you can run uWSGI in Emperor mode (configured in /etc/uwsgi/emperor.


1 Answers

First, make all environment variables in the .ini file refer to the environment variables like below:

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

Then set whatever default values you want for these environment variables inside the Dockerfile.

Now, anyone using your base image can overwrite any config by setting the specific env variable.

like image 96
amirathi Avatar answered Sep 23 '22 19:09

amirathi