Skip to content
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

Introduce a single source of truth for project domain name #1082

Open
webyneter opened this issue Mar 16, 2017 · 2 comments
Open

Introduce a single source of truth for project domain name #1082

webyneter opened this issue Mar 16, 2017 · 2 comments

Comments

@webyneter
Copy link
Collaborator

webyneter commented Mar 16, 2017

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, --

  • python files (including migrations),
  • templates,
  • shell scripts,

-- 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 through env_file setting in both dev.yml and docker-compose.yml like that:

env_file:
- common.env
- .env

(Elaborating on that even further, my other suggestion would be to contain 'orphan' variables scattered all around dev.yml in a separate dev.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 concatenate common.env and .env in an automatic manner (incorporating this functionality in, say, ./compose/django/create-env.sh, called upon in django service's command in docker-compose.yml before ./compose/django/gunicorn.sh is called should suffice).

To handle that, special treatment would be required for various kinds of files:

  • python files (migrations included):
import environ
env = environ.Env()
# reference the variable via env('DOMAIN_NAME')
  • templates: pass DOMAIN_NAME through the corresponding view's context;
  • shell scripts: so far, ./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 of nginx service-provided MY_DOMAIN_NAME variable is made, but referencing common.env in the nginx service's env_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.

@webyneter webyneter changed the title Introduce a single source of truth for project domain name [suggestion] Introduce a single source of truth for project domain name Mar 16, 2017
@webyneter webyneter changed the title [suggestion] Introduce a single source of truth for project domain name Introduce a single source of truth for project domain name Mar 16, 2017
@browniebroke
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants