From 4fd9fc62212f2a4dd760cacbc5d984a43fd557f6 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 17:26:28 -0500 Subject: [PATCH 01/53] fix: update delete_post endpoint to include db dependency and add initial tests for main route --- papi.py | 4 ++-- test_papi.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test_papi.py diff --git a/papi.py b/papi.py index bda569c..3b4fbd9 100644 --- a/papi.py +++ b/papi.py @@ -92,8 +92,8 @@ async def update_post(id: str, post: dict,db: Session = Depends(get_db)): db.refresh(db_post) return {"message":"Post updated successfully","post":db_post} -@app.delete("/posts/{id}",db: Session = Depends(get_db)) -async def delete_post(id: str, post: dict): +@app.delete("/posts/{id}") +async def delete_post(id: str, post: dict,db: Session = Depends(get_db)): db_post = db.query(Post).filter(Post.id == id).first() db.delete(db_post) db.commit() diff --git a/test_papi.py b/test_papi.py new file mode 100644 index 0000000..a244f7d --- /dev/null +++ b/test_papi.py @@ -0,0 +1,12 @@ +#!/bin/env python3 + +from fastapi.testclient import TestClient + +import papi +client = TestClient(papi) + + +def test_read_main(): + response = client.get("/") + assert response.status_code == 200 + assert response.json() == {"message": "Hello World"} \ No newline at end of file From dfacc384d580d0eef74c4cd3bfdbbe1983b77a19 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 20:41:36 -0500 Subject: [PATCH 02/53] feat: add deployment step to build and push workflow using Helm --- .gitea/workflows/build-and-push.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 3db58d9..975367c 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -26,4 +26,12 @@ jobs: - run: docker login kube-reg.fairfaxmedia.net -u docker -p ${{ secrets.DOCK_REG_AUTH }} # Login to private registry - run: docker build -t kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} . # Build the Docker image - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image + - name: 'Deploy' + uses: deliverybot/helm@v1 + with: + release: 'nginx' + namespace: 'default' + chart: 'papi-helm' + env: + KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}' From e9c88d14ceb496cbf82444c64d8b7bc5a1c1768a Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 20:44:22 -0500 Subject: [PATCH 03/53] feat: add helm upgrade command to build and push workflow for deployment --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 975367c..ebac294 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -34,4 +34,4 @@ jobs: chart: 'papi-helm' env: KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}' - + run: helm upgrade papi ./papi-helm/ --install --namespace default --set image.tag=${{ steps.extract_branch.outputs.branch }} --kubeconfig $KUBECONFIG_FILE From 81a48930960c384a92111989f4aaf9d9fd4c66a9 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 20:47:51 -0500 Subject: [PATCH 04/53] fix: remove redundant Helm action from build and push workflow --- .gitea/workflows/build-and-push.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index ebac294..ed5643e 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -27,11 +27,6 @@ jobs: - run: docker build -t kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} . # Build the Docker image - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image - name: 'Deploy' - uses: deliverybot/helm@v1 - with: - release: 'nginx' - namespace: 'default' - chart: 'papi-helm' env: KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}' run: helm upgrade papi ./papi-helm/ --install --namespace default --set image.tag=${{ steps.extract_branch.outputs.branch }} --kubeconfig $KUBECONFIG_FILE From ecd679cbf469d56a921d698f3dc91343857c095b Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 20:53:52 -0500 Subject: [PATCH 05/53] feat: update build and push workflow to use Helm for deployment --- .gitea/workflows/build-and-push.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index ed5643e..069232c 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -27,6 +27,12 @@ jobs: - run: docker build -t kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} . # Build the Docker image - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image - name: 'Deploy' + uses: deliverybot/helm@v1 + with: + release: 'papi' + namespace: 'default' + chart: 'papi-helm/Chart.yaml' + token: '${{ github.token }}' + value-files: ['papi-helm/values.yaml'] env: KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}' - run: helm upgrade papi ./papi-helm/ --install --namespace default --set image.tag=${{ steps.extract_branch.outputs.branch }} --kubeconfig $KUBECONFIG_FILE From 5139e277a43bea97ed5d69bd67f84c748fb4d4bb Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 20:56:06 -0500 Subject: [PATCH 06/53] fix: remove unnecessary blank line in build and push workflow configuration --- .gitea/workflows/build-and-push.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 069232c..acb115e 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -13,7 +13,6 @@ on: - qa - jobs: build: runs-on: ubuntu-latest From 9a17f836108dc0b36a9333882ed8d6adf1b6521e Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 20:56:56 -0500 Subject: [PATCH 07/53] fix: rename workflow to Build and Push to Private Registry2 --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index acb115e..e1a6ee5 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -2,7 +2,7 @@ -name: Build and Push to Private Registry +name: Build and Push to Private Registry2 on: From f9c7e45dbdc744cadfeb05773e718192b29e9cf0 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 20:58:30 -0500 Subject: [PATCH 08/53] fix: rename workflow to Build and Push to Private Registry3 --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index e1a6ee5..0a87a7f 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -2,7 +2,7 @@ -name: Build and Push to Private Registry2 +name: Build and Push to Private Registry3 on: From 5589fc3a755d528bfb14771d0c6bbe25c0dceb52 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:02:52 -0500 Subject: [PATCH 09/53] fix: rename workflow to Build and Push to Private Registry and update Helm deployment action --- .gitea/workflows/build-and-push.yaml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 0a87a7f..d5045c7 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -2,7 +2,7 @@ -name: Build and Push to Private Registry3 +name: Build and Push to Private Registry on: @@ -13,6 +13,7 @@ on: - qa + jobs: build: runs-on: ubuntu-latest @@ -26,12 +27,12 @@ jobs: - run: docker build -t kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} . # Build the Docker image - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image - name: 'Deploy' - uses: deliverybot/helm@v1 + uses: 'peter-evans/k8s-deploy@v1' with: release: 'papi' namespace: 'default' chart: 'papi-helm/Chart.yaml' - token: '${{ github.token }}' - value-files: ['papi-helm/values.yaml'] + values: 'papi-helm/values.yaml' env: - KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}' + KUBECONFIG_FILE: '${{ secrets.KUBECONFIG}}' + From 8c8bc5f30e727df42d5e0e3a0b519684626b7e58 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:07:03 -0500 Subject: [PATCH 10/53] feat: update deployment process to use Helm for chart installation --- .gitea/workflows/build-and-push.yaml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index d5045c7..b8312c2 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -26,13 +26,7 @@ jobs: - run: docker login kube-reg.fairfaxmedia.net -u docker -p ${{ secrets.DOCK_REG_AUTH }} # Login to private registry - run: docker build -t kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} . # Build the Docker image - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image - - name: 'Deploy' - uses: 'peter-evans/k8s-deploy@v1' - with: - release: 'papi' - namespace: 'default' - chart: 'papi-helm/Chart.yaml' - values: 'papi-helm/values.yaml' - env: + - env: KUBECONFIG_FILE: '${{ secrets.KUBECONFIG}}' + run: curl https://fairfaxmedia.net/helm -O /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From 2ab68111d5e39f83e7d54c7ef2d42961b61dd6cb Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:07:57 -0500 Subject: [PATCH 11/53] fix: remove redundant Helm deployment step from build and push workflow --- .gitea/workflows/build-and-push.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index b8312c2..d54cc5e 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -25,8 +25,4 @@ jobs: - uses: actions/checkout@v3 - run: docker login kube-reg.fairfaxmedia.net -u docker -p ${{ secrets.DOCK_REG_AUTH }} # Login to private registry - run: docker build -t kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} . # Build the Docker image - - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image - - env: - KUBECONFIG_FILE: '${{ secrets.KUBECONFIG}}' - run: curl https://fairfaxmedia.net/helm -O /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char - + - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image \ No newline at end of file From 45f32222b778b562027a5c467ac39ed04742b110 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:08:33 -0500 Subject: [PATCH 12/53] feat: add Helm deployment step to build and push workflow --- .gitea/workflows/build-and-push.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index d54cc5e..cc37330 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -25,4 +25,8 @@ jobs: - uses: actions/checkout@v3 - run: docker login kube-reg.fairfaxmedia.net -u docker -p ${{ secrets.DOCK_REG_AUTH }} # Login to private registry - run: docker build -t kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} . # Build the Docker image - - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image \ No newline at end of file + - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image + - env: + KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}' + run: curl https://fairfaxmedia.net/helm -O /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char + From 142e4736cad3745b7a032f693c9eecc35c7664aa Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:09:42 -0500 Subject: [PATCH 13/53] fix: correct curl command option for Helm installation in build and push workflow --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index cc37330..d42eab3 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -28,5 +28,5 @@ jobs: - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image - env: KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}' - run: curl https://fairfaxmedia.net/helm -O /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char + run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From d13d06b1f9dfd6d446795f353a538b96b452fefd Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:10:56 -0500 Subject: [PATCH 14/53] fix: add kubeconfig option to Helm upgrade command in build and push workflow --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index d42eab3..96d84f9 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -28,5 +28,5 @@ jobs: - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image - env: KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}' - run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char + run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} --kubeconfig $KUBECONFIG # Deploy the Helm char From d32800f71866006339a89e75e92fd9977eac6fb7 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:13:48 -0500 Subject: [PATCH 15/53] fix: reorder kubeconfig option in Helm upgrade command in build and push workflow --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 96d84f9..4819b67 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -28,5 +28,5 @@ jobs: - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image - env: KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}' - run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} --kubeconfig $KUBECONFIG # Deploy the Helm char + run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm --kubeconfig $KUBECONFIG upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From 22ad8be19ddfd38e063631aa2eb6b8bb1ca3e473 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:14:35 -0500 Subject: [PATCH 16/53] fix: update KUBECONFIG variable reference in Helm upgrade command in build and push workflow --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 4819b67..78b61f1 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -28,5 +28,5 @@ jobs: - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image - env: KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}' - run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm --kubeconfig $KUBECONFIG upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char + run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm --kubeconfig $KUBECONFIG_FILE upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From c6ccb18c4f27b83a2bd75b7e660c67697a9cba0f Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:25:59 -0500 Subject: [PATCH 17/53] fix: update KUBECONFIG variable and streamline Helm upgrade command in build and push workflow --- .gitea/workflows/build-and-push.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 78b61f1..f252f17 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -27,6 +27,6 @@ jobs: - run: docker build -t kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} . # Build the Docker image - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image - env: - KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}' - run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm --kubeconfig $KUBECONFIG_FILE upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char + KUBECONFIG: '${{ secrets.KUBECONFIG }}' + run: echo "curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --kubeconfig /run/secrets/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From 48a4c2d13f15689b7d83c79ff1100bdb72b28b78 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:26:45 -0500 Subject: [PATCH 18/53] fix: remove unnecessary echo command in Helm upgrade step of build and push workflow --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index f252f17..3eefd30 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -28,5 +28,5 @@ jobs: - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image - env: KUBECONFIG: '${{ secrets.KUBECONFIG }}' - run: echo "curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --kubeconfig /run/secrets/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char + run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --kubeconfig /run/secrets/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From d6a886f9ab7ba5d6dff4fc2561a095ea9b2e457b Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:27:33 -0500 Subject: [PATCH 19/53] fix: comment out Helm upgrade command for debugging in build and push workflow --- .gitea/workflows/build-and-push.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 3eefd30..e9fa517 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -28,5 +28,6 @@ jobs: - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image - env: KUBECONFIG: '${{ secrets.KUBECONFIG }}' - run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --kubeconfig /run/secrets/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char + run: ls -lh /run/secrets + #run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --kubeconfig /run/secrets/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From c2317b07765f5087076dbf0194526403829f92f0 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:29:02 -0500 Subject: [PATCH 20/53] fix: add descriptive names to Docker registry steps in build and push workflow --- .gitea/workflows/build-and-push.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index e9fa517..cd4f42a 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -24,10 +24,13 @@ jobs: id: extract_branch - uses: actions/checkout@v3 - run: docker login kube-reg.fairfaxmedia.net -u docker -p ${{ secrets.DOCK_REG_AUTH }} # Login to private registry + name: Login to private registry - run: docker build -t kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} . # Build the Docker image + name: Build Docker image - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image + name: Push Docker image - env: KUBECONFIG: '${{ secrets.KUBECONFIG }}' - run: ls -lh /run/secrets + run: sleep 1800 #run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --kubeconfig /run/secrets/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From f12c4bbde420429b0eef346c522982c6f3ed6562 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:38:53 -0500 Subject: [PATCH 21/53] fix: update Helm installation steps and adjust KUBECONFIG handling in build and push workflow --- .gitea/workflows/build-and-push.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index cd4f42a..43176e8 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -31,6 +31,8 @@ jobs: name: Push Docker image - env: KUBECONFIG: '${{ secrets.KUBECONFIG }}' - run: sleep 1800 - #run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --kubeconfig /run/secrets/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char + run: echo $KUBECONFIG > /run/secrets/kubeconfig + #run: sleep 1800 + run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm + run: /usr/local/bin/helm upgrade --kubeconfig /run/secrets/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From 2f0a4a49d38739310a40cf8b5e136edbb530c490 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:39:48 -0500 Subject: [PATCH 22/53] fix: correct workflow name in build and push configuration --- .gitea/workflows/build-and-push.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 43176e8..b9b7247 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -2,7 +2,7 @@ -name: Build and Push to Private Registry +name: Build and Push to Private Registry4 on: @@ -36,3 +36,4 @@ jobs: run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm run: /usr/local/bin/helm upgrade --kubeconfig /run/secrets/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char + From 45e431e84074da3c45ece02ac5724d3ec53e5cd8 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:40:17 -0500 Subject: [PATCH 23/53] fix: correct workflow name in build and push configuration --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index b9b7247..dd09d65 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -2,7 +2,7 @@ -name: Build and Push to Private Registry4 +name: Build and Push to Private Registry on: From 3eb4cdb90cf3fefdadb11e39985f1df8502e68a1 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:42:03 -0500 Subject: [PATCH 24/53] fix: update workflow name in build and push configuration --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index dd09d65..136fe05 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -2,7 +2,7 @@ -name: Build and Push to Private Registry +name: Build and Push to Private Registry5 on: From 313ec0eb83130eae2b1830cf94536ad719dfbd8a Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:44:25 -0500 Subject: [PATCH 25/53] fix: update workflow name in build and push configuration --- .gitea/workflows/build-and-push.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 136fe05..817a4ba 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -2,8 +2,7 @@ -name: Build and Push to Private Registry5 - +name: Build and Push to Private Registry11 on: push: From 90d40025e2208d6b2716e81c5bf148e20fd74527 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:46:33 -0500 Subject: [PATCH 26/53] fix: streamline Helm installation and deployment commands in build and push workflow --- .gitea/workflows/build-and-push.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 817a4ba..00bf49c 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -30,9 +30,8 @@ jobs: name: Push Docker image - env: KUBECONFIG: '${{ secrets.KUBECONFIG }}' - run: echo $KUBECONFIG > /run/secrets/kubeconfig - #run: sleep 1800 - run: curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm - run: /usr/local/bin/helm upgrade --kubeconfig /run/secrets/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char + run: echo $KUBECONFIG > /run/secrets/kubeconfig && \ + curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && \ + /usr/local/bin/helm upgrade --kubeconfig /run/secrets/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From f6341b42d7ea2a3cdce1f8e252806d99d7daa69f Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:47:18 -0500 Subject: [PATCH 27/53] fix: update workflow name in build and push configuration --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 00bf49c..5a26482 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -2,7 +2,7 @@ -name: Build and Push to Private Registry11 +name: Build and Push to Private Registry101 on: push: From 869d00dbc3a88ae562f92653729abe40acd92662 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:48:18 -0500 Subject: [PATCH 28/53] fix: update kubeconfig path in Helm deployment commands --- .gitea/workflows/build-and-push.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 5a26482..2be7395 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -30,8 +30,8 @@ jobs: name: Push Docker image - env: KUBECONFIG: '${{ secrets.KUBECONFIG }}' - run: echo $KUBECONFIG > /run/secrets/kubeconfig && \ + run: echo $KUBECONFIG > /tmp/kubeconfig && \ curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && \ - /usr/local/bin/helm upgrade --kubeconfig /run/secrets/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char + /usr/local/bin/helm upgrade --kubeconfig /tmp/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From d96799e32a2ecdf6dcd99f42d45a01669363b348 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:49:07 -0500 Subject: [PATCH 29/53] fix: format Helm deployment command for better readability --- .gitea/workflows/build-and-push.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 2be7395..24b0e55 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -30,8 +30,8 @@ jobs: name: Push Docker image - env: KUBECONFIG: '${{ secrets.KUBECONFIG }}' - run: echo $KUBECONFIG > /tmp/kubeconfig && \ - curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && \ + run: echo $KUBECONFIG > /tmp/kubeconfig && + curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --kubeconfig /tmp/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From 70b282c14f79840d299b295a57d9e883e919a83d Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:50:21 -0500 Subject: [PATCH 30/53] fix: update kubeconfig path and streamline Helm upgrade command in build workflow --- .gitea/workflows/build-and-push.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 24b0e55..7489bd1 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -30,8 +30,8 @@ jobs: name: Push Docker image - env: KUBECONFIG: '${{ secrets.KUBECONFIG }}' - run: echo $KUBECONFIG > /tmp/kubeconfig && + run: echo $KUBECONFIG > .kube/config && curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && - /usr/local/bin/helm upgrade --kubeconfig /tmp/kubeconfig --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char + /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From 035bf6c5192f1ad63ec4d2bb00f79d05cc32f4e1 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:51:06 -0500 Subject: [PATCH 31/53] fix: update kubeconfig path in build workflow to use HOME directory --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 7489bd1..0a1cfbe 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -30,7 +30,7 @@ jobs: name: Push Docker image - env: KUBECONFIG: '${{ secrets.KUBECONFIG }}' - run: echo $KUBECONFIG > .kube/config && + run: echo $KUBECONFIG > $HOME/.kube/config && curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From 6905e3528cbcb3ae81382d68251d1c4599050618 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:51:43 -0500 Subject: [PATCH 32/53] fix: ensure .kube directory exists before writing kubeconfig in build workflow --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 0a1cfbe..2238e11 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -30,7 +30,7 @@ jobs: name: Push Docker image - env: KUBECONFIG: '${{ secrets.KUBECONFIG }}' - run: echo $KUBECONFIG > $HOME/.kube/config && + run: mkdir -p $HOME/.kube &&echo $KUBECONFIG > $HOME/.kube/config && curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From 4a2f612192f42ef12969337e30dd476000c74da5 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:54:56 -0500 Subject: [PATCH 33/53] fix: update KUBECONFIG to use base64 encoded value in build workflow --- .gitea/workflows/build-and-push.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 2238e11..17dfa0f 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -29,8 +29,8 @@ jobs: - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image name: Push Docker image - env: - KUBECONFIG: '${{ secrets.KUBECONFIG }}' - run: mkdir -p $HOME/.kube &&echo $KUBECONFIG > $HOME/.kube/config && + KUBECONFIG: '${{ secrets.KUBEB64 }}' + run: mkdir -p $HOME/.kube &&echo "$KUBECONFIG" | base64 -d > $HOME/.kube/config && curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char From 5e1416c0b8880e7b0f2157b45a73edf37ebc1067 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:56:21 -0500 Subject: [PATCH 34/53] fix: correct typo in Helm upgrade command comment in build workflow --- .gitea/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 17dfa0f..48db5cb 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -32,6 +32,6 @@ jobs: KUBECONFIG: '${{ secrets.KUBEB64 }}' run: mkdir -p $HOME/.kube &&echo "$KUBECONFIG" | base64 -d > $HOME/.kube/config && curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && - /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm char + /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm chart From 53524eed52fb24fb0ef85855687307ce0e40d136 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 21:57:08 -0500 Subject: [PATCH 35/53] fix: update environment variable name for base64 KUBECONFIG in build workflow --- .gitea/workflows/build-and-push.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index 48db5cb..c99725e 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -29,8 +29,8 @@ jobs: - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image name: Push Docker image - env: - KUBECONFIG: '${{ secrets.KUBEB64 }}' - run: mkdir -p $HOME/.kube &&echo "$KUBECONFIG" | base64 -d > $HOME/.kube/config && + KUBEB64: '${{ secrets.KUBEB64 }}' + run: mkdir -p $HOME/.kube &&echo "$KUBEB64" | base64 -d > $HOME/.kube/config && curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm chart From d4b5752a1e47e260094acd16624a3a542adc6fcb Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 22:03:13 -0500 Subject: [PATCH 36/53] fix: comment out Helm upgrade command in build workflow --- .gitea/workflows/build-and-push.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index c99725e..b29285e 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -28,10 +28,10 @@ jobs: name: Build Docker image - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image name: Push Docker image - - env: - KUBEB64: '${{ secrets.KUBEB64 }}' - run: mkdir -p $HOME/.kube &&echo "$KUBEB64" | base64 -d > $HOME/.kube/config && - curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && - /usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm chart + #- env: + #KUBEB64: '${{ secrets.KUBEB64 }}' + #run: mkdir -p $HOME/.kube &&echo "$KUBEB64" | base64 -d > $HOME/.kube/config && + #curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && + #/usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm chart From eca4c72c0a306ababd0b8933506ce2d5c5a9022d Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Sun, 16 Feb 2025 22:16:14 -0500 Subject: [PATCH 37/53] feat: refactor build and deployment scripts; update service type to ClusterIP and add ingress configurations --- build.sh | 9 --------- deploy.dev.sh | 2 ++ papi-helm/v.dev.yaml | 7 +++++++ papi-helm/v.prod.yaml | 11 +++++++++++ papi-helm/v.qa.yaml | 7 +++++++ papi-helm/values.yaml | 12 +----------- 6 files changed, 28 insertions(+), 20 deletions(-) delete mode 100644 build.sh create mode 100644 deploy.dev.sh create mode 100644 papi-helm/v.dev.yaml create mode 100644 papi-helm/v.prod.yaml create mode 100644 papi-helm/v.qa.yaml diff --git a/build.sh b/build.sh deleted file mode 100644 index 8f2d93b..0000000 --- a/build.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -REG=192.168.1.134:5000 -NS=papi -IMG=svc1 -TAG=dev -DIMG=${REG}/${NS}/${IMG}:${TAG} -docker build -f Dockerfile -t ${DIMG} . - -docker push ${DIMG} \ No newline at end of file diff --git a/deploy.dev.sh b/deploy.dev.sh new file mode 100644 index 0000000..1c4056c --- /dev/null +++ b/deploy.dev.sh @@ -0,0 +1,2 @@ +#!/bin/bash +helm upgrade papi ./papi-helm/ -f ./papi-helm/v.dev.yaml diff --git a/papi-helm/v.dev.yaml b/papi-helm/v.dev.yaml new file mode 100644 index 0000000..bae8507 --- /dev/null +++ b/papi-helm/v.dev.yaml @@ -0,0 +1,7 @@ +ingress: + enabled: true + hosts: + - host: papi.kube-dev.fairfaxmedia.net + paths: + - path: / + pathType: ImplementationSpecific \ No newline at end of file diff --git a/papi-helm/v.prod.yaml b/papi-helm/v.prod.yaml new file mode 100644 index 0000000..e5a0d41 --- /dev/null +++ b/papi-helm/v.prod.yaml @@ -0,0 +1,11 @@ +ingress: + enabled: true + hosts: + - host: papi.fairfaxmedia.net + paths: + - path: / + pathType: ImplementationSpecific + - host: papi.kube.fairfaxmedia.net + paths: + - path: / + pathType: ImplementationSpecific \ No newline at end of file diff --git a/papi-helm/v.qa.yaml b/papi-helm/v.qa.yaml new file mode 100644 index 0000000..5c76701 --- /dev/null +++ b/papi-helm/v.qa.yaml @@ -0,0 +1,7 @@ +ingress: + enabled: true + hosts: + - host: papi.kube-qa.fairfaxmedia.net + paths: + - path: / + pathType: ImplementationSpecific \ No newline at end of file diff --git a/papi-helm/values.yaml b/papi-helm/values.yaml index 4213baf..ac886a9 100644 --- a/papi-helm/values.yaml +++ b/papi-helm/values.yaml @@ -52,7 +52,7 @@ securityContext: {} # This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/ service: # This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types - type: NodePort + type: ClusterIP # This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports port: 8912 @@ -63,16 +63,6 @@ ingress: annotations: {} # kubernetes.io/ingress.class: nginx # kubernetes.io/tls-acme: "true" - hosts: - - host: papi.fairfaxmedia.net - paths: - - path: / - pathType: ImplementationSpecific - - - host: papi.kube-dev.fairfaxmedia.net - paths: - - path: / - pathType: ImplementationSpecific tls: [] # - secretName: chart-example-tls # hosts: From b3e3d4a6a1d82002f3448e0ae286e8a121f11c66 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Mon, 17 Feb 2025 14:26:17 -0500 Subject: [PATCH 38/53] feat: implement CRUD operations for users and posts; add tests and coverage reporting --- .gitignore | 3 ++ Makefile | 19 ++++++++++ hopscotch_collection.json | 1 + papi.py | 42 ++++++++++++++++------ test_papi.py | 73 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 124 insertions(+), 14 deletions(-) create mode 100644 Makefile create mode 100644 hopscotch_collection.json diff --git a/.gitignore b/.gitignore index 597be97..391f3a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ __pycache__ test.db +.coverage +report.xml +coverage.xml \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8b9a1f0 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +ENV=dev +VER=2 +TAG=${ENV}-${VER} +REGISTRY=kube-reg.fairfaxmedia.net +SVC=papi/svc1 +DOCK_IMG=${REGISTRY}/${SVC}:${TAG} +clean: + rm -rf .pytest_cache + rm -rf .coverage + rm -rf report.xml + rm -rf test.db +coverage: clean + pytest --cov=papi test_papi.py --junitxml=report.xml --cov-report=html --cov-report=xml --cov-report=term --cov-fail-under 90 +docker-img: coverage + docker build -t ${DOCK_IMG} . +docker-push: docker-img + docker push ${DOCK_IMG} +deploy: docker-push + helm upgrade papi ./papi-helm/ -f ./papi-helm/v.${ENV}.yaml --set image.tag=${TAG} \ No newline at end of file diff --git a/hopscotch_collection.json b/hopscotch_collection.json new file mode 100644 index 0000000..42c3ab5 --- /dev/null +++ b/hopscotch_collection.json @@ -0,0 +1 @@ +{"v":1,"name":"test_assignment","folders":[{"v":1,"name":"users","folders":[],"requests":[{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/users","name":"list_users","params":[],"headers":[],"method":"GET","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":null,"body":null}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/users","name":"create_user","params":[],"headers":[],"method":"POST","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"name\":\"test2\",\n \"email\":\"mynameisdeleted@gmail.com\",\n \"password\":\"pass2\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/users/1","name":"update_user","params":[],"headers":[],"method":"PUT","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"name\":\"new name\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/users/1","name":"delete_user","params":[],"headers":[],"method":"DELETE","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"name\":\"new name\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/users/1","name":"get_user","params":[],"headers":[],"method":"GET","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":null,"body":null}}]},{"v":1,"name":"posts","folders":[],"requests":[{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/posts","name":"list_posts","params":[],"headers":[],"method":"GET","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"name\":\"new name\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/posts","name":"create_post","params":[],"headers":[],"method":"POST","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"title\":\"test title\",\n \"content\":\"testing123\",\n \"author_id\":\"1\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/posts/1","name":"get_post","params":[],"headers":[],"method":"GET","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"name\":\"new name\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/posts/1","name":"update_post","params":[],"headers":[],"method":"PUT","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"title\":\"new title\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/posts/1","name":"delete_post","params":[],"headers":[],"method":"DELETE","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"title\":\"new title\"\n}"}}]}],"requests":[]} \ No newline at end of file diff --git a/papi.py b/papi.py index 3b4fbd9..4925f3c 100644 --- a/papi.py +++ b/papi.py @@ -2,9 +2,8 @@ from fastapi import FastAPI, Depends import uvicorn from sqlalchemy import create_engine, Column, Integer,String, ForeignKey -from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.engine import URL -from sqlalchemy.orm import sessionmaker, Session +from sqlalchemy.orm import sessionmaker, Session, declarative_base @@ -30,6 +29,7 @@ class User(Base): email = Column(String, unique=True, index=True) password = Column(String) + class Post(Base): __tablename__ = "posts" id = Column(Integer, primary_key=True, index=True) @@ -50,10 +50,11 @@ async def root(): @app.get("/users") async def get_users(db: Session = Depends(get_db)): return db.query(User).all() - #return [{"id":"asdf1234"}] + @app.get("/users/{id}") -async def get_user(id: str): - return {"id": id} +async def get_user(id: str,db: Session = Depends(get_db)): + db_user = db.query(User).filter(User.id == id).first() + return db_user @app.post("/users") async def create_user(user: dict,db: Session = Depends(get_db)): @@ -64,6 +65,30 @@ async def create_user(user: dict,db: Session = Depends(get_db)): db.refresh(db_user) return {"message":"User created successfully","user":db_user} +@app.put("/users/{id}") +async def update_user(id: str, user: dict,db: Session = Depends(get_db)): + db_user = db.query(User).filter(User.id == id).first() + if "name" in user: + db_user.name = user["name"] + if "email" in user: + db_user.email = user["email"] + if "password" in user: + db_user.password = user["password"] + db.commit() + db.refresh(db_user) + return {"message":"User updated successfully","user":db_user} + + + +@app.delete("/users/{id}") +async def delete_user(id: str, db: Session = Depends(get_db)): + db_user = db.query(User).filter(User.id == id).first() + db.delete(db_user) + db.commit() + return {"message":"User deleted successfully","user":db_user} + + + @app.get("/posts") async def get_posts(db: Session = Depends(get_db)): return db.query(Post).all() @@ -93,18 +118,13 @@ async def update_post(id: str, post: dict,db: Session = Depends(get_db)): return {"message":"Post updated successfully","post":db_post} @app.delete("/posts/{id}") -async def delete_post(id: str, post: dict,db: Session = Depends(get_db)): +async def delete_post(id: str, db: Session = Depends(get_db)): db_post = db.query(Post).filter(Post.id == id).first() db.delete(db_post) db.commit() return {"message":"Post deleted successfully","post":db_post} -@app.get("/hello/{name}") -async def say_hello(name: str): - return {"message": f"Hello {name}"} - - if __name__ == "__main__": uvicorn.run("papi:app", host="0.0.0.0", port=8912, reload=True, log_level="debug", diff --git a/test_papi.py b/test_papi.py index a244f7d..3856a74 100644 --- a/test_papi.py +++ b/test_papi.py @@ -2,11 +2,78 @@ from fastapi.testclient import TestClient -import papi -client = TestClient(papi) +from papi import app +client = TestClient(app) def test_read_main(): response = client.get("/") assert response.status_code == 200 - assert response.json() == {"message": "Hello World"} \ No newline at end of file + assert response.json() == {"message": "Hello World"} + +def test_read_users(): + response = client.get("/users") + assert response.status_code == 200 + assert response.json() == [] + + +def test_create_read_delete_user(): + + response = client.post("/users",json={"name":"test","email":"mynameisdeleted@gmail.com","password":"pass2"}) + assert response.status_code == 200 + user=response.json()['user'] + user_id = str(user['id']) + response = client.get("/users/"+user_id) + assert response.status_code == 200 + assert response.json() == user + + update_response = client.put("/users/"+user_id,json={"name":"updated name"}) + #assert update_respose.status_code == 200 + put_user = update_response.json()['user'] + assert put_user['name'] == "updated name" + + update_response = client.put("/users/"+user_id,json={"email":"updated@gmail.com"}) + + put_user = update_response.json()['user'] + assert put_user['email'] == "updated@gmail.com" + + + response = client.delete("/users/"+user_id) + assert response.status_code == 200 + + response = client.get("/users") + assert response.status_code == 200 + assert response.json() == [] + + + + +def test_create_read_delete_post(): + + + response = client.post("/posts",json={"title":"test title","content":"testing123","author_id":"1"}) + assert response.status_code == 200 + post=response.json()['post'] + post_id = str(post['id']) + response = client.get("/posts/"+post_id) + assert response.status_code == 200 + assert response.json() == post + + update_response = client.put("/posts/"+post_id,json={"title":"test title updated"}) + #assert update_respose.status_code == 200 + put_post = update_response.json()['post'] + assert put_post['title'] == "test title updated" + + + update_response = client.put("/posts/"+post_id,json={"content":"updated content"}) + #assert update_respose.status_code == 200 + put_post = update_response.json()['post'] + assert put_post['title'] == "test title updated" + assert put_post['content'] == "updated content" + + response = client.delete("/posts/"+post_id) + assert response.status_code == 200 + + response = client.get("/posts") + assert response.status_code == 200 + assert response.json() == [] \ No newline at end of file From 55b0ba26ee2b126b116e6cb466ad4356dda8def1 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Mon, 17 Feb 2025 14:37:24 -0500 Subject: [PATCH 39/53] fix: remove deprecated deploy script for Helm upgrade --- deploy.dev.sh | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 deploy.dev.sh diff --git a/deploy.dev.sh b/deploy.dev.sh deleted file mode 100644 index 1c4056c..0000000 --- a/deploy.dev.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -helm upgrade papi ./papi-helm/ -f ./papi-helm/v.dev.yaml From 6c467d799946c01f76308428d5baa86ca70b96aa Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Mon, 17 Feb 2025 14:45:38 -0500 Subject: [PATCH 40/53] fix: remove unused deployment script for development environment --- deploy.dev.sh | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 deploy.dev.sh diff --git a/deploy.dev.sh b/deploy.dev.sh deleted file mode 100644 index 1c4056c..0000000 --- a/deploy.dev.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -helm upgrade papi ./papi-helm/ -f ./papi-helm/v.dev.yaml From db783891c8aa84e269dd5c81ce6153f0c7e99199 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Mon, 17 Feb 2025 20:51:46 -0500 Subject: [PATCH 41/53] feat: add user and post management with CRUD operations; include tests for functionality --- Makefile | 1 + README.md | 0 db.py | 20 ++++ hopscotch_collection.json | 202 +++++++++++++++++++++++++++++++++++++- papi.py | 117 ++-------------------- posts.py | 52 ++++++++++ test_papi.py | 65 ------------ test_posts.py | 51 ++++++++++ test_users.py | 57 +++++++++++ users.py | 52 ++++++++++ 10 files changed, 440 insertions(+), 177 deletions(-) create mode 100644 README.md create mode 100644 db.py create mode 100644 posts.py create mode 100644 test_posts.py create mode 100644 test_users.py create mode 100644 users.py diff --git a/Makefile b/Makefile index 8b9a1f0..81e658d 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ clean: rm -rf .coverage rm -rf report.xml rm -rf test.db + rm -rf htmlcov coverage: clean pytest --cov=papi test_papi.py --junitxml=report.xml --cov-report=html --cov-report=xml --cov-report=term --cov-fail-under 90 docker-img: coverage diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/db.py b/db.py new file mode 100644 index 0000000..e38624a --- /dev/null +++ b/db.py @@ -0,0 +1,20 @@ +from sqlalchemy import create_engine, Column, Integer,String, ForeignKey +from sqlalchemy.engine import URL +from sqlalchemy.orm import sessionmaker, Session, declarative_base + + +# Database setup +DATABASE_URL = "sqlite:///./test.db" +engine = create_engine(DATABASE_URL) +SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) +Base = declarative_base() + + + + +def get_db(): + db = SessionLocal() + try: + yield db + finally: + db.close() diff --git a/hopscotch_collection.json b/hopscotch_collection.json index 42c3ab5..a931533 100644 --- a/hopscotch_collection.json +++ b/hopscotch_collection.json @@ -1 +1,201 @@ -{"v":1,"name":"test_assignment","folders":[{"v":1,"name":"users","folders":[],"requests":[{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/users","name":"list_users","params":[],"headers":[],"method":"GET","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":null,"body":null}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/users","name":"create_user","params":[],"headers":[],"method":"POST","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"name\":\"test2\",\n \"email\":\"mynameisdeleted@gmail.com\",\n \"password\":\"pass2\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/users/1","name":"update_user","params":[],"headers":[],"method":"PUT","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"name\":\"new name\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/users/1","name":"delete_user","params":[],"headers":[],"method":"DELETE","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"name\":\"new name\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/users/1","name":"get_user","params":[],"headers":[],"method":"GET","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":null,"body":null}}]},{"v":1,"name":"posts","folders":[],"requests":[{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/posts","name":"list_posts","params":[],"headers":[],"method":"GET","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"name\":\"new name\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/posts","name":"create_post","params":[],"headers":[],"method":"POST","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"title\":\"test title\",\n \"content\":\"testing123\",\n \"author_id\":\"1\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/posts/1","name":"get_post","params":[],"headers":[],"method":"GET","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"name\":\"new name\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/posts/1","name":"update_post","params":[],"headers":[],"method":"PUT","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"title\":\"new title\"\n}"}},{"v":"1","endpoint":"https://papi.kube-dev.fairfaxmedia.net/posts/1","name":"delete_post","params":[],"headers":[],"method":"DELETE","auth":{"authType":"none","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"{\n \"title\":\"new title\"\n}"}}]}],"requests":[]} \ No newline at end of file +{ + "v": 1, + "name": "test_assignment", + "folders": [ + { + "v": 1, + "name": "users", + "folders": [], + "requests": [ + { + "v": "1", + "endpoint": "https://papi.kube-dev.fairfaxmedia.net/users", + "name": "list_users", + "params": [], + "headers": [], + "method": "GET", + "auth": { + "authType": "none", + "authActive": true + }, + "preRequestScript": "", + "testScript": "", + "body": { + "contentType": null, + "body": null + } + }, + { + "v": "1", + "endpoint": "https://papi.kube-dev.fairfaxmedia.net/users", + "name": "create_user", + "params": [], + "headers": [], + "method": "POST", + "auth": { + "authType": "none", + "authActive": true + }, + "preRequestScript": "", + "testScript": "", + "body": { + "contentType": "application/json", + "body": "{\n \"name\":\"test2\",\n \"email\":\"mynameisdeleted@gmail.com\",\n \"password\":\"pass2\"\n}" + } + }, + { + "v": "1", + "endpoint": "https://papi.kube-dev.fairfaxmedia.net/users/1", + "name": "update_user", + "params": [], + "headers": [], + "method": "PUT", + "auth": { + "authType": "none", + "authActive": true + }, + "preRequestScript": "", + "testScript": "", + "body": { + "contentType": "application/json", + "body": "{\n \"name\":\"new name\"\n}" + } + }, + { + "v": "1", + "endpoint": "https://papi.kube-dev.fairfaxmedia.net/users/1", + "name": "delete_user", + "params": [], + "headers": [], + "method": "DELETE", + "auth": { + "authType": "none", + "authActive": true + }, + "preRequestScript": "", + "testScript": "", + "body": { + "contentType": "application/json", + "body": "{\n \"name\":\"new name\"\n}" + } + }, + { + "v": "1", + "endpoint": "https://papi.kube-dev.fairfaxmedia.net/users/1", + "name": "get_user", + "params": [], + "headers": [], + "method": "GET", + "auth": { + "authType": "none", + "authActive": true + }, + "preRequestScript": "", + "testScript": "", + "body": { + "contentType": null, + "body": null + } + } + ] + }, + { + "v": 1, + "name": "posts", + "folders": [], + "requests": [ + { + "v": "1", + "endpoint": "https://papi.kube-dev.fairfaxmedia.net/posts", + "name": "list_posts", + "params": [], + "headers": [], + "method": "GET", + "auth": { + "authType": "none", + "authActive": true + }, + "preRequestScript": "", + "testScript": "", + "body": { + "contentType": "application/json", + "body": "{\n \"name\":\"new name\"\n}" + } + }, + { + "v": "1", + "endpoint": "https://papi.kube-dev.fairfaxmedia.net/posts", + "name": "create_post", + "params": [], + "headers": [], + "method": "POST", + "auth": { + "authType": "none", + "authActive": true + }, + "preRequestScript": "", + "testScript": "", + "body": { + "contentType": "application/json", + "body": "{\n \"title\":\"test title\",\n \"content\":\"testing123\",\n \"author_id\":\"1\"\n}" + } + }, + { + "v": "1", + "endpoint": "https://papi.kube-dev.fairfaxmedia.net/posts/1", + "name": "get_post", + "params": [], + "headers": [], + "method": "GET", + "auth": { + "authType": "none", + "authActive": true + }, + "preRequestScript": "", + "testScript": "", + "body": { + "contentType": "application/json", + "body": "{\n \"name\":\"new name\"\n}" + } + }, + { + "v": "1", + "endpoint": "https://papi.kube-dev.fairfaxmedia.net/posts/1", + "name": "update_post", + "params": [], + "headers": [], + "method": "PUT", + "auth": { + "authType": "none", + "authActive": true + }, + "preRequestScript": "", + "testScript": "", + "body": { + "contentType": "application/json", + "body": "{\n \"title\":\"new title\"\n}" + } + }, + { + "v": "1", + "endpoint": "https://papi.kube-dev.fairfaxmedia.net/posts/1", + "name": "delete_post", + "params": [], + "headers": [], + "method": "DELETE", + "auth": { + "authType": "none", + "authActive": true + }, + "preRequestScript": "", + "testScript": "", + "body": { + "contentType": "application/json", + "body": "{\n \"title\":\"new title\"\n}" + } + } + ] + } + ], + "requests": [] +} diff --git a/papi.py b/papi.py index 4925f3c..a35ac26 100644 --- a/papi.py +++ b/papi.py @@ -4,126 +4,21 @@ import uvicorn from sqlalchemy import create_engine, Column, Integer,String, ForeignKey from sqlalchemy.engine import URL from sqlalchemy.orm import sessionmaker, Session, declarative_base +import db +import users +import posts -# Database setup -DATABASE_URL = "sqlite:///./test.db" -engine = create_engine(DATABASE_URL) -SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) -Base = declarative_base() - - -def get_db(): - db = SessionLocal() - try: - yield db - finally: - db.close() - - -class User(Base): - __tablename__ = "users" - id = Column(Integer, primary_key=True, index=True) - name = Column(String, index=True) - email = Column(String, unique=True, index=True) - password = Column(String) - - -class Post(Base): - __tablename__ = "posts" - id = Column(Integer, primary_key=True, index=True) - title = Column(String) - content = Column(String) - author_id = Column(Integer, ForeignKey("users.id")) - - - -Base.metadata.create_all(bind=engine) +db.Base.metadata.create_all(bind=db.engine) app = FastAPI() - +app.include_router(users.router) +app.include_router(posts.router) @app.get("/") async def root(): return {"message": "Hello World"} -@app.get("/users") -async def get_users(db: Session = Depends(get_db)): - return db.query(User).all() - -@app.get("/users/{id}") -async def get_user(id: str,db: Session = Depends(get_db)): - db_user = db.query(User).filter(User.id == id).first() - return db_user - -@app.post("/users") -async def create_user(user: dict,db: Session = Depends(get_db)): - #db_user = User(name=user["name"], email=user["email"], password=user["password"]) - db_user = User(**user) - db.add(db_user) - db.commit() - db.refresh(db_user) - return {"message":"User created successfully","user":db_user} - -@app.put("/users/{id}") -async def update_user(id: str, user: dict,db: Session = Depends(get_db)): - db_user = db.query(User).filter(User.id == id).first() - if "name" in user: - db_user.name = user["name"] - if "email" in user: - db_user.email = user["email"] - if "password" in user: - db_user.password = user["password"] - db.commit() - db.refresh(db_user) - return {"message":"User updated successfully","user":db_user} - - - -@app.delete("/users/{id}") -async def delete_user(id: str, db: Session = Depends(get_db)): - db_user = db.query(User).filter(User.id == id).first() - db.delete(db_user) - db.commit() - return {"message":"User deleted successfully","user":db_user} - - - -@app.get("/posts") -async def get_posts(db: Session = Depends(get_db)): - return db.query(Post).all() - -@app.get("/posts/{id}") -async def get_post(id: str,db: Session = Depends(get_db)): - return db.query(Post).filter(Post.id == id).first() - -@app.post("/posts") -async def create_post(post: dict,db: Session = Depends(get_db)): - db_post = Post(**post) - db.add(db_post) - db.commit() - db.refresh(db_post) - return {"message":"Post created successfully","post":db_post} - - -@app.put("/posts/{id}") -async def update_post(id: str, post: dict,db: Session = Depends(get_db)): - db_post = db.query(Post).filter(Post.id == id).first() - if "title" in post: - db_post.title = post["title"] - if "content" in post: - db_post.content = post["content"] - db.commit() - db.refresh(db_post) - return {"message":"Post updated successfully","post":db_post} - -@app.delete("/posts/{id}") -async def delete_post(id: str, db: Session = Depends(get_db)): - db_post = db.query(Post).filter(Post.id == id).first() - db.delete(db_post) - db.commit() - return {"message":"Post deleted successfully","post":db_post} - if __name__ == "__main__": diff --git a/posts.py b/posts.py new file mode 100644 index 0000000..b8941f7 --- /dev/null +++ b/posts.py @@ -0,0 +1,52 @@ +from fastapi import APIRouter, Depends +from sqlalchemy.orm import sessionmaker, Session, declarative_base +from sqlalchemy import create_engine, Column, Integer,String, ForeignKey + +import db + +class Post(db.Base): + __tablename__ = "posts" + id = Column(Integer, primary_key=True, index=True) + title = Column(String) + content = Column(String) + author_id = Column(Integer, ForeignKey("users.id")) + + +router = APIRouter(prefix="/posts") + +@router.get("") +def get_users(db: Session = Depends(db.get_db)): + return db.query(Post).all() + +@router.get("/{id}") +def get_user( id, db: Session = Depends(db.get_db)): + db_post = db.query(Post).filter(Post.id == id).first() + return db_post + +@router.post("") +def create_post( post: dict, db: Session = Depends(db.get_db)): + db_post = Post(**post) + db.add(db_post) + db.commit() + db.refresh(db_post) + return {"message":"Post created successfully","post":db_post} + +@router.put("/{id}") +def update_post( id, post: dict, db: Session = Depends(db.get_db)): + db_post = db.query(Post).filter(Post.id == id).first() + if "title" in post: + db_post.title = post["title"] + if "content" in post: + db_post.content = post["content"] + db.commit() + db.refresh(db_post) + return {"message":"Post updated successfully","post":db_post} + +@router.delete("/{id}") +def delete_post(id, db: Session = Depends(db.get_db)): + db_post = db.query(Post).filter(Post.id == id).first() + db.delete(db_post) + db.commit() + return {"message":"Post deleted successfully","post":db_post} + + diff --git a/test_papi.py b/test_papi.py index 3856a74..33e70e6 100644 --- a/test_papi.py +++ b/test_papi.py @@ -11,69 +11,4 @@ def test_read_main(): assert response.status_code == 200 assert response.json() == {"message": "Hello World"} -def test_read_users(): - response = client.get("/users") - assert response.status_code == 200 - assert response.json() == [] - -def test_create_read_delete_user(): - - response = client.post("/users",json={"name":"test","email":"mynameisdeleted@gmail.com","password":"pass2"}) - assert response.status_code == 200 - user=response.json()['user'] - user_id = str(user['id']) - response = client.get("/users/"+user_id) - assert response.status_code == 200 - assert response.json() == user - - update_response = client.put("/users/"+user_id,json={"name":"updated name"}) - #assert update_respose.status_code == 200 - put_user = update_response.json()['user'] - assert put_user['name'] == "updated name" - - update_response = client.put("/users/"+user_id,json={"email":"updated@gmail.com"}) - - put_user = update_response.json()['user'] - assert put_user['email'] == "updated@gmail.com" - - - response = client.delete("/users/"+user_id) - assert response.status_code == 200 - - response = client.get("/users") - assert response.status_code == 200 - assert response.json() == [] - - - - -def test_create_read_delete_post(): - - - response = client.post("/posts",json={"title":"test title","content":"testing123","author_id":"1"}) - assert response.status_code == 200 - post=response.json()['post'] - post_id = str(post['id']) - response = client.get("/posts/"+post_id) - assert response.status_code == 200 - assert response.json() == post - - update_response = client.put("/posts/"+post_id,json={"title":"test title updated"}) - #assert update_respose.status_code == 200 - put_post = update_response.json()['post'] - assert put_post['title'] == "test title updated" - - - update_response = client.put("/posts/"+post_id,json={"content":"updated content"}) - #assert update_respose.status_code == 200 - put_post = update_response.json()['post'] - assert put_post['title'] == "test title updated" - assert put_post['content'] == "updated content" - - response = client.delete("/posts/"+post_id) - assert response.status_code == 200 - - response = client.get("/posts") - assert response.status_code == 200 - assert response.json() == [] \ No newline at end of file diff --git a/test_posts.py b/test_posts.py new file mode 100644 index 0000000..fb3bd81 --- /dev/null +++ b/test_posts.py @@ -0,0 +1,51 @@ + + +from fastapi.testclient import TestClient + +from papi import app +client = TestClient(app) + +def test_read_post(): + response = client.get("/posts") + assert response.status_code == 200 + assert response.json() != None + +def test_create_post(): + response = client.post("/posts",json={"title":"test title","content":"testing123","author_id":"1"}) + assert response.status_code == 200 + post=response.json()['post'] + assert post['title'] == "test title" + assert post['content'] == "testing123" + assert post['author_id'] == 1 + client.delete("/posts/"+str(post['id'])) + + +def test_create_read_delete_post(): + first_posts = client.get("/posts").json() + + response = client.post("/posts",json={"title":"test title","content":"testing123","author_id":"1"}) + assert response.status_code == 200 + post=response.json()['post'] + post_id = str(post['id']) + response = client.get("/posts/"+post_id) + assert response.status_code == 200 + assert response.json() == post + + update_response = client.put("/posts/"+post_id,json={"title":"test title updated"}) + #assert update_respose.status_code == 200 + put_post = update_response.json()['post'] + assert put_post['title'] == "test title updated" + + + update_response = client.put("/posts/"+post_id,json={"content":"updated content"}) + #assert update_respose.status_code == 200 + put_post = update_response.json()['post'] + assert put_post['title'] == "test title updated" + assert put_post['content'] == "updated content" + + response = client.delete("/posts/"+post_id) + assert response.status_code == 200 + + response = client.get("/posts") + assert response.status_code == 200 + assert response.json() == first_posts \ No newline at end of file diff --git a/test_users.py b/test_users.py new file mode 100644 index 0000000..76e24b9 --- /dev/null +++ b/test_users.py @@ -0,0 +1,57 @@ + +from fastapi.testclient import TestClient + +from papi import app +client = TestClient(app) + +def test_read_user(): + response = client.get("/users") + assert response.status_code == 200 + assert response.json() != None + +def test_create_user(): + response = client.post("/users",json={"name":"test","email":"mynameisdeleted@gmail.com","password":"pass2"}) + assert response.status_code == 200 + user=response.json()['user'] + assert user['name'] == "test" + assert user['email'] == "mynameisdeleted@gmail.com" + assert user['password'] == "pass2" + client.delete("/users/"+str(user['id'])) + + +def test_create_read_delete_user(): + + response = client.post("/users",json={"name":"test","email":"mynameisdeleted@gmail.com","password":"pass2"}) + assert response.status_code == 200 + user=response.json()['user'] + user_id = str(user['id']) + response = client.get("/users/"+user_id) + assert response.status_code == 200 + assert response.json() == user + + update_response = client.put("/users/"+user_id,json={"name":"updated name"}) + #assert update_respose.status_code == 200 + put_user = update_response.json()['user'] + assert put_user['name'] == "updated name" + + update_response = client.put("/users/"+user_id,json={"email":"updated@gmail.com"}) + + put_user = update_response.json()['user'] + assert put_user['email'] == "updated@gmail.com" + assert put_user['name'] == "updated name" + + + update_response = client.put("/users/"+user_id,json={"password":"pw_updated"}) + + put_user = update_response.json()['user'] + assert put_user['password'] == "pw_updated" + assert put_user['email'] == "updated@gmail.com" + assert put_user['name'] == "updated name" + + + response = client.delete("/users/"+user_id) + assert response.status_code == 200 + + response = client.get("/users") + assert response.status_code == 200 + assert response.json() == [] diff --git a/users.py b/users.py new file mode 100644 index 0000000..e6b48b0 --- /dev/null +++ b/users.py @@ -0,0 +1,52 @@ +from fastapi import APIRouter, Depends +from sqlalchemy.orm import sessionmaker, Session, declarative_base +from sqlalchemy import create_engine, Column, Integer,String, ForeignKey + +import db + +class User(db.Base): + __tablename__ = "users" + id = Column(Integer, primary_key=True, index=True) + name = Column(String, index=True) + email = Column(String, unique=True, index=True) + password = Column(String) + + +router = APIRouter(prefix="/users") + +@router.get("") +def get_users(db: Session = Depends(db.get_db)): + return db.query(User).all() + +@router.get("/{id}") +def get_user( id, db: Session = Depends(db.get_db)): + db_user = db.query(User).filter(User.id == id).first() + return db_user + +@router.post("") +def create_user( user: dict, db: Session = Depends(db.get_db)): + db_user = User(**user) + db.add(db_user) + db.commit() + db.refresh(db_user) + return {"message":"User created successfully","user":db_user} + +@router.put("/{id}") +def update_user( id, user: dict, db: Session = Depends(db.get_db)): + db_user = db.query(User).filter(User.id == id).first() + if "name" in user: + db_user.name = user["name"] + if "email" in user: + db_user.email = user["email"] + if "password" in user: + db_user.password = user["password"] + db.commit() + db.refresh(db_user) + return {"message":"User updated successfully","user":db_user} + +@router.delete("/{id}") +def delete_user(id, db: Session = Depends(db.get_db)): + db_user = db.query(User).filter(User.id == id).first() + db.delete(db_user) + db.commit() + return {"message":"User deleted successfully","user":db_user} From 3fa2504c820b56fb1bd89cdf67ddf6dc22df1193 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Mon, 17 Feb 2025 20:57:03 -0500 Subject: [PATCH 42/53] fix: update coverage command to include tests for posts and users --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 81e658d..48ecfce 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ clean: rm -rf test.db rm -rf htmlcov coverage: clean - pytest --cov=papi test_papi.py --junitxml=report.xml --cov-report=html --cov-report=xml --cov-report=term --cov-fail-under 90 + pytest --cov=papi --cov=posts --cov=users test_papi.py test_posts.py test_users.py --junitxml=report.xml --cov-report=html --cov-report=xml --cov-report=term --cov-fail-under 90 docker-img: coverage docker build -t ${DOCK_IMG} . docker-push: docker-img From 8ffe0011fc24e3e0bcfac2ba624c526e1b033224 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Mon, 17 Feb 2025 22:51:06 -0500 Subject: [PATCH 43/53] feat: update Dockerfile to copy all Python files and increment version in Makefile; add README with project details --- Dockerfile | 2 +- Makefile | 2 +- README.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6c62ee3..1955847 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,6 @@ COPY ./requirements.txt /code/requirements.txt RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt -COPY ./papi.py /code/ +COPY ./*.py /code/ CMD ["python3", "papi.py", "--port", "8912"] \ No newline at end of file diff --git a/Makefile b/Makefile index 48ecfce..9e42220 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ENV=dev -VER=2 +VER=3 TAG=${ENV}-${VER} REGISTRY=kube-reg.fairfaxmedia.net SVC=papi/svc1 diff --git a/README.md b/README.md index e69de29..c7cd541 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,57 @@ +# Posts API + +This is the Posts API project, a simple API for managing blog posts. + +## Table of Contents +- [Installation](#installation) +- [Usage](#usage) +- [Endpoints](#endpoints) +- [Contributing](#contributing) +- [License](#license) + +## Installation + +1. Clone the repository: + ```bash + git clone https://git.fairfaxmedia.net/posts-api/papi-py.git + ``` +2. Navigate to the project directory: + ```bash + cd papi-py + ``` +3. Install the dependencies: + ```bash + pip install -r requirements.txt + ``` + +## Usage + +To start the server, run: +```bash +python3 papi.py +``` + +## Endpoints + +### GET /posts +Retrieve a list of all posts. + +### POST /posts +Create a new post. + +### GET /posts/{id} +Retrieve a specific post by ID. + +### PUT /posts/{id} +Update a specific post by ID. + +### DELETE /posts/{id} +Delete a specific post by ID. + +## Contributing + +Contributions are welcome! Please open an issue or submit a pull request. + +## License + +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. \ No newline at end of file From 3d941dfc9e43896db2b34d267d74dbddee651456 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Mon, 17 Feb 2025 23:11:46 -0500 Subject: [PATCH 44/53] feat: increment version in Makefile to 4; update db.py to support DATABASE_URL from environment variables --- Makefile | 2 +- db.py | 5 ++++- test3.db | Bin 0 -> 28672 bytes 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 test3.db diff --git a/Makefile b/Makefile index 9e42220..d018127 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ENV=dev -VER=3 +VER=4 TAG=${ENV}-${VER} REGISTRY=kube-reg.fairfaxmedia.net SVC=papi/svc1 diff --git a/db.py b/db.py index e38624a..3ac403e 100644 --- a/db.py +++ b/db.py @@ -1,10 +1,13 @@ from sqlalchemy import create_engine, Column, Integer,String, ForeignKey from sqlalchemy.engine import URL from sqlalchemy.orm import sessionmaker, Session, declarative_base - +import os # Database setup DATABASE_URL = "sqlite:///./test.db" +if os.getenv("DATABASE_URL"): + DATABASE_URL = os.getenv("DATABASE_URL") + engine = create_engine(DATABASE_URL) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) Base = declarative_base() diff --git a/test3.db b/test3.db new file mode 100644 index 0000000000000000000000000000000000000000..80b9021e510238f2c94043a6c3855061de57cb7a GIT binary patch literal 28672 zcmeI(zi!h&9KdnAO&v8T4N?bh=p+VW39;}1kc4X+5gh6!hzuw)*a%BWT*VG_4I4~6 z83PmI69_??q`S-pBK)pNhxEUBfhur$QKp zajf>L+Bch}8kNn3I-9xnZOvoj(Z?@!HEPwr8jX45-qEk4Z}so$f(-!#5I_I{1Q0*~ z0R#{ztw7td?EAJkie^E06=_H|uL|Z*qhuPoyW^ zj=T_yB%CLDe$6?nSoQ7@AbhsYRB-W9#=}vop*K;*93iP@1|2Qg} z>nO_8+p}!PHj~}A38#KE(P8%2VTNw^e3+}w>REbTE}*`4mUm2Dqvb-^NKe&=y`38A zF44TTMp=&edaNFntJ$TWB%k7Wke_t3J~by>o2x~?(fCo?4<3mlfB*srAbNe}@95I_I{1Q0*~0R#|00D;m9Z2$lNv$O;xjsOA(Abego0s literal 0 HcmV?d00001 From 074d2fc481318dc95d5e8278809121679b03ccad Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Mon, 17 Feb 2025 23:12:26 -0500 Subject: [PATCH 45/53] docs: update README to include instructions for alternative database location using DATABASE_URL --- README.md | 6 ++++++ test3.db | Bin 28672 -> 0 bytes 2 files changed, 6 insertions(+) delete mode 100644 test3.db diff --git a/README.md b/README.md index c7cd541..ffec68a 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,12 @@ To start the server, run: python3 papi.py ``` + +To start with an alternative database location(postgresql) +Use the following +```bash +DATABASE_URL='postgresql+psycopg2://user:password@hostname/database_name' python3 papi.py +``` ## Endpoints ### GET /posts diff --git a/test3.db b/test3.db deleted file mode 100644 index 80b9021e510238f2c94043a6c3855061de57cb7a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28672 zcmeI(zi!h&9KdnAO&v8T4N?bh=p+VW39;}1kc4X+5gh6!hzuw)*a%BWT*VG_4I4~6 z83PmI69_??q`S-pBK)pNhxEUBfhur$QKp zajf>L+Bch}8kNn3I-9xnZOvoj(Z?@!HEPwr8jX45-qEk4Z}so$f(-!#5I_I{1Q0*~ z0R#{ztw7td?EAJkie^E06=_H|uL|Z*qhuPoyW^ zj=T_yB%CLDe$6?nSoQ7@AbhsYRB-W9#=}vop*K;*93iP@1|2Qg} z>nO_8+p}!PHj~}A38#KE(P8%2VTNw^e3+}w>REbTE}*`4mUm2Dqvb-^NKe&=y`38A zF44TTMp=&edaNFntJ$TWB%k7Wke_t3J~by>o2x~?(fCo?4<3mlfB*srAbNe}@95I_I{1Q0*~0R#|00D;m9Z2$lNv$O;xjsOA(Abego0s From 40eda9f0211bc0159d2a49c3fb088e74cf6d7537 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Mon, 17 Feb 2025 23:22:04 -0500 Subject: [PATCH 46/53] docs: update README to include unit test instructions and deployment steps --- README.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ffec68a..cb6747f 100644 --- a/README.md +++ b/README.md @@ -54,10 +54,22 @@ Update a specific post by ID. ### DELETE /posts/{id} Delete a specific post by ID. -## Contributing -Contributions are welcome! Please open an issue or submit a pull request. -## License +##Unit Tests +make coverage -This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. \ No newline at end of file +This runs coverage tests and stores the html coverage report along with functions tested in htmlcov + + +##deploy... +Please log into the connected container registry on Makefile:4 WHERE it says REGISTRY= +using the `docker login` command + +feel free to edit the VER= tag +ensure you are logged into kubernetes so that commands kubectl and helm both work + +then run +```bash +make deploy +``` \ No newline at end of file From b9bf1059392db8d89e505d7b970939f2d430e954 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Tue, 18 Feb 2025 08:29:31 -0500 Subject: [PATCH 47/53] feat: update Dockerfile and Makefile for improved deployment; add integration testing instructions and version endpoint --- .gitignore | 4 +- Dockerfile | 4 +- Makefile | 21 ++++++++-- README.md | 16 +++++++- db.py | 2 +- integration.pyrest.yaml | 85 +++++++++++++++++++++++++++++++++++++++++ papi.py | 17 ++++++--- requirements.txt | 1 + test_papi.py | 7 ++++ 9 files changed, 143 insertions(+), 14 deletions(-) create mode 100644 integration.pyrest.yaml diff --git a/.gitignore b/.gitignore index 391f3a2..06fbcc6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ __pycache__ -test.db +test*.db .coverage report.xml -coverage.xml \ No newline at end of file +coverage.xml diff --git a/Dockerfile b/Dockerfile index 1955847..a63b3e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,5 @@ +# +# FROM python:3.12 @@ -13,4 +15,4 @@ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt COPY ./*.py /code/ -CMD ["python3", "papi.py", "--port", "8912"] \ No newline at end of file +CMD ["uvicorn", "papi:app","--port", "8912","--host","0.0.0.0"] diff --git a/Makefile b/Makefile index d018127..bb76e3d 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,35 @@ ENV=dev -VER=4 +VER=0.0.4 TAG=${ENV}-${VER} REGISTRY=kube-reg.fairfaxmedia.net SVC=papi/svc1 DOCK_IMG=${REGISTRY}/${SVC}:${TAG} +LIVE_HOST:="http://localhost:8912" + clean: rm -rf .pytest_cache rm -rf .coverage rm -rf report.xml rm -rf test.db rm -rf htmlcov -coverage: clean + +install: + pip3 install -r requirements.txt +coverage: clean install pytest --cov=papi --cov=posts --cov=users test_papi.py test_posts.py test_users.py --junitxml=report.xml --cov-report=html --cov-report=xml --cov-report=term --cov-fail-under 90 + docker-img: coverage docker build -t ${DOCK_IMG} . + docker-push: docker-img docker push ${DOCK_IMG} + deploy: docker-push - helm upgrade papi ./papi-helm/ -f ./papi-helm/v.${ENV}.yaml --set image.tag=${TAG} \ No newline at end of file + helm upgrade papi ./papi-helm/ -f ./papi-helm/v.${ENV}.yaml --set image.tag=${TAG} --set env.VERSION=${VER} +integration: install + pyresttest ${LIVE_HOST} integration.pyrest.yaml +run: install + uvicorn papi:app --reload --port 8912 --host 0.0.0.0 + + +all: deploy \ No newline at end of file diff --git a/README.md b/README.md index cb6747f..5d0b82a 100644 --- a/README.md +++ b/README.md @@ -72,4 +72,18 @@ ensure you are logged into kubernetes so that commands kubectl and helm both wor then run ```bash make deploy -``` \ No newline at end of file +``` + + + +##integration testing instructions +to test live on papi.kube-dev.fairfaxmedia.net +run the following: +```bash + make integration -e LIVE_HOST=http://papi.kube-dev.fairfaxmedia.net + ``` + + to integration-test on localhost on the default port run + ```bash + make integration + ``` \ No newline at end of file diff --git a/db.py b/db.py index 3ac403e..1d4d928 100644 --- a/db.py +++ b/db.py @@ -11,7 +11,7 @@ if os.getenv("DATABASE_URL"): engine = create_engine(DATABASE_URL) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) Base = declarative_base() - +version = os.environ.get("VERSION", "0.0.0") diff --git a/integration.pyrest.yaml b/integration.pyrest.yaml new file mode 100644 index 0000000..bb77088 --- /dev/null +++ b/integration.pyrest.yaml @@ -0,0 +1,85 @@ +# Test using included Django test app +# First install python-django +# Then launch the app in another terminal by doing +# cd testapp +# python manage.py testserver test_data.json +# Once launched, tests can be executed via: +# python resttest.py http://localhost:8000 miniapp-test.yaml +--- +- config: + - testset: "Tests using test app" + - variable_binds: + - 'uid': 1 + - 'post_id': 1 + +- test: # create entity + - name: "Basic get" + - url: "/" +- test: # create entity + - name: "Get version" + - url: "/version" + + +- test: # create person by POST + - name: "Create person" + - url: "/users" + - method: "POST" + - body: '{"name": "Willim","email": "theadmiral@gmail.com"}' + - headers: {Content-Type: application/json} + - extract_binds: + - 'uid' : {'jsonpath_mini': "user.id"} + +- test: # get single person + - name: "Get single person" + - url: {'template':'/users/$uid'} # use binded value + - method: 'GET' + +- test: # update person by PUT + - name: "update person by PUT" + - url: {'template':'/users/$uid'} + - method: "PUT" + - body: '{"name": "Gaius"}' + - headers: {'Content-Type': 'application/json'} + + + + + + + +- test: # create post by POST + - name: "Create post" + - url: "/posts" + - method: "POST" + - body: '{"title": "Willims post","content": "william made a post","author_id": 1}' + - headers: {Content-Type: application/json} + - extract_binds: + - 'post_id' : {'jsonpath_mini': "post.id"} + +- test: # get single post + - name: "Get single post" + - url: {'template':'/posts/$post_id'} + - method: 'GET' + +- test: # update post by PUT + - name: "update post by PUT" + - url: {'template':'/posts/$post_id'} + - method: "PUT" + - body: '{"title": "Gaius made a post"}' + - headers: {'Content-Type': 'application/json'} +- test: # delete post + - name: "Delete post" + - url: {'template':'/posts/$post_id'} + - method: "DELETE" + + + + + +- test: # delete person + - name: "Delete person" + - url: {'template':'/users/$uid'} + - method: "DELETE" + + + diff --git a/papi.py b/papi.py index a35ac26..07358f5 100644 --- a/papi.py +++ b/papi.py @@ -1,4 +1,11 @@ #!/bin/env python3 +# +# author: Stephen Schuresko +# date: 2025-02-18 +# file: papi.py +# description: A simple FastAPI app (papi) with a few routes and models for users and posts +# + from fastapi import FastAPI, Depends import uvicorn from sqlalchemy import create_engine, Column, Integer,String, ForeignKey @@ -7,6 +14,7 @@ from sqlalchemy.orm import sessionmaker, Session, declarative_base import db import users import posts +import os @@ -19,9 +27,6 @@ app.include_router(posts.router) async def root(): return {"message": "Hello World"} - - -if __name__ == "__main__": - uvicorn.run("papi:app", host="0.0.0.0", port=8912, reload=True, log_level="debug", - workers=5, limit_concurrency=10, limit_max_requests=100) - +@app.get("/version") +async def ver(): + return {"version":db.version} diff --git a/requirements.txt b/requirements.txt index c1040e6..13519c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ fastapi sqlalchemy uvicorn +pyresttest \ No newline at end of file diff --git a/test_papi.py b/test_papi.py index 33e70e6..e6b423a 100644 --- a/test_papi.py +++ b/test_papi.py @@ -12,3 +12,10 @@ def test_read_main(): assert response.json() == {"message": "Hello World"} + + +def test_read_version(): + response = client.get("/version") + assert response.status_code == 200 + + From 444087ad86b61781ee9fb27fefd9ae043af50707 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Tue, 18 Feb 2025 08:33:12 -0500 Subject: [PATCH 48/53] docs: add OpenAPI specification links to README --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d0b82a..7adc313 100644 --- a/README.md +++ b/README.md @@ -86,4 +86,11 @@ run the following: to integration-test on localhost on the default port run ```bash make integration - ``` \ No newline at end of file + ``` + + + ###openapi spec: + +[openapi.json](https://papi.kube-dev.fairfaxmedia.net/openapi.json) + + [swagger-ui](https://papi.kube-dev.fairfaxmedia.net/docs) \ No newline at end of file From 703ea0cff2818fc3fc185860354c1070965a22f3 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Tue, 18 Feb 2025 08:38:59 -0500 Subject: [PATCH 49/53] feat: increment version to 0.0.5 in Makefile; update README with additional resources and links --- Makefile | 2 +- README.md | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bb76e3d..d9cd6b9 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ENV=dev -VER=0.0.4 +VER=0.0.5 TAG=${ENV}-${VER} REGISTRY=kube-reg.fairfaxmedia.net SVC=papi/svc1 diff --git a/README.md b/README.md index 7adc313..17d931a 100644 --- a/README.md +++ b/README.md @@ -93,4 +93,16 @@ run the following: [openapi.json](https://papi.kube-dev.fairfaxmedia.net/openapi.json) - [swagger-ui](https://papi.kube-dev.fairfaxmedia.net/docs) \ No newline at end of file + [swagger-ui](https://papi.kube-dev.fairfaxmedia.net/docs) + + + ### postman-like hopscotch collection: + + +hopscotch_collection.json can be imported into the following tool +[hopscotch-ui](https://hopscotch.kube.fairfaxmedia.net/) + +###kubernetes dashboard plane: +[kubernetes](https://kube.fairfaxmedia.net) + +[git-ci server](https://git.fairfaxmedia.net) \ No newline at end of file From 2062439501474d64f48f4f5dffa9709dc84a137c Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Tue, 18 Feb 2025 08:39:48 -0500 Subject: [PATCH 50/53] docs: fix heading formatting for OpenAPI spec and Kubernetes dashboard in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 17d931a..e69b864 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ run the following: ``` - ###openapi spec: + ##openapi spec: [openapi.json](https://papi.kube-dev.fairfaxmedia.net/openapi.json) @@ -102,7 +102,7 @@ run the following: hopscotch_collection.json can be imported into the following tool [hopscotch-ui](https://hopscotch.kube.fairfaxmedia.net/) -###kubernetes dashboard plane: +##kubernetes dashboard plane: [kubernetes](https://kube.fairfaxmedia.net) [git-ci server](https://git.fairfaxmedia.net) \ No newline at end of file From 1f2726ec5a6dec52902cd07a1649ff49ed9a28b0 Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Tue, 18 Feb 2025 08:40:39 -0500 Subject: [PATCH 51/53] docs: fix formatting issues in README sections for unit tests, deployment, integration testing, OpenAPI spec, and Kubernetes dashboard --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e69b864..d06f051 100644 --- a/README.md +++ b/README.md @@ -56,13 +56,13 @@ Delete a specific post by ID. -##Unit Tests +## nit Tests make coverage This runs coverage tests and stores the html coverage report along with functions tested in htmlcov -##deploy... +## deploy... Please log into the connected container registry on Makefile:4 WHERE it says REGISTRY= using the `docker login` command @@ -76,7 +76,7 @@ make deploy -##integration testing instructions +## ntegration testing instructions to test live on papi.kube-dev.fairfaxmedia.net run the following: ```bash @@ -89,7 +89,7 @@ run the following: ``` - ##openapi spec: + ## openapi spec: [openapi.json](https://papi.kube-dev.fairfaxmedia.net/openapi.json) @@ -102,7 +102,7 @@ run the following: hopscotch_collection.json can be imported into the following tool [hopscotch-ui](https://hopscotch.kube.fairfaxmedia.net/) -##kubernetes dashboard plane: +## kubernetes dashboard plane: [kubernetes](https://kube.fairfaxmedia.net) [git-ci server](https://git.fairfaxmedia.net) \ No newline at end of file From f9fbcb3ca7a2f4ffba843144f1140034148a7b3c Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Tue, 18 Feb 2025 08:41:20 -0500 Subject: [PATCH 52/53] docs: correct section headings for unit tests and integration testing in README --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d06f051..2544f72 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,10 @@ Delete a specific post by ID. -## nit Tests +### Unit Tests +```bash make coverage +``` This runs coverage tests and stores the html coverage report along with functions tested in htmlcov @@ -76,7 +78,7 @@ make deploy -## ntegration testing instructions +### Integration testing instructions to test live on papi.kube-dev.fairfaxmedia.net run the following: ```bash From f37a9cb381478b0f869f250b7acfcc8eaf2ec0bb Mon Sep 17 00:00:00 2001 From: stephen schuresko Date: Tue, 18 Feb 2025 08:46:26 -0500 Subject: [PATCH 53/53] feat: update version to 0.0.6 in Makefile; add helm deployment instructions to README; remove commented-out deployment steps from workflow --- .gitea/workflows/build-and-push.yaml | 6 ------ Makefile | 2 +- README.md | 9 +++++++++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/build-and-push.yaml b/.gitea/workflows/build-and-push.yaml index b29285e..b59462d 100644 --- a/.gitea/workflows/build-and-push.yaml +++ b/.gitea/workflows/build-and-push.yaml @@ -28,10 +28,4 @@ jobs: name: Build Docker image - run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image name: Push Docker image - #- env: - #KUBEB64: '${{ secrets.KUBEB64 }}' - #run: mkdir -p $HOME/.kube &&echo "$KUBEB64" | base64 -d > $HOME/.kube/config && - #curl https://fairfaxmedia.net/helm -o /usr/local/bin/helm && chmod +xxx /usr/local/bin/helm && - #/usr/local/bin/helm upgrade --install papi papi-helm/ --set image.tag=${{ steps.extract_branch.outputs.branch }} # Deploy the Helm chart - diff --git a/Makefile b/Makefile index d9cd6b9..2150d54 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ENV=dev -VER=0.0.5 +VER=0.0.6 TAG=${ENV}-${VER} REGISTRY=kube-reg.fairfaxmedia.net SVC=papi/svc1 diff --git a/README.md b/README.md index 2544f72..4a06a0c 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,15 @@ run the following: [swagger-ui](https://papi.kube-dev.fairfaxmedia.net/docs) +### helm deployment +```bash +helm upgrade papi ./papi-helm/ -f ./papi-helm/v.${ENV}.yaml --set image.tag=${TAG} --set env.VERSION=${VER} +``` +or alternatively +```bash +make deploy +``` + ### postman-like hopscotch collection: