This project is a stock portfolio management system that allows users to manage their stock investments. It includes functionalities to add, update, delete, and retrieve stock information, as well as calculate stock values and portfolio gains. The project is built using Flask for the backend and MongoDB for data storage. The system is containerized using Docker and orchestrated using Docker Compose.
- Stock Management: Add, update, delete, and retrieve stock information.
- Stock Value Calculation: Calculate the current value of stocks using an external API.
- Portfolio Value Calculation: Calculate the total value of the stock portfolio.
- Capital Gains Calculation: Calculate the capital gains for the portfolio.
- Health Check: Endpoint to check the health of the service.
The project incorporates a CI/CD pipeline using GitHub Actions. The workflow is defined in the .github/workflows/assignment4.yml file and includes the following jobs:
- Checkout Code: Checks out the project code from the repository.
- Build Docker Images: Builds Docker images for the
stocksandcapital-gainsservices. - Save Artifacts: Saves the built Docker images as artifacts for use in subsequent jobs.
- Log Information: Logs the build status and other relevant information.
- Download Artifacts: Downloads the Docker images built in the previous job.
- Load Docker Images: Loads the Docker images into the Docker daemon.
- Run Docker Compose: Starts the services using Docker Compose.
- Run Tests: Executes the test suite using
pytestto verify the functionality of the services. - Log Test Results: Logs the test results and uploads them as artifacts.
- Download Artifacts: Downloads the Docker images built in the build job.
- Load Docker Images: Loads the Docker images into the Docker daemon.
- Run Docker Compose: Starts the services using Docker Compose.
- Run Queries: Executes specific queries against the running services and records the results.
- Log Query Results: Logs the query results and uploads them as artifacts.
- Docker
- Docker Compose
- Python 3.8+
- MongoDB
-
Clone the Repository:
git clone <repository-url> cd project4
-
Set Up Environment Variables: Create a
.envfile in the root directory with the following content:API_KEY=<your_api_key>
-
Build and Run Services:
docker-compose up --build
-
Run Tests:
pytest tests/assn4_tests.py
The CI/CD pipeline is triggered automatically on a workflow dispatch event. You can also manually trigger the workflow from the GitHub Actions tab in your repository.
This project demonstrates the integration of CI/CD practices using GitHub Actions to automate the build, test, and deployment processes. By following this approach, we ensure that the application is consistently built and tested, leading to higher code quality and faster delivery.