Open webyneter opened 7 years ago
I think the situation has improved slightly with changes from #1801
We might be able to simplify this a bit further, but not by much: https://github.com/pydanny/cookiecutter-django/search?q=DOMAIN_NAME&unscoped_q=DOMAIN_NAME
What do you think @webyneter? Is it still an issue?
Here is where it's used at the moment:
Env file, which should be the source of truth:
In production settings, as default values. Actually uses the source of truth if set:
Traefik config (doesn't support environment variables it seems), little we can do IMO:
In one of our migrations:
This is the only one where we could improve things by using the value from the environment. Maybe we can use the setting to proxy the default value from the scaffoling?
As of now, project domain name is determined at the initial, scaffolding stage only, for it to then be hard-coded into numerous files, -- it might take quite some time to accurately update all the occurrences once required.
Since the domain name is used across multiple file types, --
-- introducing an environment variable representing the domain name might be the single feasible solution, IMO. As for the variable name, it might be
DOMAIN_NAME
.To ensure the variable is accessible project-wide, -- and, given the fact that
.env
file comprising other variables is for production use only, -- I suggest that we create a separate, say,common.env
file with the variable definition, referencing it throughenv_file
setting in bothdev.yml
anddocker-compose.yml
like that:(Elaborating on that even further, my other suggestion would be to contain 'orphan' variables scattered all around
dev.yml
in a separatedev.env
file which can be stored in VCS likewise the development-specific variables it defines are.) Yet, only a single.env
file must be available at production, so we'd need to concatenatecommon.env
and.env
in an automatic manner (incorporating this functionality in, say,./compose/django/create-env.sh
, called upon indjango
service'scommand
indocker-compose.yml
before./compose/django/gunicorn.sh
is called should suffice).To handle that, special treatment would be required for various kinds of files:
DOMAIN_NAME
through the corresponding view's context;./compose/nginx/start.sh
is the only place the domain name is utilized, and happily it's the only place where the problem is solved already (there, the use ofnginx
service-providedMY_DOMAIN_NAME
variable is made, but referencingcommon.env
in thenginx
service'senv_file
would be one further enhancement).I'm in huge appreciation of any critics and suggestions to follow; that would also be a pleasure for me to provide a PR ones we reach consensus on the issue.