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

Modify db docker service to use the env file #437

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

Conversation

del9ra
Copy link
Member

@del9ra del9ra commented Nov 14, 2024

Fixes #309

What changes did you make?

  • moved the environment variables from docker-compose.yml file to .env.docker-example
  • replaced the environment section with env_file: - ./app/.env.docker-example in docker-compose.yml
  • change the django settings (settings.py) code to use the database variable names that the db container uses

Why did you make the changes (we will use this info to test)?

  • to update the db Docker container to use the same .env file as the web container, so we avoid hard-coding values in the docker-compose.yml file

@del9ra del9ra force-pushed the modify-db-docker-service-309 branch from 2cc0bd9 to 5e12156 Compare November 14, 2024 01:57
Copy link
Member

@fyliu fyliu left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

I slack messaged Ethan about the sqlite. I think we need to wait for his response to determine how to name the env variables. But, ultimately, we want to get rid of the docker-compose.yml variables like you did here.

Comment on lines 10 to 15
POSTGRES_ENGINE=django.db.backends.postgresql
POSTGRES_DATABASE=people_depot_dev
POSTGRES_USER=people_depot
POSTGRES_PASSWORD=people_depot
POSTGRES_HOST=db
POSTGRES_PORT=5432
Copy link
Member

Choose a reason for hiding this comment

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

I see there are other places with the "SQL_ENGINE" type of names. You should change them as well. They're commented out, but they're also examples for non-default cases.

This relates to what I said about whether or not changing the variable names make sense. I think if we're not going to run the backend with sqlite anymore, changing the name makes sense. If we want to continue making the backend work with sqlite, then maybe it doesn't make sense to change the variable names to have the "POSTGRES_" prefix. In that case, you can add the "POSTGRES-*" variables and do something like "SQL_USER=$POSTGRES_USER".

SQL_HOST=db
SQL_PORT=5432
POSTGRES_ENGINE=django.db.backends.postgresql
POSTGRES_DATABASE=people_depot_dev
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 the variable name is actually POSTGRES_DB, from the docker-compose.yml

@del9ra
Copy link
Member Author

del9ra commented Nov 15, 2024

  1. Almost done
  2. Blocker: I changed each SQL affix to POSTGRES under this section: # postgres settings for local development, but I didn’t change anything under # sqlite settings for local development since it’s for SQLite. I only changed the variable names, not the values.
    Do I need to replace the SQL prefix with POSTGRES in the .env.docker file as well?
  3. ETA - November 15

@del9ra del9ra requested a review from fyliu November 17, 2024 01:44
Copy link
Member

@fyliu fyliu left a comment

Choose a reason for hiding this comment

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

Sorry I wasn't more clear before. I was also not thinking clearly about the scope of this issue. We're just trying to remove the hardcoded lines in the compose file. Since the project had support for sqlite, we should just let it keep doing that and add a workaround to do both. I wrote the details on what to do in the comments.

SQL_PASSWORD=people_depot
SQL_HOST=db
SQL_PORT=5432
POSTGRES_ENGINE=django.db.backends.postgresql
Copy link
Member

Choose a reason for hiding this comment

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

Since the compose file only used POSTGRES USER, PASSWORD, and DB, you should just modify those 3 variable names.

I was trying to decide the best way to do this, and thinking what if we removed sqlite support to use postgres variable names only. But that's not the goal of this issue, so we should leave the code in a state where sqlite should still work.

This means that we still need to have the SQL USER, PASSWORD, and DATABASE variables since it wouldn't make sense for the sqlite section to assign to variables like POSTGRES_USER. To work around this, we can add assignments in this format for the 3 changed variables:

SQL_USER=POSTGRES_USER
...

Now we're limiting the changes to the docker section of the file and can leave the rest alone.

Please revert the changes to the local development section. I didn't give you clear enough instructions before for that, and I wasn't thinking right in terms of what this issue should be about.

@@ -116,8 +116,8 @@

DATABASES = {
"default": {
"ENGINE": os.environ.get("SQL_ENGINE", "django.db.backends.sqlite3"),
"NAME": os.environ.get("SQL_DATABASE", BASE_DIR / "db.sqlite3"),
"ENGINE": os.environ.get("SQL_ENGINE", "django.db.backends.postgresql"),
Copy link
Member

Choose a reason for hiding this comment

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

Please revert the changes to this file. We don't really want to change the behavior of defaulting to sqlite.

Just a note to clarify how these lines work: Notice the first arguments to these os.environ.get functions correspond to the env variable names in the .env.docker.example file. Those would've needed to change to something like "POSTGRES_USER" if we were to switch everything to the postgres variable names. The 2nd arguments are the default values to return in case those variables are not present.

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

Successfully merging this pull request may close these issues.

Modify db docker service to use the env file
2 participants