Add ability to set settings from environment variables

Bug #1399585 reported by Guilhem Lettron
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack Dashboard (Horizon)
Won't Fix
Undecided
Unassigned

Bug Description

To ease deployment and configuration, we want to being able to use environment variables as settings from horizon django app.

A use case can be, for example, to set `SECRET_KEY` in a uwsgi configuration file provisioned by chef/puppet...

With env variables, cfg software doesn't have to know very much about horizon (and its update) and can add specific settings.

Another use case is for packaging to set STATIC_ROOT (and push files in there own package) without having to change a file.

description: updated
Changed in horizon:
assignee: nobody → Guilhem Lettron (guilhem-fr)
status: New → In Progress
Revision history for this message
Timur Sufiev (tsufiev-x) wrote :

The solution is the same as in bug 1399580: just pull values out of environment variables in your local_settings - then it will be imported into settings.py.

Matthias Runge (mrunge)
Changed in horizon:
status: In Progress → Invalid
Revision history for this message
Guilhem Lettron (guilhem-fr) wrote :

Are you just reading what people put in description???

I put many use case when `local_settings` is invalid and can't be used.

As a devops, I pushed this solution on many proprietary Django software with huge success.

Maybe my solution with `exec(` is bad and I have to work on it, but this feature is really useful and doesn't concern local_settings.

You may want me to explain more why local_settings is invalid, but please don't close ticket so quickly!

Revision history for this message
Timur Sufiev (tsufiev-x) wrote :

Guilhem, both cases you mentioned (overriding SECRET_KEY and STATIC_ROOT) could be easily overridden in openstack_dashboard.local.local_settings which is usually symlinked from /etc/openstack-dashboard/local_settings. Please refer to the docs at http://docs.openstack.org/developer/horizon/topics/customizing.html - Horizon Dashboard is quite customizable out of the box.

Revision history for this message
Guilhem Lettron (guilhem-fr) wrote :

I'm aware of this use case. And in fact we was using it before.

But there is MANY bad sides:
* You have to maintain this symlink... what can be really difficult (you are linking a configuration to a software change)
* local_settings is python, not a configuration file, so it's harder to create it from a (ruby) cfgmgmt software.
* if you want to separate static file at packaging moment (to do a "horizon" and a "horizon-static" package), changing local_setting with bash is hard.

I can give you code example in bash, debian packaging, chef, uwsgi conf to convince you why this is useful. :)

Moreover, my patch doesn't change anything for someone who are using local_settings.
Adding configuration from env with a prefix is really a common modern pattern.

Revision history for this message
Timur Sufiev (tsufiev-x) wrote :

Well, you might be interested with this one: https://review.openstack.org/#/c/100521/

Revision history for this message
Guilhem Lettron (guilhem-fr) wrote :

it's related of course.... but it doesn't help on packaging side.

And my patch is only ~5 lines... not changing all configuration stuff.
It's like using a hammer to kill a fly

Changed in horizon:
status: Invalid → In Progress
Revision history for this message
Radomir Dopieralski (deshipu) wrote :

If you set a custom DJANGO_SETTINGS_MODULE, you can have your own module that then imports from any number of other files, managed by puppet or generated otherwise.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on horizon (master)

Change abandoned by David Lyle (<email address hidden>) on branch: master
Review: https://review.openstack.org/139112
Reason: This review is > 4 weeks without comment and currently blocked by a core reviewer with a -2. We are abandoning this for now. Feel free to reactivate the review by pressing the restore button and contacting the reviewer with the -2 on this review to ensure you address their concerns.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (master)

Fix proposed to branch: master
Review: https://review.openstack.org/201270

Changed in horizon:
assignee: Guilhem Lettron (guilhem-fr) → David Lyle (david-lyle)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (master)

Reviewed: https://review.openstack.org/201270
Committed: https://git.openstack.org/cgit/openstack/horizon/commit/?id=f341decaebacbb29ed2fc75dc72ee673dca2133a
Submitter: Jenkins
Branch: master

commit f341decaebacbb29ed2fc75dc72ee673dca2133a
Author: David Lyle <email address hidden>
Date: Mon Jul 13 11:40:32 2015 -0600

    Allow STATIC_ROOT override

    STATIC_ROOT is a file system location. It does not need to be tied
    to WEBROOT.

    Change-Id: I4935c5d8bd883cb5f091af22582e942f13aa5100
    Partial-Bug: #1399585

tags: added: kilo-backport-potential
Revision history for this message
Andrew Balfour (andrew-balfour) wrote :

Added the kilo-backport-potential tag as overriding STATIC_URL in local_settings worked fine in Juno, but was broken in Kilo by the "Fixing changing WEBROOT from / " changeset [1]

The fix for this bug would make it work again in Kilo as well.

[1] - https://github.com/openstack/horizon/commit/18dddd97da19af894a0974e3560197036ea8969a

Revision history for this message
Gary W. Smith (gary-w-smith) wrote :

Un-assigning as there has been no progress on this in a couple years.

Changed in horizon:
assignee: David Lyle (david-lyle) → nobody
Revision history for this message
Akihiro Motoki (amotoki) wrote :

This can be done by using your own (local_)settings file.
Other OpenStack projects do not support configuration via environment variables.

In addition, we are exploring to support configuration through oslo-config style.
I believe the motivation of this bug report can be addressed by this effort.

Changed in horizon:
status: In Progress → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.