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

Pull Request - CI/CD Part 1 Dynamic Env - Digital Dreamers #100

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

Conversation

xinpengwoo
Copy link

@xinpengwoo xinpengwoo commented Aug 31, 2024

Summary

The .env file with the utility function configures environment variables during local development. This allows developers to customize their local environment without affecting the production settings.

Changes

  • Two files added: env_manager.py (Location: app/services/env_manager.py) and test_env_manager.py (Location: app/services/tests/test_env_manager.py)

  • Changes made to the ./local-start.sh to incorporate the utility function

Screenshot 2024-08-31 at 11 13 59
  • Changes made to the .gitignore to ignore the folder keys/
  • Change made in the requirements.txt, fastapi changed to fastapi[standard]

Testing

The new feature was tested using the following unit tests and integration tests. Refer to the documentation for more details.

I) Unit Tests

  • ‘Test_env_variable_from_env_file’: this test verifies that the ‘get_env_variable’ function correctly retrieves environment variables from a ‘.env’ file.
  • ‘test_env_variable _from_google_secrets’: this test checks that the ‘get_env_variable’ function correctly retrieve environment variables from Google Cloud’s Secret Manager when the variable is not found in the ‘.env’ file.

Steps to run the unit tests:

Execute the test command: pytest app/services/tests/test_env_manager.py
Review the test output: after running the command, you’ll see output indicating whether the tests passed or failed.
Expected Output: Upon successful execution, you should see the following output in terminal:
Screenshot 2024-09-07 at 12 03 21

II) Integration Tests

  • The integration test ensures that the ‘get_env_variable’ function works correctly when integrated into the broader application environment. This test verifies that environment variables are correctly loaded from both the ‘.env’ file and Google Cloud’s Secret Manager, and that the application starts with the correct configuration.

Steps to run the integration test:
Run the Startup Script:

./local-start.sh

The script begins by setting up local environment variables required by the application.
It authenticates the Google Cloud project using the service account credentials specified in the ‘local-auth.json’ file.
The ‘get_env_variable’ function is called to fetch environment variables, ‘GOOGLE_API_KEY’, ‘ENV_TYPE’,and ‘PROJECT_ID’. These variables are either retrieved from the local ‘.env’ file or from Google Cloud Secret Manager if not found locally.
Expected Output: Upon successful execution, you should see the following output in terminal:
Screenshot 2024-08-31 at 11 16 32

Results

The new feature passed the above-mentioned tests and performed its required function without breaking the existing codebase.

Notes

  • The utility function ‘get_env_varible’ is designed to streamline the process of retrieving environment variables from both the .env file (for local development) and Google Cloud Secrets Manager (for production).
  • Documentation: CI/CD Part : Dynamic Environment
  • This function attempts to retrieve environment variables in a secure and reliable manner. It first attempts to retrieve the environment variable from a local .env file. If the variable is not found there, the function then tries to retrieve it from Google Cloud Secret Manager.

Screenshots

The utility function with relevant error handling performed.
Screenshot 2024-08-31 at 10 13 06
Screenshot 2024-08-31 at 10 13 22

Copy link
Collaborator

@huzaifakhan04 huzaifakhan04 left a comment

Choose a reason for hiding this comment

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

Excellent job on the pipeline! It would be helpful to add more documentation through code comments to enhance clarity. Please update the app/services/tests/test_env_manager.py file as specified. Your code is well-written and tidy – great work on that! :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's switch the testing framework to pytest, as it's our primary choice. This will maintain consistency across all contributions.

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

Successfully merging this pull request may close these issues.

2 participants