Skip to content

Commit ea373f8

Browse files
author
Gpshfrd
committed
add: task 1, task 2
1 parent dbcda73 commit ea373f8

6 files changed

Lines changed: 96 additions & 1 deletion

File tree

.github/workflows/python-ci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Python CI
2+
3+
on:
4+
push:
5+
paths:
6+
- "app_python/**"
7+
- ".github/workflows/python-ci.yml"
8+
pull_request:
9+
paths:
10+
- "app_python/**"
11+
12+
jobs:
13+
test-and-build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repo
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.12"
24+
cache: "pip"
25+
26+
- name: Install dependencies
27+
run: |
28+
pip install -r app_python/requirements.txt
29+
pip install -r app_python/requirements-dev.txt
30+
31+
- name: Run tests
32+
run: |
33+
cd app_python
34+
pytest
35+
36+
- name: gpshfrd
37+
uses: docker/login-action@v3
38+
with:
39+
username: ${{ secrets.DOCKERHUB_USERNAME }}
40+
password: ${{ secrets.DOCKERHUB_TOKEN }}
41+
42+
- name: Build and push Docker image
43+
uses: docker/build-push-action@v6
44+
with:
45+
context: app_python
46+
push: true
47+
tags: |
48+
${{ secrets.DOCKERHUB_USERNAME }}/devops-info-python:${{ env.VERSION }}
49+
${{ secrets.DOCKERHUB_USERNAME }}/devops-info-python:latest

app_python/docs/LAB03.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Overview
2+
Pytest was chosen because it has simple syntax and is well suited for testing Flask applications.
3+
The CI workflow runs on push and pull requests to app_python/.
4+
Calendar Versioning was used because this is a continuously deployed service.
5+
6+
## Workflow Evidence
7+
- GitHub Actions: green successful run
8+
- Docker Hub: image published with tags `latest` and `2026.02`
9+
- Local tests: pytest passed successfully
10+
11+
## Best Practices Implemented
12+
- Dependency caching to speed up CI runs
13+
- Fail fast strategy: Docker build runs only after tests pass
14+
- Secrets used for Docker Hub authentication
15+
16+
## Challenges
17+
- Initial test client setup for Flask
18+
- Fixing import paths for pytest
19+
- Docker authentication in CI
20+
- The issue occurred because pytest was executed using the global installation instead of the virtual environment. Running tests via python -m pytest ensured correct dependency resolution.
64.4 KB
Loading

app_python/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Flask==3.1.0
1+
Flask==3.1.0
2+
pytest

app_python/tests/test_health.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from app import app
2+
3+
def test_health_endpoint():
4+
client = app.test_client()
5+
response = client.get('/health')
6+
7+
assert response.status_code == 200
8+
9+
data = response.get_json()
10+
assert data["status"] == "healthy"

app_python/tests/test_root.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import json
2+
from app import app
3+
4+
def test_root_endpoint():
5+
client = app.test_client()
6+
response = client.get('/')
7+
8+
assert response.status_code == 200
9+
10+
data = response.get_json()
11+
assert isinstance(data, dict)
12+
13+
assert "service" in data
14+
assert "system" in data
15+
assert "runtime" in data

0 commit comments

Comments
 (0)