From 520a5dfbc3d63b579a7a1137f44cbe9c4727e49d Mon Sep 17 00:00:00 2001 From: Hugo Hoang Date: Sat, 7 Mar 2026 14:56:22 +0100 Subject: [PATCH 1/4] Added pre-commit hooks --- .pre-commit-config.yaml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d337d10..650d470 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,3 +3,31 @@ repos: rev: v5.0.0 hooks: - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files + args: ["--maxkb=500"] + - id: check-yaml + exclude: ^helm/ + - id: detect-private-key + + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + name: isort (python) + + - repo: https://github.com/PyCQA/bandit + rev: 1.8.3 + hooks: + - id: bandit + args: ["-r", "app/", "-ll"] + + - repo: https://github.com/Yelp/detect-secrets + rev: v1.5.0 + hooks: + - id: detect-secrets + + - repo: https://github.com/psf/black + rev: 24.10.0 + hooks: + - id: black From bdd95e31b133a6eb36a5568e456224b714d69610 Mon Sep 17 00:00:00 2001 From: Hugo Hoang Date: Sat, 7 Mar 2026 15:41:02 +0100 Subject: [PATCH 2/4] Added new endpoint --- app/main.py | 6 ++++++ tests/test_main.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/main.py b/app/main.py index ae8adc6..ebb7f0a 100644 --- a/app/main.py +++ b/app/main.py @@ -39,6 +39,12 @@ async def list_items(): } +@app.post("/api/items") +async def create_item(name: str, description: str): + """Create a new item.""" + return {"id": 999, "name": name, "description": description, "created": True} + + @app.get("/api/items/{item_id}") async def get_item(item_id: int): """Example endpoint to get a specific item by ID.""" diff --git a/tests/test_main.py b/tests/test_main.py index db89e2f..e3af109 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -41,3 +41,17 @@ def test_get_item(): assert data["id"] == 5 assert data["name"] == "Item 5" assert "item number 5" in data["description"] + + +def test_create_item(): + """Test the create item endpoint.""" + response = client.post( + "/api/items", + params={"name": "Test Item", "description": "A test item"}, + ) + assert response.status_code == 200 + data = response.json() + assert data["id"] == 999 + assert data["name"] == "Test Item" + assert data["description"] == "A test item" + assert data["created"] is True From afac0e4e51b5429d1db751681a3ffb3e27d1a4f2 Mon Sep 17 00:00:00 2001 From: Hugo Hoang Date: Sat, 7 Mar 2026 16:12:33 +0100 Subject: [PATCH 3/4] Added a CI pipeline --- .github/workflows/ci-cd.yml | 55 ++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index a98b15e..083e8b2 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -2,7 +2,7 @@ name: CI/CD Pipeline on: release: - types: [ published ] + types: [published] push: branches: - '**' @@ -19,6 +19,17 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install Ruff + run: pip install ruff==0.8.4 + + - name: Run Ruff linter + run: ruff check app/ tests/ + test: name: Run Tests runs-on: ubuntu-latest @@ -28,6 +39,17 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Run tests with coverage + run: pytest --cov=app --cov-report=term-missing --cov-fail-under=80 + build: name: Build Docker Image runs-on: ubuntu-latest @@ -40,3 +62,34 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + if: github.event_name == 'release' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build Docker image (branch push — no push to registry) + if: github.event_name == 'push' + uses: docker/build-push-action@v6 + with: + context: . + file: docker/Dockerfile + push: false + tags: fastapi-gitops-starter:build + + - name: Build and push Docker image (release) + if: github.event_name == 'release' + uses: docker/build-push-action@v6 + with: + context: . + file: docker/Dockerfile + push: true + tags: | + ghcr.io/${{ github.repository }}:${{ github.event.release.tag_name }} + ghcr.io/${{ github.repository }}:latest From b83e4f0cf5b7e1881589298cbaef5429cfb269ae Mon Sep 17 00:00:00 2001 From: Hugo Hoang Date: Sun, 8 Mar 2026 02:11:02 +0100 Subject: [PATCH 4/4] Added HPA --- custom-values.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 custom-values.yaml diff --git a/custom-values.yaml b/custom-values.yaml new file mode 100644 index 0000000..9ecb48b --- /dev/null +++ b/custom-values.yaml @@ -0,0 +1,19 @@ +replicaCount: 1 + +ingress: + enabled: true + className: "nginx" + hosts: + - host: minikube.test + paths: + - path: /GitOps-Starter + pathType: Prefix + +app: + rootPath: "/GitOps-Starter" + +autoscaling: + enabled: true + minReplicas: 1 + maxReplicas: 10 + targetCPUUtilizationPercentage: 10