chaynHQ / bloom-backend

Code for the backend / API of the Bloom service
https://bloom.chayn.co/
MIT License
19 stars 31 forks source link

Docker Compose doesn't load .env file and incorrect DATABASE_URL configuration #588

Open SureshPradhana opened 3 months ago

SureshPradhana commented 3 months ago

Overview:

There are two main issues in the current Docker setup:

  1. The .env file is not being loaded, causing missing environment variables during runtime.
  2. The DATABASE_URL uses host.docker.internal:35000, which leads to connection errors within the Docker network.

These issues prevent the backend service from properly connecting to the PostgreSQL database when using Docker Compose.

Environment:

Actions Needed:

Proposed Fix:

  1. Load .env file: Add the following to the api service in docker-compose.yml:

    env_file:
     - .env
  2. Correct DATABASE_URL: Update the DATABASE_URL in docker-compose.yml:

    DATABASE_URL=postgres://postgres:postgres@db:5432/bloom
SureshPradhana commented 3 months ago

Hi, can you confirm if the issue I reported is correct? If so, I'd like to work on it.

kyleecodes commented 2 months ago
  1. The .env file is not being loaded, causing missing environment variables during runtime.
  2. The DATABASE_URL uses host.docker.internal:35000, which leads to connection errors within the Docker network.

Hi @SureshPradhana, thank you for your suggestion, and patience while we were out of office. Can you share the exact connection errors you experienced? They might be specific to your set-up. But we aim to support all environments, so it's important we learn what is going on here.

As for loading env vars, I agree they should be mounted to the volume / loaded at runtime, as you demonstrated. Our current set-up isn't best practice, this would be more secure and flexible.

SureshPradhana commented 2 months ago

Hi @kyleecodes,

Thanks for the feedback. Here are the connection errors I faced:

i use linux found out that On Linux, host.docker.internal is not available out-of-the-box. Instead, you might need to use the host’s IP address or configure Docker networking to access the host machine.

In a Docker Compose setup, host.docker.internal isn't suitable because PostgreSQL runs in a Docker container. The recommended approach is to use postgres://postgres:postgres@db:5432/bloom to connect to the PostgreSQL service within Docker.

github-actions[bot] commented 1 month ago

Thank you @SureshPradhana you have been assigned this issue! Please follow the directions in our Contributing Guide. We look forward to reviewing your pull request shortly ✨


Support Chayn's mission? ⭐ Please star this repo to help us find more contributors like you! Learn more about Chayn here and explore our projects. 🌸

kyleecodes commented 1 month ago

Great points @SureshPradhana. Thanks for your patience while we were out of office. This might be a Linux specific suggestion? But let's try it! We are currently making updates to our Docker set-up. I've assigned you the issue if you would like to implement these changes. Please tag me if you have any questions or if you'd like to be unassigned.