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

2

15

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 =
Saskatchewan answered 13/11, 2018 at 14:30 Comment(1)
T
5

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.

Tennilletennis answered 19/11, 2018 at 12:47 Comment(1)
Thanks for your answer! Though you haven't actually answered my question, you've come up with an alternate solution. In order to receive the bounty, I expect the requirements to be fully met (see the bounty description above). I do appreciate that you've taken the time and energy to help me out though.Saskatchewan
A
0

I am not aware of a way to tell uWSGI to prioritize environment variables over the configuration file. If you do not have many values to override, a relatively compact workaround is:

workers = 1
if-env = UWSGI_WORKERS
workers = %(_)
endif =
Akel answered 17/10, 2023 at 8:1 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.