From 8dd4d1dfb0122a67284fdf8662815c6a8061ab42 Mon Sep 17 00:00:00 2001 From: raluc12 Date: Sat, 14 Mar 2026 23:45:50 +0100 Subject: [PATCH 1/3] Add amazing feature --- .github/workflows/markdown2pdf.yml | 2 +- README.md | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/markdown2pdf.yml b/.github/workflows/markdown2pdf.yml index fcb4671..4177b58 100644 --- a/.github/workflows/markdown2pdf.yml +++ b/.github/workflows/markdown2pdf.yml @@ -19,7 +19,7 @@ jobs: - name: Replace links run: | - cp README.md README_WITH_LINKS.md + cp README.md README_WITH_LINKS.md sed -i -e "s#\(^\!\[[^]]\+\](\)\(images/\)#\1$URL/\2#g" README_WITH_LINKS.md for file in sources/*; do sed -i -e "s#($file)#($URL/$file)#g" README_WITH_LINKS.md ; done diff --git a/README.md b/README.md index 79bb814..057f54d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ GitOps with FastAPI ***University of Amsterdam*** -# 1. Introduction +# 1. Introduction In this tutorial, we use GitOps practices with FastAPI, including CI/CD pipelines, code quality tools, and automated testing. @@ -35,7 +35,7 @@ In this tutorial, we use GitOps practices with FastAPI, including CI/CD pipeline -# 2. Tutorial +# 2. Tutorial The steps of this tutorial are as follows: - [Building REST APIs with FastAPI](#21-setting-up-the-project) @@ -60,17 +60,17 @@ Prerequisites: ``` * Set Up the Python Environmentt: - + ```bash # Create a virtual environment python -m venv venv - + # Activate the virtual environment # On Linux/MacOS: source venv/bin/activate # On Windows: venv\Scripts\activate - + # Install dependencies pip install -r requirements.txt ``` @@ -110,7 +110,7 @@ Prerequisites: ```bash # Check for issues ruff check app/ tests/ - + # Fix auto-fixable issues ruff check app/ tests/ --fix ``` @@ -120,7 +120,7 @@ Prerequisites: ```bash # Check formatting black --check app/ tests/ - + # Format code black app/ tests/ ``` @@ -134,7 +134,7 @@ Pre-commit hooks automatically run checks before each commit to ensure consisten ```bash # Install pre-commit pip install pre-commit - + # Install the git hooks pre-commit install ``` @@ -142,11 +142,11 @@ Pre-commit hooks automatically run checks before each commit to ensure consisten * Using Pre-commit: Pre-commit will now run automatically on `git commit`. You can also run it manually: - + ```bash # Run on all files pre-commit run --all-files - + # Run on staged files pre-commit run ``` @@ -200,14 +200,14 @@ This repository includes a Helm chart for deploying the application to Kubernete - Kubernetes 1.19+ - Helm 3.0+ -* Install the Helm Chart: +* Install the Helm Chart: ```bash helm install my-release ./helm/fastapi-gitops-starter ``` -* Uninstall the Helm Chart: - +* Uninstall the Helm Chart: + ```bash helm uninstall my-release ``` @@ -239,7 +239,7 @@ including host and paths. * To make sure we do not commit secrets * To check code style - + ## 3.2 Add a New Endpoint 1. Open `app/main.py` From dc9c30b70c50f62fe196c72256cab2c73642e8f9 Mon Sep 17 00:00:00 2001 From: raluc12 Date: Sun, 15 Mar 2026 16:43:10 +0100 Subject: [PATCH 2/3] pre commit hooks + ci + endpoint + k8 --- .github/workflows/ci-cd.yml | 50 ++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 27 +++++++++++++++++++ .secrets.baseline | Bin 0 -> 11286 bytes app/main.py | 11 ++++++++ custom-values.yaml | 13 ++++++++++ tests/test_main.py | 11 ++++++++ 6 files changed, 112 insertions(+) create mode 100644 .secrets.baseline create mode 100644 custom-values.yaml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index a98b15e..bacc12d 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -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 + + - name: Lint with Ruff + 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,31 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract image metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + # tag with version and 'latest' on release + type=semver,pattern={{version}} + type=semver,pattern=latest + # tag with short commit SHA on regular pushes + type=sha + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + # only push on release, just build on regular pushes + push: ${{ github.event_name == 'release' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d337d10..0da5279 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,3 +3,30 @@ repos: rev: v5.0.0 hooks: - id: trailing-whitespace + - id: check-added-large-files + - id: check-yaml + args: ['--unsafe'] + exclude: ^helm/ + + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + + # - repo: https://github.com/returntocorp/semgrep + # rev: v1.68.0 + # hooks: + # - id: semgrep + # args: ['--config', 'p/python', '--error'] + + - repo: https://github.com/Yelp/detect-secrets + rev: v1.5.0 + hooks: + - id: detect-secrets + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.8.4 + hooks: + - id: ruff + args: [--fix] + - id: ruff-format \ No newline at end of file diff --git a/.secrets.baseline b/.secrets.baseline new file mode 100644 index 0000000000000000000000000000000000000000..95da0e06fc67c83e010ad04470f52dc3332db022 GIT binary patch literal 11286 zcmeI2Yi}Ay6o%(>rTz!R=VEa;&Nrv2V)qtHwp6KUg)qCuC>SVUC$#ckZ}Pk|jM?=< zgMo>OU9A>|*}0u_-g(bCvwZyb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hs!3wfjkb<0TK2U+o>k~^4)S6ywYdOIjYq*>ErqsK@TVQwgQLV{!oIvz z%bo@lK$XMTkXmt}p6CsN@UHg4u9!vK99srd45T(wetCagpvLj(lrgmT(k!~GEV)~n zSs&M8(=zrcf>QBj9eb3(Yz>qi@TAITl{%fBh)rvJR%unGPn~xA)CcC$qycID+bWpyT@U? z#sbD$A2Z3fp1H(H|8m)UCU`%4_W8Zyn;4+9BzOZa9Ed(_1Fv7|?sBpHIzf3?f@ujKYrxC}!G&2mYyCYxh~v)J?YeaocJ?ox+}RdV2`5UZun zH;3i?wnOo@-_Ik?IYo7c(g@G2 Date: Sun, 15 Mar 2026 16:51:40 +0100 Subject: [PATCH 3/3] fix dockerfile paths and dockerignore location --- Dockerfile | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..122b346 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# Use Python 3.11 slim image as base +FROM python:3.11-slim + +# Set working directory +WORKDIR /app + +# Install dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy application code +COPY app ./app/ + +# Expose port 8000 +EXPOSE 8000 + +# Run the application +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] + +# Copy application code +COPY ../app ./app/ + +# Expose port 8000 +EXPOSE 8000 + +# Run the application +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]