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

Use POSTGRES_* and REDIS_URL as fallback #4811

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

foarsitter
Copy link
Collaborator

This PR extends the base configuration in two ways:

  1. When DATABASE_URL is missing it is using POSTGRES_* variables for configuring the database.
  2. CELERY_BROKER_URL defaults to REDIS_URL

When using #4810 the POSTGRES_* and REDIS_URL variables are present but I'm not using the entrypoint script. This modification gives the possibility to run without entrypoint and without further modifications by using the variables already present.

@foarsitter foarsitter changed the title Config postgres celery vars Use POSTGRES_* and REDIS_URL as fallback Jan 27, 2024
@foarsitter foarsitter force-pushed the config_postgres_celery_vars branch 2 times, most recently from 0ae5d90 to 9c70d0a Compare January 27, 2024 11:39
@foarsitter foarsitter closed this Feb 7, 2024
@foarsitter foarsitter deleted the config_postgres_celery_vars branch February 7, 2024 19:05
@foarsitter foarsitter restored the config_postgres_celery_vars branch February 7, 2024 19:05
@foarsitter foarsitter reopened this Feb 7, 2024
Copy link
Member

@browniebroke browniebroke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the issue about hybrid dev, I'd like to ask a few questions, in the hope that we can maybe achieve the same outcome, without the try/except:

  1. Why is it easier to set 5 env variables (POSTGRES_...) than 1 (DATABASE_URL) in your hybrid dev mode (without Docker)?
  2. The POSTGRES_... vars are set in Docker, so do we actually need the DATABASE_URL?
  3. Could we instead replace the entrypoint script by an off-the-shelf solution as suggested in Why prefer python than bash for wait the service start #4539?

Then perhaps we could always use the POSTGRES_... variables instead?

Comment on lines +58 to +68
except environ.ImproperlyConfigured:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": env.str("POSTGRES_DB"),
"USER": env.str("POSTGRES_USER"),
"PASSWORD": env.str("POSTGRES_PASSWORD"),
"HOST": env.str("POSTGRES_HOST"),
"PORT": env.str("POSTGRES_PORT"),
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of this except 🤔 I can't quite really put a finger on why, though (sorry, that's unhelpful)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's because in case of problems, it becomes harder to figure out where the DB credentials are coming from. Do I have a DATABASE_URL set? Do I have anything missing from the required POSTGRES_... env?

Sure, it's only one more place to check, but it can be really confusing when your app won't conect to the DB

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relaying on exceptions here is a lazy way of doing things I suppose. When a faulty url is given it would try to use the postgres vars, so I agree on your reluctance and it should be improved.

Comment on lines +300 to +303
try:
CELERY_BROKER_URL = env("CELERY_BROKER_URL")
except environ.ImproperlyConfigured:
CELERY_BROKER_URL = env("REDIS_URL")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I look at this, I wonder why we need CELERY_BROKER_URL in the first place 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a project, in the time that Heroku had free redis instances, I used a three instances: a cache backend, celery broker and result backend. But yeah, we can get rid of it since it doesn't add any value.

@foarsitter
Copy link
Collaborator Author

  1. Why is it easier to set 5 env variables (POSTGRES_...) than 1 (DATABASE_URL) in your hybrid dev mode (without Docker)?

When I'm talking about hybrid I' talking about a local interpreter with docker services. In a non docker setup It wouldn't matter to me to set 5 or just 1 composed out of 5.

  1. The POSTGRES_... vars are set in Docker, so do we actually need the DATABASE_URL?

DATABASE_URL is there for deploys on heroku I suppose.

  1. Could we instead replace the entrypoint script by an off-the-shelf solution as suggested in Why prefer python than bash for wait the service start #4539?

If we get rid of CELERY_BROKER_URL then we can replace the entrypoint script. DATABASE_URL isn't required for the docker setup

Then perhaps we could always use the POSTGRES_... variables instead?

We can put DATABASE_URL around an statement that checks for use_heroku.

Sweet, I like where we are going!

@foarsitter
Copy link
Collaborator Author

docs/conf.py relies also on DATABASE_URL. Is it an idea to create a custom settings file config.settings.docs? Simpyfies docs/conf.py significant.

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

Successfully merging this pull request may close these issues.

None yet

2 participants