Skip to content

Commit 01d4bb1

Browse files
authored
Merge pull request #11 from boyanaboneva/feature/add-resources
Updated README.md.
2 parents d483ac0 + 55917f1 commit 01d4bb1

1 file changed

Lines changed: 83 additions & 54 deletions

File tree

README.md

Lines changed: 83 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,81 @@
1-
# FastAPI starter
1+
# FastAPI Starter
22

33
A boilerplate application to start developing microservices in Python.
44

55
## Tests
66

7-
To run the tests use following command:
7+
To run the tests, use the following command:
88
```shell
99
pytest
1010
```
1111

12-
To run the tests with coverage use following command:
12+
To run the tests with coverage, use the following command:
1313
```shell
1414
pytest --cov=app --cov-report=term-missing
1515
```
1616

1717
## Docker
1818

19-
To build Dockerfile locally use following commands:
19+
To build the Dockerfile locally, use the following commands:
2020
```shell
2121
docker build . -t [image-name]:[tag] -f /path/to/Dockerfile
2222
```
2323
```shell
2424
docker run -d tag
2525
```
26-
then open a browser and navigate to http://localhost:8000. If it opens "Hello world", then it works.
26+
Then open a browser and navigate to http://localhost:8000. If it opens "Hello world", then it works.
2727

2828
## Workflows
2929

30-
Two workflows are available in the project. One should trigger on pull request and another one on merge. A workflow,
31-
which triggers on push is not created, as it may cost a lot of resources and go over the budget.
30+
Two workflows are available in the project. One triggers on pull requests, and another triggers on merges. A workflow that triggers on every push is not created, as it may consume excessive resources and exceed the budget.
3231

33-
To run ***fastapi_merge.yml*** workflow, a pull request should be made to the main branch and merged to GitHub.
34-
It will trigger the pipeline and can be seen in GitHub -> Actions tab. The workflow includes the following checks:
35-
SonarCloud, Snyk, Trivy. It also builds the Docker image and push it to DockerHub.
32+
### **Pull Request Workflow**
33+
To run the ***fastapi_pr.yml*** pipeline, a pull request should be made to the main branch on GitHub. This will trigger the pipeline, which can be monitored in the GitHub -> Actions tab. The workflow includes the following checks:
34+
- **GitLeaks**: Scans for sensitive information in the codebase.
35+
- **EditorConfig**: Ensures consistent coding styles.
36+
- **Python PyLint**: Checks for Python code quality.
37+
- **Python Black**: Formats Python code to adhere to PEP 8 standards.
38+
- **MarkdownLint CLI**: Validates Markdown files for proper formatting.
39+
- **Unit Tests**: Runs the test suite to ensure code correctness.
3640

37-
To run ***fastapi_pr.yml*** pipeline, a pull request should be made to the main branch to GitHub.
38-
It will trigger the pipeline and can be seen in GitHub -> Actions tab. The workflow includes the following checks:
39-
GitLeaks, EditConfig, Python PyLint, Python Black, MarkdownLint CLI, Unit tests.
41+
### **Merge Workflow**
42+
To run the ***fastapi_merge.yml*** workflow, a pull request should be merged into the main branch on GitHub. This will trigger the pipeline, which can also be monitored in the GitHub -> Actions tab. The workflow includes the following steps:
43+
- **SonarCloud**: Performs static code analysis for code quality and security.
44+
- **Snyk**: Scans for vulnerabilities in dependencies.
45+
- **Trivy**: Scans Docker images for vulnerabilities.
46+
- **Docker Image Build and Push**: Builds the Docker image and pushes it to Docker Hub.
4047

4148
## ArgoCD
4249

43-
Prerequisites:
44-
- installed ***kubectl*** command-line tool
45-
- installed ***Docker Desktop*** or other external cluster
50+
### Prerequisites
51+
- Installed ***kubectl*** command-line tool.
52+
- Installed ***Docker Desktop*** or another external Kubernetes cluster.
4653

4754
### Install ArgoCD
48-
55+
To install ArgoCD, create a namespace for it:
4956
```shell
5057
kubectl create namespace argocd
5158
```
52-
53-
This will create a new namespace server, where Argo CD services and application resources will live.
59+
Then apply the installation manifest:
5460
```shell
5561
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
5662
```
5763

58-
### Download ArgoCD on Macbook
59-
64+
### Download ArgoCD CLI (MacOS Example)
6065
```shell
6166
brew install argocd
6267
```
63-
Port Forwarding
68+
69+
### Port Forwarding
70+
To access the ArgoCD UI, forward the port:
6471
```shell
6572
kubectl port-forward svc/argocd-server -n argocd 8080:443
6673
```
6774

6875
### Login via UI
69-
70-
Navigate to a browser and open *https://localhost:8080* - the certificate will be invalid, though open it.
71-
The username is *admin* and the temp password can be extracted with the command bellow, excluding the % symbol at the end.
76+
Navigate to *https://localhost:8080* in your browser. The certificate will be invalid, but you can proceed. Use the following credentials:
77+
- **Username**: `admin`
78+
- **Temporary Password**: Extract it using the command below (exclude the `%` symbol at the end):
7279
```shell
7380
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
7481
```
@@ -77,66 +84,88 @@ Update the password:
7784
argocd account update-password
7885
```
7986

80-
### Create apps via UI
81-
82-
After logging in, click the '+ New App' button, give the app a name (at this example set 'app'), use the project 'default',
83-
and leave the sync policy as 'Manual'.
84-
Connect the deployment repo to Argo CD by setting repository URL to the GitHub repo URL:
85-
https://github.com/boyanaboneva/devops-gitops,
86-
leave revision as 'HEAD', and set the path to the deployment folder name - in this case 'devops-service-deployment'.
87-
For 'Destination' set cluster to:
88-
https://kubernetes.default.svc
89-
and namespace to 'application'. Finally, click on the 'Create' button.
87+
### Create Applications via UI
88+
1. Log in to the ArgoCD UI.
89+
2. Click the '+ New App' button.
90+
3. Provide the following details:
91+
- **Application Name**: `app`
92+
- **Project**: `default`
93+
- **Sync Policy**: `Manual`
94+
- **Repository URL**: `https://github.com/boyanaboneva/devops-gitops`
95+
- **Revision**: `HEAD`
96+
- **Path**: `devops-service-deployment`
97+
- **Destination Cluster**: `https://kubernetes.default.svc`
98+
- **Namespace**: `application`
99+
4. Click 'Create'.
90100

91-
### Sync (Deploy) The Application
101+
### Sync (Deploy) the Application
102+
If the application's health status is "Out of sync," click the 'Sync apps' button in the UI. Then, click 'Synchronize' to deploy the application. You can view more details by clicking on the application.
92103

93-
If it's Health status is 'Out of sync', then click on the 'Sync apps' button in the application page UI. A panel will be
94-
opened and then, click on 'Synchronize' button.
95-
You can see more details by clicking at the 'app' application.
104+
## Kubernetes Deployment
96105

97-
## Kubernetes deployment
106+
The deployment files are stored in a separate GitOps repository: [https://github.com/boyanaboneva/devops-gitops](https://github.com/boyanaboneva/devops-gitops).
98107

99-
Deployments files are in another repo: https://github.com/boyanaboneva/devops-gitops
100-
101-
Create another namespace, e.g. 'application':
108+
### Create a Namespace
109+
Create a namespace for the application:
102110
```shell
103111
kubectl create namespace application
104112
```
105113

106-
To create a config map with environment variables navigate to the file in the gitops repo via terminal:
114+
### Apply ConfigMap
115+
Navigate to the GitOps repository and apply the environment variables ConfigMap:
107116
```shell
108117
kubectl apply -f env_fastapi_configmap.yml
109118
```
110119

111-
Using terminal navigate to the kubernetes deployment folder in the gitops repo. Apply the 'deployment.yml' file in the
112-
newly created namespace, e.g. 'application':
120+
### Apply Deployment
121+
Navigate to the Kubernetes deployment folder in the GitOps repository and apply the deployment manifest:
113122
```shell
114123
kubectl apply -f deployment.yml -n application
115124
```
116-
The response should look like this:
125+
Expected response:
117126
```shell
118127
deployment.apps/fast-api-deployment created
119128
```
120129

121-
To check everything is applied, get the pods of this namespace:
130+
### Verify Deployment
131+
Check the pods in the namespace:
122132
```shell
123133
kubectl get pods -n application
124134
```
125-
The response should look like this:
135+
Expected response:
126136
```shell
127137
NAME READY STATUS RESTARTS AGE
128138
fast-api-deployment-66ff55bb64-cmkbl 1/1 Running 0 22s
129139
```
130140

131-
Using terminal navigate to the kubernetes deployment folder in the gitops repo. Apply the 'service.yml' file in the
132-
newly created namespace, e.g. 'application':
141+
### Apply Service
142+
Apply the service manifest:
133143
```shell
134144
kubectl apply -f service.yml -n application
135145
```
136-
The response should look like this:
146+
Expected response:
137147
```shell
138148
service/fastapi-service configured
139149
```
140150

141-
## Software architecture diagram
142-
![alt text](resources/software-architecture.png "architecture")
151+
## Architecture Overview
152+
153+
This project follows a modern DevOps architecture that integrates **GitHub**, **GitHub Actions**, **ArgoCD**, **Docker Hub**, and **Kubernetes**. Below is a detailed explanation of the architecture:
154+
155+
### Key Components
156+
1. **GitHub**: Hosts the application code and a separate GitOps repository for Kubernetes manifests.
157+
2. **GitHub Actions**: Automates CI/CD workflows, including building, testing, and pushing Docker images.
158+
3. **Docker Hub**: Stores Docker images for deployment.
159+
4. **Kubernetes**: Orchestrates containerized applications, ensuring scalability and reliability.
160+
5. **ArgoCD**: Implements GitOps principles by syncing Kubernetes manifests from the GitOps repository to the cluster.
161+
162+
### Workflow Summary
163+
1. Developers push code changes to GitHub.
164+
2. GitHub Actions builds the application, runs tests, and pushes Docker images to Docker Hub.
165+
3. The GitOps repository is updated with the new image tag in the Kubernetes manifests.
166+
4. ArgoCD detects changes in the GitOps repository and syncs them to the Kubernetes cluster.
167+
168+
This architecture ensures a seamless CI/CD pipeline with automated deployments, version control, and rollback capabilities.
169+
170+
## Software Architecture Diagram
171+
![alt text](resources/software-architecture.png "architecture")

0 commit comments

Comments
 (0)