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

feat:add apollo configuration to load env file #11139

Closed

Conversation

huanshare
Copy link

@huanshare huanshare commented Nov 26, 2024

Close #11064

Summary

Please note:dify supports loading env file configuration from the configuration-center(apollo). If you use apollo, first configure the dify configuration on apollo, and then before starting the project, configure the following parameters in the environment variables:
CONFIGURATION_TYPE=apollo,APOLLO_APP_ID=xxx,APOLLO_CLUSTER=xxx,APOLLO_CONFIG_URL=xxx,APOLLO_NAMESPACE=xxx

Tip

Close issue syntax: Fixes #<issue number> or Resolves #<issue number>, see documentation for more details.

Screenshots

Before: After:
... ...

Checklist

Important

Please review the checklist below before submitting your pull request.

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 💪 enhancement New feature or request 📚 documentation Improvements or additions to documentation labels Nov 26, 2024
@crazywoola
Copy link
Member

Cool, I shall talk to the dev team regarding this pull request.

@laipz8200
Copy link
Member

laipz8200 commented Nov 27, 2024

I think this PR needs improvement:

  1. The configuration information used by Apollo is only sourced from environment variables. It would be clearer to include this information in the code like the DifyConfig structure.
  2. We should first read the configuration center details from the environment variables (or a .env file) and then access the configuration center to update the settings.
  3. Overwriting the .env file is a bad idea, as it would result in losing the original content of the file.

刘欢(liuhuan101) added 2 commits November 28, 2024 10:26
fix:not overwrite of .env files
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Nov 28, 2024
@huanshare
Copy link
Author

I think this PR needs improvement:

  1. The configuration information used by Apollo is only sourced from environment variables. It would be clearer to include this information in the code like the DifyConfig structure.
  2. We should first read the configuration center details from the environment variables (or a .env file) and then access the configuration center to update the settings.
  3. Overwriting the .env file is a bad idea, as it would result in losing the original content of the file.

1、The first problem has been adjusted.
2、The second apollo configuration involves security issues. It is recommended to configure from environment variables instead of reading from env files.
3、The third problem has been adjusted (the key that exists in apollo overwrites the one in env file, and the key that does not exist in apollo still uses the original one).

*** For the third problem, it is recommended that all configurations except environment variables should be configured using apollo, so that it is easier to maintain in one place.

@laipz8200
Copy link
Member

Hi @huanshare.

The current implementation still doesn’t quite meet my expectations. Here’s the scenario I envision:

  1. The user configures Apollo-related information in environment variables.
  2. When Dify starts, this information is loaded into dify_config.
  3. ext_configuration retrieves dify_config and checks if Apollo is configured.
  4. ext_configuration fetches the configuration from Apollo and updates dify_config.

Hope this helps clarify!

@huanshare huanshare closed this Nov 29, 2024
@huanshare
Copy link
Author

Hi @huanshare.

The current implementation still doesn’t quite meet my expectations. Here’s the scenario I envision:

  1. The user configures Apollo-related information in environment variables.
  2. When Dify starts, this information is loaded into dify_config.
  3. ext_configuration retrieves dify_config and checks if Apollo is configured.
  4. ext_configuration fetches the configuration from Apollo and updates dify_config.

Hope this helps clarify!

I am sorry,I ran into some issues and need to close this pull request

@huanshare huanshare deleted the feat/add-apollo-configuration branch November 29, 2024 07:40
@huanshare huanshare restored the feat/add-apollo-configuration branch November 29, 2024 07:40
@huanshare huanshare deleted the feat/add-apollo-configuration branch November 29, 2024 07:40
@laipz8200
Copy link
Member

Don’t mind. Would you consider opening a new PR to complete this feature? I agree that we can read Apollo's configuration directly from environment variables (in fact, adding the configuration to DifyConfig will still prioritize using environment variables), but I would like to avoid modifying our .env file. Instead, we can simply update the dify_config object.

@huanshare
Copy link
Author

Don’t mind. Would you consider opening a new PR to complete this feature? I agree that we can read Apollo's configuration directly from environment variables (in fact, adding the configuration to DifyConfig will still prioritize using environment variables), but I would like to avoid modifying our .env file. Instead, we can simply update the dify_config object.

you can visit this #11210

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 documentation Improvements or additions to documentation 💪 enhancement New feature or request size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.env configuration pull from "configuration center"
3 participants