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

CLI v5.8.12 (still) does not create the proper env var for MongoDB! #451

Open
malhusseiny opened this issue Mar 21, 2024 · 4 comments
Open

Comments

@malhusseiny
Copy link

A MongoDB service with the following docker-compose configuration in compose.yml:

mongo:
  image: mongo
  restart: always
  environment:
    MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER:-app}
    MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD:-!ChangeMe!}
    MONGO_INITDB_DATABASE: ${MONGODB_DB:-symfony}

causes the variables MONGO_DATABASE, MONGO_DB , MONGO_NAME to be set to symfony, which is fine. However, it also sets the authSource param of MONGO_URL to symfony as shown below:

symfony var:export --multiline             
export MONGO_DATABASE=symfony
export MONGO_DB=symfony
export MONGO_HOST=127.0.0.1
export MONGO_NAME=symfony
export MONGO_PASSWORD=!ChangeMe!
export MONGO_PORT=32795
export MONGO_SCHEME=mongodb
export MONGO_SERVER=mongodb://127.0.0.1:32795
export MONGO_URL=mongodb://app:!ChangeMe!@127.0.0.1:32795/?authSource=symfony
export MONGO_USER=app
export MONGO_USERNAME=app

Without the MONGO_INITDB_DATABASE: ${MONGODB_DB:-symfony} in the docker compose file, all database-related environment variables as well as the authSource param become empty. It would be great if you could untangle that coupling.

@fabpot
Copy link
Contributor

fabpot commented Mar 25, 2024

The logic that parses the Docker configuration for MongoDB is here: https://github.com/symfony-cli/symfony-cli/blob/main/envs/docker.go#L401 and the logic to use that information to create env vars is here: https://github.com/symfony-cli/symfony-cli/blob/main/envs/docker.go#L401

As I'm not a MongoDB user myself, I'm not sure what should be changed there. @malhusseiny Can you help me?

@malhusseiny
Copy link
Author

@fabpot

Here is the line that needs to be changed: https://github.com/symfony-cli/symfony-cli/blob/main/envs/envs.go#L242

In order to create the correct MONGODB_URL env var, it should be changed to:

values[fmt.Sprintf("%sURL", prefix)] = fmt.Sprintf("%s://%s:%s@%s:%s", endpoint["scheme"].(string), endpoint["username"].(string), endpoint["password"].(string), endpoint["host"].(string), formatInt(endpoint["port"]))

such that the value of endpoint["path"] (i.e. default working database) is not incorrectly set as authentication database (the one where MongoDB looks up the connection login credentials). This is also consistent with with intended purpose of the MONGO_INITDB_DATABASE docker environment variable as per the official mongo docker image.

@fabpot
Copy link
Contributor

fabpot commented Mar 26, 2024

But here, you've completely removed the "path", which looks wrong to me. But then again, I'm not a MongoDB user, so ideally, I'd like others to chime in here.
As a first step, maybe you can create a PR for that change?

@malhusseiny
Copy link
Author

@fabpot Absolutely! Please check out my justification in the PR #458

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

No branches or pull requests

2 participants