Add REDIS_HOST
and POSTGRES_HOST
Environment Variables to Example Voting App Configuration (Fixes #370)
#386
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Description
Overview
This pull request addresses issue #370, which proposes the ability to configure Redis and PostgreSQL hosts through environment variables instead of relying on hard-coded values. This change is particularly beneficial for users deploying the application in environments such as AWS EKS with ElastiCache and RDS.
Changes Made
The following modifications have been implemented to enable configuration via environment variables:
Redis Connection:
vote/app.py
to replace the hardcoded Redis host with an environment variable. The new implementation usesos.getenv('REDIS_HOST', 'redis')
, allowing users to specify a custom host while defaulting to'redis'
if the variable is unset.Postgres Connection:
result/server.js
to utilize an environment variable for the Postgres hostname.worker/Program.cs
, updated the connection settings for both Redis and Postgres to draw from environment variables instead of hardcoded values.Testing:
'redis'
anddb
) and with user-specified values.Rationale
The hard-coded values for Redis and Postgres made it challenging to adapt the application for different environments. By introducing environment variable configuration, we increase the flexibility of the application, enabling seamless integration with various deployments.
Validation
To validate the changes:
Additional Notes
REDIS_HOST
andPOSTGRES_HOST
as needed to utilize this feature.Conclusion
This enhancement improves the usability of the example voting app for a broader range of deployment scenarios and aligns with best practices for configuration management in modern applications.
Fixes #370