diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index a98b15e..61e2748 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.12' + + - name: Install Ruff + run: pip install ruff + + - name: Lint with Ruff + run: ruff check . + 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.12' + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Run tests with coverage + run: pytest --cov=app --cov-fail-under=80 + build: name: Build Docker Image runs-on: ubuntu-latest @@ -40,3 +62,28 @@ 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 metadata for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=raw,value=latest,enable=${{ github.event_name == 'release' }} + type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }} + type=sha,enable=${{ github.event_name == 'push' }} + + - name: Build Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: docker/Dockerfile + push: ${{ github.event_name == 'release' }} + tags: ${{ steps.meta.outputs.tags }} \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/fastapi-gitops.iml b/.idea/fastapi-gitops.iml new file mode 100644 index 0000000..763b4f3 --- /dev/null +++ b/.idea/fastapi-gitops.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/jsonSchemas.xml b/.idea/jsonSchemas.xml new file mode 100644 index 0000000..b7636c2 --- /dev/null +++ b/.idea/jsonSchemas.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6341f53 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f954136 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d337d10..db556b9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,3 +3,27 @@ repos: rev: v5.0.0 hooks: - id: trailing-whitespace + - id: check-added-large-files + - id: check-yaml + exclude: ^helm/ + + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + + - repo: https://github.com/PyCQA/bandit + rev: 1.7.10 + hooks: + - id: bandit + args: ["--exclude", "tests"] + + - 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.6 + hooks: + - id: ruff \ No newline at end of file diff --git a/app/main.py b/app/main.py index ae8adc6..4294526 100644 --- a/app/main.py +++ b/app/main.py @@ -48,6 +48,16 @@ async def get_item(item_id: int): "description": f"This is item number {item_id}", } +@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 + } if __name__ == "__main__": - uvicorn.run(app, host="0.0.0.0", port=8000) + uvicorn.run(app, host="0.0.0.0", port=8000) # nosec B104 + # comment for the commit diff --git a/helm/fastapi-gitops-starter/custom-values.yaml b/helm/fastapi-gitops-starter/custom-values.yaml new file mode 100644 index 0000000..7bdb34f --- /dev/null +++ b/helm/fastapi-gitops-starter/custom-values.yaml @@ -0,0 +1,24 @@ +image: + repository: ghcr.io/kikomiguelmendes/do_2_f + tag: "latest" + pullPolicy: IfNotPresent + +imagePullSecrets: [] + +registry: + createImagePullSecret: false + +ingress: + enabled: true + className: nginx + hosts: + - host: minikube.test + paths: + - path: /GitOps-Starter + pathType: Prefix + +autoscaling: + enabled: true + minReplicas: 1 + maxReplicas: 10 + targetCPUUtilizationPercentage: 10 \ No newline at end of file diff --git a/tests/test_main.py b/tests/test_main.py index db89e2f..dd6b519 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -41,3 +41,12 @@ def test_get_item(): assert data["id"] == 5 assert data["name"] == "Item 5" assert "item number 5" in data["description"] + +def test_create_item(): + response = client.post("/api/items?name=TestItem&description=TestDescription") + assert response.status_code == 200 + data = response.json() + assert data["name"] == "TestItem" + assert data["description"] == "TestDescription" + assert data["created"] is True + assert "id" in data