Skip to content

Commit 38c5339

Browse files
committed
reorganize
1 parent 36518ee commit 38c5339

1 file changed

Lines changed: 65 additions & 63 deletions

File tree

README.md

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
11
# DevOps and Cloud Based Software
22

3-
## FastAPI GitOps Starter
3+
# 1. Introduction
44

5-
A comprehensive starter template for learning GitOps practices with FastAPI. This repository demonstrates modern software development workflows including CI/CD pipelines, code quality tools, and automated testing.
5+
In this tutorial will use GitOps practices with FastAPI including CI/CD pipelines, code quality tools, and automated testing.
66

7-
### 🎯 Learning Objectives
7+
## 🎓 Background Resources
8+
9+
#### FastAPI
10+
- [Official Documentation](https://fastapi.tiangolo.com/)
11+
- [Tutorial - User Guide](https://fastapi.tiangolo.com/tutorial/)
12+
13+
#### GitOps
14+
- [GitOps Principles](https://www.gitops.tech/)
15+
- [GitHub Actions Documentation](https://docs.github.com/en/actions)
16+
17+
#### Code Quality
18+
- [Ruff Documentation](https://docs.astral.sh/ruff/)
19+
- [Black Documentation](https://black.readthedocs.io/)
20+
- [Pre-commit Documentation](https://pre-commit.com/)
21+
22+
#### Testing
23+
- [Pytest Documentation](https://docs.pytest.org/)
24+
25+
#### Docker
26+
- [Docker Documentation](https://docs.docker.com/)
27+
28+
#### Kubernetes & Helm
29+
- [Kubernetes Documentation](https://kubernetes.io/docs/home/)
30+
- [Helm Documentation](https://helm.sh/docs/)
31+
- [Minikube Documentation](https://minikube.sigs.k8s.io/docs/)
32+
-
33+
## 🎯 Learning Objectives
834

935
This tutorial will teach you:
1036
- Building REST APIs with FastAPI
@@ -14,23 +40,23 @@ This tutorial will teach you:
1440
- Using pre-commit hooks for automated code validation
1541
- Following GitOps principles
1642

17-
### 📋 Prerequisites
43+
## 📋 Prerequisites
1844

1945
- Python 3.11 or higher
2046
- Git
2147
- Docker (optional, for containerization)
2248
- GitHub account
2349

24-
### 🚀 Quick Start
50+
# 2. Tutorial
2551

26-
#### 1. Clone the Repository
52+
Clone the Repository
2753

2854
```bash
2955
git clone https://github.com/DevOps-and-Cloud-based-Software/fastapi-gitops.git
3056
cd fastapi-gitops-starter
3157
```
3258

33-
#### 2. Set Up Python Environment
59+
Set Up Python Environment
3460

3561
```bash
3662
# Create a virtual environment
@@ -46,41 +72,41 @@ venv\Scripts\activate
4672
pip install -r requirements.txt
4773
```
4874

49-
#### 3. Run the Application
75+
Run the Application:
5076

5177
```bash
5278
uvicorn app.main:app --reload
5379
```
5480

5581
Visit http://localhost:8000 to see your API running!
5682

57-
#### 4. Explore the API
83+
Explore the API
5884

5985
- API Documentation: http://localhost:8000/GitOps-Starter/docs
6086
- Root endpoint: http://localhost:8000/GitOps-Starter
6187
- Health check: http://localhost:8000/GitOps-Starter/health
6288
- List items: http://localhost:8000/GitOps-Starter/api/items
6389
- Get specific item: http://localhost:8000/GitOps-Starter/api/items/1
6490

65-
### 🧪 Testing
91+
## 🧪 Testing
6692

67-
#### Run Tests
93+
Run Tests
6894

6995
```bash
7096
pytest
7197
```
7298

73-
#### Run Tests with Coverage
99+
Run Tests with Coverage
74100

75101
```bash
76102
pytest --cov=app --cov-report=html
77103
```
78104

79105
View the coverage report by opening `htmlcov/index.html` in your browser.
80106

81-
### 🔍 Code Quality
107+
## 🔍 Code Quality
82108

83-
#### Linting with Ruff
109+
Linting with Ruff
84110

85111
```bash
86112
# Check for issues
@@ -90,7 +116,7 @@ ruff check app/ tests/
90116
ruff check app/ tests/ --fix
91117
```
92118

93-
#### Code Formatting with Black
119+
Code Formatting with Black
94120

95121
```bash
96122
# Check formatting
@@ -100,12 +126,12 @@ black --check app/ tests/
100126
black app/ tests/
101127
```
102128

103-
### 🪝 Pre-commit Hooks
129+
## 🪝 Pre-commit Hooks
104130

105131
Pre-commit hooks automatically check your code before each commit, ensuring
106132
consistent code quality.
107133

108-
#### Setup Pre-commit
134+
Setup Pre-commit:
109135

110136
```bash
111137
# Install pre-commit
@@ -115,7 +141,7 @@ pip install pre-commit
115141
pre-commit install
116142
```
117143

118-
#### Using Pre-commit
144+
Using Pre-commit:
119145

120146
Pre-commit will now run automatically on `git commit`. You can also run it manually:
121147

@@ -133,13 +159,13 @@ The pre-commit hooks include:
133159

134160
### 🐳 Docker
135161

136-
#### Build the Docker Image
162+
Build the Docker Image:
137163

138164
```bash
139165
docker build -t fastapi-gitops-starter .
140166
```
141167

142-
#### Run the Container
168+
Run the Container:
143169

144170
```bash
145171
docker run -p 8000:8000 fastapi-gitops-starter
@@ -150,14 +176,16 @@ Access the API at http://localhost:8000/GitOps-Starter/
150176
### Minikube Setup
151177

152178
If you want to test the Kubernetes deployment locally, you can use Minikube.
153-
#### Install Minikube
179+
180+
Install Minikube
154181
Follow the instructions at the [Minikube installation guide](https://minikube.sigs.k8s.io/docs/start/).
155-
#### Start Minikube with Ingress and Ingress-DNS Addons
182+
183+
Start Minikube with Ingress and Ingress-DNS Addons:
156184
```bash
157185
minikube start --addons=ingress,ingress-dns
158186
```
159187

160-
#### Add Minikube IP to /etc/hosts
188+
Add Minikube IP to /etc/hosts:
161189
Get the Minikube IP:
162190
```bash
163191
minikube ip
@@ -169,24 +197,24 @@ Add the following line to your `/etc/hosts` file:
169197
Replace `<MINIKUBE_IP>` with the IP address obtained from the previous command.
170198

171199

172-
### ☸️ Kubernetes Deployment with Helm
200+
## ☸️ Kubernetes Deployment with Helm
173201

174202
This repository includes a Helm chart for deploying the application to Kubernetes.
175203

176-
#### Prerequisites
204+
### Prerequisites
177205

178206
- Kubernetes 1.19+
179207
- Helm 3.0+
180208

181-
#### Install the Helm Chart
209+
### Install the Helm Chart
182210

183211
Install the chart:
184212

185213
```bash
186214
helm install my-release ./helm/fastapi-gitops-starter
187215
```
188216

189-
#### Uninstall the Helm Chart
217+
### Uninstall the Helm Chart
190218
To uninstall/delete the deployment:
191219

192220
```bash
@@ -198,9 +226,9 @@ Make sure you understand how to set up the Horizontal Pod Autoscaler (HPA) for
198226
scaling based on load and ingress configuration for accessing the application
199227
including host and paths.
200228

201-
### 📚 Tutorial Exercises
229+
# 3. 📚 Tutorial Exercises
202230

203-
#### Exercise 1: Add pre-commit Hooks
231+
## Exercise 1: Add pre-commit Hooks
204232
1. Open `.pre-commit-config.yaml`
205233
2. Add a new hook to check:
206234
* if we try to commit large files
@@ -210,12 +238,12 @@ including host and paths.
210238
* To make sure we do not commit secrets using
211239
* To check code style
212240

213-
##### Questions
241+
## Questions
214242
1. What are the benefits of using pre-commit hooks in a project?
215243
2. How can pre-commit hooks improve code quality and consistency?
216244
3. How do you configure pre-commit hooks to run only on specific file types or directories?
217245

218-
#### Exercise 2: Add a New Endpoint
246+
## Exercise 2: Add a New Endpoint
219247

220248
1. Open `app/main.py`
221249
2. Add a new endpoint to create an item:
@@ -235,27 +263,27 @@ async def create_item(name: str, description: str):
235263
3. Write a test in `tests/test_main.py`
236264
4. Run tests to verify
237265

238-
##### Questions
266+
### Questions
239267
1. How can you ensure that your tests cover edge cases and error scenarios?
240268
2. How do you run tests and view coverage reports?
241269
3. What are the benefits of maintaining high code coverage in a project?
242270
4. What other metrics can be used to assess code quality besides code coverage?
243271

244272

245-
#### Exercise 3: Add a CI Pipeline
273+
## Exercise 3: Add a CI Pipeline
246274

247275
1. Open `.github/workflows/ci-cd.yml`
248276
2. Add a step to lint the code using Ruff
249277
3. Add a step to run tests with coverage. The pipeline should fail if coverage is below 80%
250278
4. Add a step to build the Docker image if tests pass. If we do a release, tag the image appropriately (with its version and the tag 'latest') and push it to GitHub registry
251279

252-
##### Questions
280+
### Questions
253281

254282
1. What are some strategies for rolling back deployments in case of failures in the CI/CD pipeline?
255283
2. How can you ensure your application is always up to date with the latest security patches and dependencies?
256284
3. How can you set up automatic deployments in a production environment while minimizing downtime and ensuring KPOs are met?
257285

258-
#### Exercise 4: Deploy on a K8s "production" Cluster
286+
## Exercise 4: Deploy on a K8s "production" Cluster
259287

260288
1. Set up a Kubernetes cluster (e.g., using Minikube or a cloud provider)
261289
2. Deploy the application using the Helm chart
@@ -270,40 +298,14 @@ kubectl get hpa -n default -w
270298
```
271299
7. Note how much time it takes for the pods to scale up and down based on the load
272300

273-
##### Questions
301+
### Questions
274302
1. The auto-scaling did not work as expected. What could be the possible reasons?
275303
2. How does Horizontal Pod Autoscaling (HPA) work in Kubernetes?
276304
3. How can you add custom metrics for scaling decisions in HPA?
277305
4. The helm chart provides a way to perform canary and blue-green deployments. How would you set this up in a production environment? What other tools you need to use to make this work?
278306
5. What is the difference limits and autoscaling
279307

280308

281-
### 🎓 Learning Resources
282-
283-
#### FastAPI
284-
- [Official Documentation](https://fastapi.tiangolo.com/)
285-
- [Tutorial - User Guide](https://fastapi.tiangolo.com/tutorial/)
286-
287-
#### GitOps
288-
- [GitOps Principles](https://www.gitops.tech/)
289-
- [GitHub Actions Documentation](https://docs.github.com/en/actions)
290-
291-
#### Code Quality
292-
- [Ruff Documentation](https://docs.astral.sh/ruff/)
293-
- [Black Documentation](https://black.readthedocs.io/)
294-
- [Pre-commit Documentation](https://pre-commit.com/)
295-
296-
#### Testing
297-
- [Pytest Documentation](https://docs.pytest.org/)
298-
299-
#### Docker
300-
- [Docker Documentation](https://docs.docker.com/)
301-
302-
#### Kubernetes & Helm
303-
- [Kubernetes Documentation](https://kubernetes.io/docs/home/)
304-
- [Helm Documentation](https://helm.sh/docs/)
305-
- [Minikube Documentation](https://minikube.sigs.k8s.io/docs/)
306-
307309
### 🤝 Contributing
308310

309311
1. Fork the repository
@@ -314,7 +316,7 @@ kubectl get hpa -n default -w
314316
6. Ensure all tests pass and code quality checks are successful
315317
7. Merge
316318

317-
### 💡 Tips for Students
319+
### 💡 Tips
318320

319321
1. **Start Simple**: Understand each component before moving to the next
320322
2. **Read the Logs**: When something fails, the CI/CD logs contain valuable information

0 commit comments

Comments
 (0)