Skip to content

Commit a3b9758

Browse files
committed
added tests
1 parent 58badc3 commit a3b9758

3 files changed

Lines changed: 118 additions & 47 deletions

File tree

.github/workflows/markdown2pdf.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Build pdf
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
env:
8+
GITHUB_TOKEN: ${{ github.token }}
9+
URL: https://raw.githubusercontent.com/DevOps-and-Cloud-based-Software/assignment3/${{ github.ref_name }}
10+
11+
jobs:
12+
publish:
13+
runs-on: ubuntu-latest
14+
name: Publish Document
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
20+
- name: Replace links
21+
run: |
22+
cp README.md README_WITH_LINKS.md
23+
sed -i -e "s#\(^\!\[[^]]\+\](\)\(images/\)#\1$URL/\2#g" README_WITH_LINKS.md
24+
for file in sources/*; do sed -i -e "s#($file)#($URL/$file)#g" README_WITH_LINKS.md ; done
25+
26+
- name: urls-checker
27+
uses: urlstechie/urlchecker-action@master
28+
continue-on-error: true
29+
with:
30+
file_types: .md,yaml,json
31+
retry_count: 3
32+
exclude_patterns: http://IP:NODE_PORT,http://localhost,http://xxxxxxxxx.compute-1.amazonaws.com,http://IP
33+
34+
- name: Publish PDF Document
35+
uses: shrink/actions-document-publish@v1
36+
id: publish-document
37+
with:
38+
sources: 'README_WITH_LINKS.md'
39+
40+
- name: Upload Document
41+
uses: actions/upload-artifact@v4
42+
id: upload-document
43+
with:
44+
name: 'lab_assignment_3.pdf'
45+
path: ${{ steps.publish-document.outputs.pdf }}
46+
47+
- name: Upload README_WITH_LINKS.md
48+
uses: actions/upload-artifact@v4
49+
id: upload-readme-file
50+
with:
51+
name: 'README_WITH_LINKS.md'
52+
path: README_WITH_LINKS.md
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: test
2+
3+
on:
4+
[push]
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
name: Test URLs
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v3
13+
14+
- name: urls-checker
15+
uses: urlstechie/urlchecker-action@master
16+
with:
17+
file_types: .md,yaml,json
18+
retry_count: 3
19+
exclude_patterns: http://IP:NODE_PORT,http://localhost,http://xxxxxxxxx.compute-1.amazonaws.com,http://IP,http://minikube.test

README.md

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

3-
# FastAPI GitOps Starter
3+
## FastAPI GitOps Starter
44

55
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.
66

7-
## 🎯 Learning Objectives
7+
### 🎯 Learning Objectives
88

99
This tutorial will teach you:
1010
- Building REST APIs with FastAPI
@@ -14,23 +14,23 @@ This tutorial will teach you:
1414
- Using pre-commit hooks for automated code validation
1515
- Following GitOps principles
1616

17-
## 📋 Prerequisites
17+
### 📋 Prerequisites
1818

1919
- Python 3.11 or higher
2020
- Git
2121
- Docker (optional, for containerization)
2222
- GitHub account
2323

24-
## 🚀 Quick Start
24+
### 🚀 Quick Start
2525

26-
### 1. Clone the Repository
26+
#### 1. Clone the Repository
2727

2828
```bash
2929
git clone https://github.com/QCDIS/fastapi-gitops-starter.git
3030
cd fastapi-gitops-starter
3131
```
3232

33-
### 2. Set Up Python Environment
33+
#### 2. Set Up Python Environment
3434

3535
```bash
3636
# Create a virtual environment
@@ -46,41 +46,41 @@ venv\Scripts\activate
4646
pip install -r requirements.txt
4747
```
4848

49-
### 3. Run the Application
49+
#### 3. Run the Application
5050

5151
```bash
5252
uvicorn app.main:app --reload
5353
```
5454

5555
Visit http://localhost:8000 to see your API running!
5656

57-
### 4. Explore the API
57+
#### 4. Explore the API
5858

5959
- API Documentation: http://localhost:8000/GitOps-Starter/docs
6060
- Root endpoint: http://localhost:8000/GitOps-Starter
6161
- Health check: http://localhost:8000/GitOps-Starter/health
6262
- List items: http://localhost:8000/GitOps-Starter/api/items
6363
- Get specific item: http://localhost:8000/GitOps-Starter/api/items/1
6464

65-
## 🧪 Testing
65+
### 🧪 Testing
6666

67-
### Run Tests
67+
#### Run Tests
6868

6969
```bash
7070
pytest
7171
```
7272

73-
### Run Tests with Coverage
73+
#### Run Tests with Coverage
7474

7575
```bash
7676
pytest --cov=app --cov-report=html
7777
```
7878

7979
View the coverage report by opening `htmlcov/index.html` in your browser.
8080

81-
## 🔍 Code Quality
81+
### 🔍 Code Quality
8282

83-
### Linting with Ruff
83+
#### Linting with Ruff
8484

8585
```bash
8686
# Check for issues
@@ -90,7 +90,7 @@ ruff check app/ tests/
9090
ruff check app/ tests/ --fix
9191
```
9292

93-
### Code Formatting with Black
93+
#### Code Formatting with Black
9494

9595
```bash
9696
# Check formatting
@@ -100,12 +100,12 @@ black --check app/ tests/
100100
black app/ tests/
101101
```
102102

103-
## 🪝 Pre-commit Hooks
103+
### 🪝 Pre-commit Hooks
104104

105105
Pre-commit hooks automatically check your code before each commit, ensuring
106106
consistent code quality.
107107

108-
### Setup Pre-commit
108+
#### Setup Pre-commit
109109

110110
```bash
111111
# Install pre-commit
@@ -115,7 +115,7 @@ pip install pre-commit
115115
pre-commit install
116116
```
117117

118-
### Using Pre-commit
118+
#### Using Pre-commit
119119

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

@@ -131,33 +131,33 @@ The pre-commit hooks include:
131131
- Trailing whitespace removal
132132
- End of file fixer
133133

134-
## 🐳 Docker
134+
### 🐳 Docker
135135

136-
### Build the Docker Image
136+
#### Build the Docker Image
137137

138138
```bash
139139
docker build -t fastapi-gitops-starter .
140140
```
141141

142-
### Run the Container
142+
#### Run the Container
143143

144144
```bash
145145
docker run -p 8000:8000 fastapi-gitops-starter
146146
```
147147

148148
Access the API at http://localhost:8000/GitOps-Starter/
149149

150-
## Minikube Setup
150+
### Minikube Setup
151151

152152
If you want to test the Kubernetes deployment locally, you can use Minikube.
153-
### Install Minikube
153+
#### Install Minikube
154154
Follow the instructions at the [Minikube installation guide](https://minikube.sigs.k8s.io/docs/start/).
155-
### Start Minikube with Ingress and Ingress-DNS Addons
155+
#### Start Minikube with Ingress and Ingress-DNS Addons
156156
```bash
157157
minikube start --addons=ingress,ingress-dns
158158
```
159159

160-
### Add Minikube IP to /etc/hosts
160+
#### Add Minikube IP to /etc/hosts
161161
Get the Minikube IP:
162162
```bash
163163
minikube ip
@@ -168,24 +168,24 @@ Add the following line to your `/etc/hosts` file:
168168
Replace `<MINIKUBE_IP>` with the IP address obtained from the previous command.
169169

170170

171-
## ☸️ Kubernetes Deployment with Helm
171+
### ☸️ Kubernetes Deployment with Helm
172172

173173
This repository includes a Helm chart for deploying the application to Kubernetes.
174174

175-
### Prerequisites
175+
#### Prerequisites
176176

177177
- Kubernetes 1.19+
178178
- Helm 3.0+
179179

180-
### Install the Helm Chart
180+
#### Install the Helm Chart
181181

182182
Install the chart:
183183

184184
```bash
185185
helm install my-release ./helm/fastapi-gitops-starter
186186
```
187187

188-
### Uninstall the Helm Chart
188+
#### Uninstall the Helm Chart
189189
To uninstall/delete the deployment:
190190

191191
```bash
@@ -197,9 +197,9 @@ Make sure you understand how to set up the Horizontal Pod Autoscaler (HPA) for
197197
scaling based on load and ingress configuration for accessing the application
198198
including host and paths.
199199

200-
## 📚 Tutorial Exercises
200+
### 📚 Tutorial Exercises
201201

202-
### Exercise 1: Add pre-commit Hooks
202+
#### Exercise 1: Add pre-commit Hooks
203203
1. Open `.pre-commit-config.yaml`
204204
2. Add a new hook to check:
205205
* if we try to commit large files
@@ -209,12 +209,12 @@ including host and paths.
209209
* To make sure we do not commit secrets using
210210
* To check code style
211211

212-
#### Questions
212+
##### Questions
213213
1. What are the benefits of using pre-commit hooks in a project?
214214
2. How can pre-commit hooks improve code quality and consistency?
215215
3. How do you configure pre-commit hooks to run only on specific file types or directories?
216216

217-
### Exercise 2: Add a New Endpoint
217+
#### Exercise 2: Add a New Endpoint
218218

219219
1. Open `app/main.py`
220220
2. Add a new endpoint to create an item:
@@ -234,27 +234,27 @@ async def create_item(name: str, description: str):
234234
3. Write a test in `tests/test_main.py`
235235
4. Run tests to verify
236236

237-
#### Questions
237+
##### Questions
238238
1. How can you ensure that your tests cover edge cases and error scenarios?
239239
2. How do you run tests and view coverage reports?
240240
3. What are the benefits of maintaining high code coverage in a project?
241241
4. What other metrics can be used to assess code quality besides code coverage?
242242

243243

244-
### Exercise 3: Add a CI Pipeline
244+
#### Exercise 3: Add a CI Pipeline
245245

246246
1. Open `.github/workflows/ci-cd.yml`
247247
2. Add a step to lint the code using Ruff
248248
3. Add a step to run tests with coverage. The pipeline should fail if coverage is below 80%
249249
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
250250

251-
#### Questions
251+
##### Questions
252252

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

257-
### Exercise 4: Deploy on a K8s "production" Cluster
257+
#### Exercise 4: Deploy on a K8s "production" Cluster
258258

259259
1. Set up a Kubernetes cluster (e.g., using Minikube or a cloud provider)
260260
2. Deploy the application using the Helm chart
@@ -269,41 +269,41 @@ kubectl get hpa -n default -w
269269
```
270270
7. Note how much time it takes for the pods to scale up and down based on the load
271271

272-
#### Questions
272+
##### Questions
273273
1. The auto-scaling did not work as expected. What could be the possible reasons?
274274
2. How does Horizontal Pod Autoscaling (HPA) work in Kubernetes?
275275
3. How can you add custom metrics for scaling decisions in HPA?
276276
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?
277277
5. What is the difference limits and autoscaling
278278

279279

280-
## 🎓 Learning Resources
280+
### 🎓 Learning Resources
281281

282-
### FastAPI
282+
#### FastAPI
283283
- [Official Documentation](https://fastapi.tiangolo.com/)
284284
- [Tutorial - User Guide](https://fastapi.tiangolo.com/tutorial/)
285285

286-
### GitOps
286+
#### GitOps
287287
- [GitOps Principles](https://www.gitops.tech/)
288288
- [GitHub Actions Documentation](https://docs.github.com/en/actions)
289289

290-
### Code Quality
290+
#### Code Quality
291291
- [Ruff Documentation](https://docs.astral.sh/ruff/)
292292
- [Black Documentation](https://black.readthedocs.io/)
293293
- [Pre-commit Documentation](https://pre-commit.com/)
294294

295-
### Testing
295+
#### Testing
296296
- [Pytest Documentation](https://docs.pytest.org/)
297297

298-
### Docker
298+
#### Docker
299299
- [Docker Documentation](https://docs.docker.com/)
300300

301-
### Kubernetes & Helm
301+
#### Kubernetes & Helm
302302
- [Kubernetes Documentation](https://kubernetes.io/docs/home/)
303303
- [Helm Documentation](https://helm.sh/docs/)
304304
- [Minikube Documentation](https://minikube.sigs.k8s.io/docs/)
305305

306-
## 🤝 Contributing
306+
### 🤝 Contributing
307307

308308
1. Fork the repository
309309
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
@@ -313,7 +313,7 @@ kubectl get hpa -n default -w
313313
6. Ensure all tests pass and code quality checks are successful
314314
7. Merge
315315

316-
## 💡 Tips for Students
316+
### 💡 Tips for Students
317317

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

0 commit comments

Comments
 (0)