-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
P.O.C: Manage Django Settings with Dynaconf #15702
Draft
rochacbruno
wants to merge
1
commit into
ansible:devel
Choose a base branch
from
rochacbruno:dynaconf
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+310
−243
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,42 @@ | ||
# Copyright (c) 2015 Ansible, Inc. | ||
# All Rights Reserved. | ||
from ansible_base.lib.dynamic_config import factory, export | ||
from .application_name import get_application_name | ||
from dynaconf import Validator | ||
|
||
|
||
def set_application_name(settings): | ||
data = {"dynaconf_merge": True} | ||
if settings.get("DATABASES") and settings.DATABASES.get("default"): | ||
if "sqlite3" not in settings.DATABASES.default.ENGINE: | ||
data["DATABASES__default__OPTIONS__application_name"] = get_application_name(settings.CLUSTER_HOST_ID) | ||
return data | ||
|
||
|
||
DYNACONF = factory( | ||
"AWX", | ||
environments=("development", "production", "quiet", "kube"), | ||
settings_files=["defaults.py"], | ||
) | ||
DYNACONF.validators.register(Validator("FOO", required=True)) | ||
|
||
# Store snapshot before loading any custom config file | ||
if DYNACONF.current_env == "development": | ||
DYNACONF.set("DEFAULTS_SNAPSHOT", DYNACONF.as_dict(internal=False)) | ||
|
||
# Load extra config | ||
DYNACONF.load_file("/etc/tower/settings.py") | ||
DYNACONF.load_file("/etc/tower/conf.d/*.py") | ||
if DYNACONF.get_environ("AWX_KUBE_DEVEL"): | ||
DYNACONF.load_file("kube_defaults.py") | ||
else: | ||
DYNACONF.load_file("local_*.py") | ||
|
||
# This must run after all custom settings are imported | ||
DYNACONF.update(set_application_name(DYNACONF)) | ||
|
||
# Update django.conf.settings with DYNACONF keys. | ||
export(DYNACONF) | ||
|
||
# Validate the settings according to the validators registered | ||
DYNACONF.validators.validate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,8 @@ | ||
# Copyright (c) 2015 Ansible, Inc. | ||
# All Rights Reserved. | ||
|
||
# Development settings for AWX project. | ||
|
||
# Python | ||
import os | ||
import socket | ||
import copy | ||
import sys | ||
import traceback | ||
|
||
# Centos-7 doesn't include the svg mime type | ||
# /usr/lib64/python/mimetypes.py | ||
import mimetypes | ||
|
||
# Django Split Settings | ||
from split_settings.tools import optional, include | ||
|
||
# Load default settings. | ||
from .defaults import * # NOQA | ||
|
||
# awx-manage shell_plus --notebook | ||
NOTEBOOK_ARGUMENTS = ['--NotebookApp.token=', '--ip', '0.0.0.0', '--port', '9888', '--allow-root', '--no-browser'] | ||
|
||
# print SQL queries in shell_plus | ||
SHELL_PLUS_PRINT_SQL = False | ||
|
||
# show colored logs in the dev environment | ||
# to disable this, set `COLOR_LOGS = False` in awx/settings/local_settings.py | ||
COLOR_LOGS = True | ||
LOGGING['handlers']['console']['()'] = 'awx.main.utils.handlers.ColorHandler' # noqa | ||
|
||
ALLOWED_HOSTS = ['*'] | ||
|
||
mimetypes.add_type("image/svg+xml", ".svg", True) | ||
mimetypes.add_type("image/svg+xml", ".svgz", True) | ||
|
||
# Disallow sending session cookies over insecure connections | ||
SESSION_COOKIE_SECURE = False | ||
|
||
# Disallow sending csrf cookies over insecure connections | ||
CSRF_COOKIE_SECURE = False | ||
|
||
# Disable Pendo on the UI for development/test. | ||
# Note: This setting may be overridden by database settings. | ||
PENDO_TRACKING_STATE = "off" | ||
INSIGHTS_TRACKING_STATE = False | ||
|
||
# debug toolbar and swagger assume that requirements/requirements_dev.txt are installed | ||
|
||
INSTALLED_APPS += ['drf_yasg', 'debug_toolbar'] # NOQA | ||
|
||
MIDDLEWARE = ['debug_toolbar.middleware.DebugToolbarMiddleware'] + MIDDLEWARE # NOQA | ||
|
||
DEBUG_TOOLBAR_CONFIG = {'ENABLE_STACKTRACES': True} | ||
|
||
# Configure a default UUID for development only. | ||
SYSTEM_UUID = '00000000-0000-0000-0000-000000000000' | ||
INSTALL_UUID = '00000000-0000-0000-0000-000000000000' | ||
|
||
# Ansible base virtualenv paths and enablement | ||
# only used for deprecated fields and management commands for them | ||
BASE_VENV_PATH = os.path.realpath("/var/lib/awx/venv") | ||
|
||
CLUSTER_HOST_ID = socket.gethostname() | ||
|
||
AWX_CALLBACK_PROFILE = True | ||
|
||
# ======================!!!!!!! FOR DEVELOPMENT ONLY !!!!!!!================================= | ||
# Disable normal scheduled/triggered task managers (DependencyManager, TaskManager, WorkflowManager). | ||
# Allows user to trigger task managers directly for debugging and profiling purposes. | ||
# Only works in combination with settings.SETTINGS_MODULE == 'awx.settings.development' | ||
AWX_DISABLE_TASK_MANAGERS = False | ||
|
||
# Needed for launching runserver in debug mode | ||
# ======================!!!!!!! FOR DEVELOPMENT ONLY !!!!!!!================================= | ||
|
||
# Store a snapshot of default settings at this point before loading any | ||
# customizable config files. | ||
this_module = sys.modules[__name__] | ||
local_vars = dir(this_module) | ||
DEFAULTS_SNAPSHOT = {} # define after we save local_vars so we do not snapshot the snapshot | ||
for setting in local_vars: | ||
if setting.isupper(): | ||
DEFAULTS_SNAPSHOT[setting] = copy.deepcopy(getattr(this_module, setting)) | ||
|
||
del local_vars # avoid temporary variables from showing up in dir(settings) | ||
del this_module | ||
# | ||
############################################################################################### | ||
# | ||
# Any settings defined after this point will be marked as as a read_only database setting | ||
# | ||
################################################################################################ | ||
|
||
# If there is an `/etc/tower/settings.py`, include it. | ||
# If there is a `/etc/tower/conf.d/*.py`, include them. | ||
include(optional('/etc/tower/settings.py'), scope=locals()) | ||
include(optional('/etc/tower/conf.d/*.py'), scope=locals()) | ||
|
||
# If any local_*.py files are present in awx/settings/, use them to override | ||
# default settings for development. If not present, we can still run using | ||
# only the defaults. | ||
# this needs to stay at the bottom of this file | ||
try: | ||
if os.getenv('AWX_KUBE_DEVEL', False): | ||
include(optional('development_kube.py'), scope=locals()) | ||
else: | ||
include(optional('local_*.py'), scope=locals()) | ||
except ImportError: | ||
traceback.print_exc() | ||
sys.exit(1) | ||
|
||
# The below runs AFTER all of the custom settings are imported | ||
# because conf.d files will define DATABASES and this should modify that | ||
from .application_name import set_application_name | ||
|
||
set_application_name(DATABASES, CLUSTER_HOST_ID) # NOQA | ||
|
||
del set_application_name | ||
# This file exists for backwards compatibility only | ||
# the current way of running AWX is to point settings to | ||
# awx/settings/__init__.py as the entry point for the settings | ||
# that is done by exporting: export DJANGO_SETTINGS_MODULE=awx.settings | ||
from ansible_base.lib.dynamic_config import export | ||
from . import DYNACONF # noqa | ||
|
||
export(DYNACONF) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# Copyright (c) 2015 Ansible, Inc. | ||
# All Rights Reserved. | ||
|
||
# Development settings for AWX project. | ||
|
||
# Python | ||
import os | ||
import socket | ||
import copy | ||
import sys | ||
import traceback | ||
|
||
# Centos-7 doesn't include the svg mime type | ||
# /usr/lib64/python/mimetypes.py | ||
import mimetypes | ||
|
||
# Django Split Settings | ||
# from split_settings.tools import optional, include | ||
|
||
# Load default settings. | ||
# from .defaults import * # NOQA | ||
# from awx.settings.main import settings | ||
|
||
|
||
# awx-manage shell_plus --notebook | ||
NOTEBOOK_ARGUMENTS = ['--NotebookApp.token=', '--ip', '0.0.0.0', '--port', '9888', '--allow-root', '--no-browser'] | ||
|
||
# print SQL queries in shell_plus | ||
SHELL_PLUS_PRINT_SQL = False | ||
|
||
# show colored logs in the dev environment | ||
# to disable this, set `COLOR_LOGS = False` in awx/settings/local_settings.py | ||
COLOR_LOGS = True | ||
# LOGGING['handlers']['console']['()'] = 'awx.main.utils.handlers.ColorHandler' # noqa | ||
|
||
ALLOWED_HOSTS = ['*'] | ||
|
||
mimetypes.add_type("image/svg+xml", ".svg", True) | ||
mimetypes.add_type("image/svg+xml", ".svgz", True) | ||
|
||
# Disallow sending session cookies over insecure connections | ||
SESSION_COOKIE_SECURE = False | ||
|
||
# Disallow sending csrf cookies over insecure connections | ||
CSRF_COOKIE_SECURE = False | ||
|
||
# Disable Pendo on the UI for development/test. | ||
# Note: This setting may be overridden by database settings. | ||
PENDO_TRACKING_STATE = "off" | ||
INSIGHTS_TRACKING_STATE = False | ||
|
||
# debug toolbar and swagger assume that requirements/requirements_dev.txt are installed | ||
|
||
# INSTALLED_APPS = settings.INSTALLED_APPS + ['drf_yasg', 'debug_toolbar'] # NOQA | ||
INSTALLED_APPS = "@merge drf_yasg,debug_toolbar" | ||
|
||
# settings.MIDDLEWARE = ['debug_toolbar.middleware.DebugToolbarMiddleware'] + settings.MIDDLEWARE # NOQA | ||
# settings.MIDDLEWARE.insert(0, 'debug_toolbar.middleware.DebugToolbarMiddleware') | ||
# MIDDLEWARE = "@insert debug_toolbar.middleware.DebugToolbarMiddleware" | ||
|
||
DEBUG_TOOLBAR_CONFIG = {'ENABLE_STACKTRACES': True} | ||
|
||
# Configure a default UUID for development only. | ||
SYSTEM_UUID = '00000000-0000-0000-0000-000000000000' | ||
INSTALL_UUID = '00000000-0000-0000-0000-000000000000' | ||
|
||
# Ansible base virtualenv paths and enablement | ||
# only used for deprecated fields and management commands for them | ||
BASE_VENV_PATH = os.path.realpath("/var/lib/awx/venv") | ||
|
||
CLUSTER_HOST_ID = socket.gethostname() | ||
|
||
AWX_CALLBACK_PROFILE = True | ||
|
||
# ======================!!!!!!! FOR DEVELOPMENT ONLY !!!!!!!================================= | ||
# Disable normal scheduled/triggered task managers (DependencyManager, TaskManager, WorkflowManager). | ||
# Allows user to trigger task managers directly for debugging and profiling purposes. | ||
# Only works in combination with settings.SETTINGS_MODULE == 'awx.settings.development' | ||
AWX_DISABLE_TASK_MANAGERS = False | ||
|
||
# Needed for launching runserver in debug mode | ||
# ======================!!!!!!! FOR DEVELOPMENT ONLY !!!!!!!================================= | ||
|
||
# Store a snapshot of default settings at this point before loading any | ||
# customizable config files. | ||
# this_module = sys.modules[__name__] | ||
# local_vars = dir(this_module) | ||
# DEFAULTS_SNAPSHOT = {} # define after we save local_vars so we do not snapshot the snapshot | ||
# for setting in local_vars: | ||
# if setting.isupper(): | ||
# DEFAULTS_SNAPSHOT[setting] = copy.deepcopy(getattr(this_module, setting)) | ||
|
||
# del local_vars # avoid temporary variables from showing up in dir(settings) | ||
# del this_module | ||
# | ||
############################################################################################### | ||
# | ||
# Any settings defined after this point will be marked as as a read_only database setting | ||
# | ||
################################################################################################ | ||
|
||
# If there is an `/etc/tower/settings.py`, include it. | ||
# If there is a `/etc/tower/conf.d/*.py`, include them. | ||
# include(optional('/etc/tower/settings.py'), scope=locals()) | ||
# include(optional('/etc/tower/conf.d/*.py'), scope=locals()) | ||
|
||
# If any local_*.py files are present in awx/settings/, use them to override | ||
# default settings for development. If not present, we can still run using | ||
# only the defaults. | ||
# this needs to stay at the bottom of this file | ||
# try: | ||
# if os.getenv('AWX_KUBE_DEVEL', False): | ||
# include(optional('development_kube.py'), scope=locals()) | ||
# else: | ||
# include(optional('local_*.py'), scope=locals()) | ||
# except ImportError: | ||
# traceback.print_exc() | ||
# sys.exit(1) | ||
|
||
|
||
# The below runs AFTER all of the custom settings are imported | ||
# because conf.d files will define DATABASES and this should modify that | ||
# from .application_name import set_application_name | ||
|
||
# set_application_name(settings.DATABASES, CLUSTER_HOST_ID) # NOQA | ||
|
||
# del set_application_name | ||
|
||
# settings.populate_obj(sys.modules[__name__]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a replacement for the commented code here? Is it possible to obtain these behaviors (like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this replaced by something else now - to have development / production inherit all the settings from default, with defaults coming at lower precedence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/ansible/awx/pull/15702/files#diff-7c44e0fb5f02a0b7ba5fc1d0e6b57da7b35edf564011c78e45d356343b8595b6R16-R33