From 36ac5d783c3ff3f47f3bd2a2c9a1cbd0710183de Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 20 Feb 2024 22:41:34 +0530 Subject: [PATCH 01/25] Create test_api.py --- analytics/test_api.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 analytics/test_api.py diff --git a/analytics/test_api.py b/analytics/test_api.py new file mode 100644 index 00000000..93645fb0 --- /dev/null +++ b/analytics/test_api.py @@ -0,0 +1,39 @@ +# test_analytics_api.py +import unittest +from flask import json +from app import app + +class AnalyticsAPITestCase(unittest.TestCase): + def setUp(self): + self.app = app.test_client() + self.app.testing = True + + def test_root_endpoint(self): + response = self.app.get('/') + self.assertEqual(response.status_code, 200) + # Assuming the response is JSON with a list of exercises + data = json.loads(response.data) + self.assertIsInstance(data, list) # Check if data is a list + + def test_stats_endpoint(self): + response = self.app.get('/stats') + self.assertEqual(response.status_code, 200) + data = json.loads(response.data) + self.assertTrue('stats' in data) # Check if 'stats' key exists in response + + def test_user_stats_endpoint(self): + # Replace 'testuser' with a valid username from your database + response = self.app.get('/stats/testuser') + self.assertEqual(response.status_code, 200) + data = json.loads(response.data) + self.assertTrue('stats' in data) + + def test_weekly_user_stats(self): + # Ensure these query parameters are correctly formatted and valid + response = self.app.get('/stats/weekly/?user=testuser&start=2022-01-01&end=2022-01-07') + self.assertEqual(response.status_code, 200) + data = json.loads(response.data) + self.assertTrue('stats' in data) + +if __name__ == '__main__': + unittest.main() From 306735bdfb4b08fdf699e1d9d73ec6f682c63e10 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Mon, 26 Feb 2024 13:38:34 +0000 Subject: [PATCH 02/25] deploy-analytics.yaml --- .github/workflows/deploy-analytics.yaml | 57 +++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/deploy-analytics.yaml diff --git a/.github/workflows/deploy-analytics.yaml b/.github/workflows/deploy-analytics.yaml new file mode 100644 index 00000000..eb4b70e6 --- /dev/null +++ b/.github/workflows/deploy-analytics.yaml @@ -0,0 +1,57 @@ +name: Deploy Analytics Service to AWS ECR + +on: + workflow_dispatch: + push: + branches: + - main + paths: + - "analytics/**" + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: "3.8" + + - name: Change to analytics directory + run: cd analytics + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run unit tests + run: pytest + + - name: Check code coverage + run: | + coverage run -m pytest + coverage report -m --fail-under=80 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-west-2 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build, tag, and push image to Amazon ECR (Analytics Service) + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: analytics-service + IMAGE_TAG: latest + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG From 0893588904e413fb2ef4caa39a8b3e8f2e2e9f68 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Mon, 26 Feb 2024 13:46:22 +0000 Subject: [PATCH 03/25] Rename deploy-analytics.yaml to deploy-analytics.yml --- .github/workflows/{deploy-analytics.yaml => deploy-analytics.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{deploy-analytics.yaml => deploy-analytics.yml} (100%) diff --git a/.github/workflows/deploy-analytics.yaml b/.github/workflows/deploy-analytics.yml similarity index 100% rename from .github/workflows/deploy-analytics.yaml rename to .github/workflows/deploy-analytics.yml From 011417f03e9c4ab2236d54e76e91d6ba6b37f258 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Mon, 26 Feb 2024 14:04:45 +0000 Subject: [PATCH 04/25] deploy-activity-tracking.yml --- .../workflows/deploy-activity-tracking.yml | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/deploy-activity-tracking.yml diff --git a/.github/workflows/deploy-activity-tracking.yml b/.github/workflows/deploy-activity-tracking.yml new file mode 100644 index 00000000..f314d5bb --- /dev/null +++ b/.github/workflows/deploy-activity-tracking.yml @@ -0,0 +1,40 @@ +name: Deploy Activity Tracking to AWS ECR + +on: + workflow_dispatch: + push: + branches: + - main + paths: + - "activity-tracking/**" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + # Configuring AWS Credentials + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-west-2 + + # Login to Amazon ECR + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + # Build, tag, and push image for Activity Tracking + - name: Build, tag, and push image to Amazon ECR (Activity Tracking) + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: mla-fitnessapp-activity + IMAGE_TAG: latest + run: | + cd activity-tracking + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG From feff687e83bf54b2c1e9ee056af1782ec7098230 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 27 Feb 2024 16:43:27 +0530 Subject: [PATCH 05/25] Update deploy-analytics.yml --- .github/workflows/deploy-analytics.yml | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/.github/workflows/deploy-analytics.yml b/.github/workflows/deploy-analytics.yml index eb4b70e6..63a3ccbe 100644 --- a/.github/workflows/deploy-analytics.yml +++ b/.github/workflows/deploy-analytics.yml @@ -12,6 +12,8 @@ jobs: build-and-deploy: runs-on: ubuntu-latest steps: + - run: | + echo The PR was merged - name: Checkout code uses: actions/checkout@v2 @@ -43,6 +45,51 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: eu-west-2 + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build, tag, and push image to Amazon ECR (Frontend) + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: mla-fitnessapp-fe + IMAGE_TAG: latest + run: | + cd frontend + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + + - name: Build, tag, and push image to Amazon ECR (Activity Tracking) + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: mla-fitnessapp-activity + IMAGE_TAG: latest + run: | + cd activity-tracking + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + + - name: Build, tag, and push image to Amazon ECR (AuthService) + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: mla-fitnessapp-authservice + IMAGE_TAG: latest + run: | + cd authservice + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + + - name: Build, tag, and push image to Amazon ECR (Analytics) + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: mla-fitnessapp-analytics + IMAGE_TAG: latest + run: | + cd analytics + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + + - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 From e7d8c7489746430f459caa83756b0903914ac9d8 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 27 Feb 2024 20:32:59 +0530 Subject: [PATCH 06/25] Update deploy-analytics.yml --- .github/workflows/deploy-analytics.yml | 59 +++++--------------------- 1 file changed, 11 insertions(+), 48 deletions(-) diff --git a/.github/workflows/deploy-analytics.yml b/.github/workflows/deploy-analytics.yml index 63a3ccbe..66f2e708 100644 --- a/.github/workflows/deploy-analytics.yml +++ b/.github/workflows/deploy-analytics.yml @@ -1,4 +1,4 @@ -name: Deploy Analytics Service to AWS ECR +name: Deploy Analytics to AWS ECR on: workflow_dispatch: @@ -9,7 +9,7 @@ on: - "analytics/**" jobs: - build-and-deploy: + build: runs-on: ubuntu-latest steps: - run: | @@ -17,27 +17,33 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - name: Set up Python 3.8 + # Set up Python environment + - name: Set up Python uses: actions/setup-python@v2 with: python-version: "3.8" + # Navigate to analytics directory - name: Change to analytics directory run: cd analytics + # Install dependencies - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirements.txt + # Run unit tests - name: Run unit tests run: pytest + # Enforce code coverage - name: Check code coverage run: | coverage run -m pytest coverage report -m --fail-under=80 + # Configuring AWS Credentials - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: @@ -45,60 +51,17 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: eu-west-2 + # Login to Amazon ECR - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 - - name: Build, tag, and push image to Amazon ECR (Frontend) - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: mla-fitnessapp-fe - IMAGE_TAG: latest - run: | - cd frontend - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - - - name: Build, tag, and push image to Amazon ECR (Activity Tracking) - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: mla-fitnessapp-activity - IMAGE_TAG: latest - run: | - cd activity-tracking - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - - - name: Build, tag, and push image to Amazon ECR (AuthService) - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: mla-fitnessapp-authservice - IMAGE_TAG: latest - run: | - cd authservice - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - + # Build, tag, and push image for Analytics - name: Build, tag, and push image to Amazon ECR (Analytics) env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: mla-fitnessapp-analytics IMAGE_TAG: latest - run: | - cd analytics - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - - name: Build, tag, and push image to Amazon ECR (Analytics Service) - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: analytics-service - IMAGE_TAG: latest run: | docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG From 79b0b89a00ba472463f86f40752835337b4f5999 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 27 Feb 2024 20:39:24 +0530 Subject: [PATCH 07/25] Update deploy-analytics.yml --- .github/workflows/deploy-analytics.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-analytics.yml b/.github/workflows/deploy-analytics.yml index 66f2e708..3b58b3ae 100644 --- a/.github/workflows/deploy-analytics.yml +++ b/.github/workflows/deploy-analytics.yml @@ -15,11 +15,11 @@ jobs: - run: | echo The PR was merged - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 # Set up Python environment - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: "3.8" From 7470e74ee5305c6013a8b34b1fe93e10c369e8f6 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 27 Feb 2024 20:42:13 +0530 Subject: [PATCH 08/25] Update deploy-analytics.yml --- .github/workflows/deploy-analytics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-analytics.yml b/.github/workflows/deploy-analytics.yml index 3b58b3ae..8a9347f8 100644 --- a/.github/workflows/deploy-analytics.yml +++ b/.github/workflows/deploy-analytics.yml @@ -45,7 +45,7 @@ jobs: # Configuring AWS Credentials - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v2 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} From db3db90ba6427fbdd8d493345b118ad0affbb86c Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 27 Feb 2024 21:00:10 +0530 Subject: [PATCH 09/25] Create deploy-frontend.yml --- .github/workflows/deploy-frontend.yml | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/deploy-frontend.yml diff --git a/.github/workflows/deploy-frontend.yml b/.github/workflows/deploy-frontend.yml new file mode 100644 index 00000000..fc6b4dd9 --- /dev/null +++ b/.github/workflows/deploy-frontend.yml @@ -0,0 +1,61 @@ +name: Deploy Frontend to AWS ECR + +on: + workflow_dispatch: + push: + branches: + - main + paths: + - "frontend/**" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + # Set up Node.js + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: "14" # + + # Navigate to frontend directory + - name: Change to frontend directory + run: cd frontend + + # Install dependencies + - name: Install dependencies + run: npm ci # Using `npm ci` for more reliable builds in CI/CD pipelines + + # Run unit tests + - name: Run unit tests + run: npm test + + # Build React project (Optional but recommended to catch build-time errors) + - name: Build React project + run: npm run build + + # Configuring AWS Credentials + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-west-2 + + # Login to Amazon ECR + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + # Build, tag, and push image for Frontend + - name: Build, tag, and push image to Amazon ECR (Frontend) + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: mla-fitnessapp-fe + IMAGE_TAG: latest + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG From 14dfcfbda1d9db53654266d14527e6c33c7f6325 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 27 Feb 2024 21:01:09 +0530 Subject: [PATCH 10/25] Create deploy-auth.yml --- .github/workflows/deploy-auth.yml | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/deploy-auth.yml diff --git a/.github/workflows/deploy-auth.yml b/.github/workflows/deploy-auth.yml new file mode 100644 index 00000000..ee231576 --- /dev/null +++ b/.github/workflows/deploy-auth.yml @@ -0,0 +1,54 @@ +name: Deploy AuthService to AWS ECR + +on: + workflow_dispatch: + push: + branches: + - main + paths: + - "authservice/**" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + # Set up JDK 8 + - name: Set up JDK 8 + uses: actions/setup-java@v2 + with: + distribution: "adopt" + java-version: "8" + + # Navigate to authservice directory + - name: Change to authservice directory + run: cd authservice + + # Run Gradle tests + - name: Run Gradle tests + run: ./gradlew clean test + + # Configuring AWS Credentials + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-west-2 + + # Login to Amazon ECR + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + # Build, tag, and push image for AuthService + - name: Build, tag, and push image to Amazon ECR (AuthService) + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: mla-fitnessapp-authservice + IMAGE_TAG: latest + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG From ec92a206be8c3374200c03b80c58e6877f860f3b Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 27 Feb 2024 21:14:46 +0530 Subject: [PATCH 11/25] Update test_api.py --- analytics/test_api.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/analytics/test_api.py b/analytics/test_api.py index 93645fb0..30485ff3 100644 --- a/analytics/test_api.py +++ b/analytics/test_api.py @@ -2,10 +2,20 @@ import unittest from flask import json from app import app +import mongomock class AnalyticsAPITestCase(unittest.TestCase): def setUp(self): + # Create a mongomock client + self.mock_client = mongomock.MongoClient() + app.config["MONGO_URI"] = "mongomock://localhost" + + # Patch the application's database client with the mock client + app.db_client = self.mock_client + + # Continue with setting up a test client for Flask self.app = app.test_client() + #test_client used to simulate requests and test reponse without running server self.app.testing = True def test_root_endpoint(self): @@ -22,14 +32,12 @@ def test_stats_endpoint(self): self.assertTrue('stats' in data) # Check if 'stats' key exists in response def test_user_stats_endpoint(self): - # Replace 'testuser' with a valid username from your database response = self.app.get('/stats/testuser') self.assertEqual(response.status_code, 200) data = json.loads(response.data) self.assertTrue('stats' in data) def test_weekly_user_stats(self): - # Ensure these query parameters are correctly formatted and valid response = self.app.get('/stats/weekly/?user=testuser&start=2022-01-01&end=2022-01-07') self.assertEqual(response.status_code, 200) data = json.loads(response.data) From a9e36b71913ef8bb8bcec84aab0c64d9072c612f Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 27 Feb 2024 21:16:45 +0530 Subject: [PATCH 12/25] Update deploy-activity-tracking.yml --- .github/workflows/deploy-activity-tracking.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-activity-tracking.yml b/.github/workflows/deploy-activity-tracking.yml index f314d5bb..56de33d4 100644 --- a/.github/workflows/deploy-activity-tracking.yml +++ b/.github/workflows/deploy-activity-tracking.yml @@ -1,7 +1,6 @@ name: Deploy Activity Tracking to AWS ECR on: - workflow_dispatch: push: branches: - main From 7e4e5e1e51d4fc68d34bf5695c54bbb04a59dbef Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 27 Feb 2024 21:17:10 +0530 Subject: [PATCH 13/25] Update deploy-analytics.yml --- .github/workflows/deploy-analytics.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-analytics.yml b/.github/workflows/deploy-analytics.yml index 8a9347f8..4d62ff13 100644 --- a/.github/workflows/deploy-analytics.yml +++ b/.github/workflows/deploy-analytics.yml @@ -1,7 +1,6 @@ name: Deploy Analytics to AWS ECR on: - workflow_dispatch: push: branches: - main From 21914268d836fecec919ef3f96108dd0d0392634 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 27 Feb 2024 21:17:20 +0530 Subject: [PATCH 14/25] Update deploy-auth.yml --- .github/workflows/deploy-auth.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-auth.yml b/.github/workflows/deploy-auth.yml index ee231576..89c93c28 100644 --- a/.github/workflows/deploy-auth.yml +++ b/.github/workflows/deploy-auth.yml @@ -1,7 +1,6 @@ name: Deploy AuthService to AWS ECR on: - workflow_dispatch: push: branches: - main From c281e5b98928e3528a7371d7f796f46ef1756629 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 27 Feb 2024 21:17:33 +0530 Subject: [PATCH 15/25] Update deploy-frontend.yml --- .github/workflows/deploy-frontend.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-frontend.yml b/.github/workflows/deploy-frontend.yml index fc6b4dd9..362436fd 100644 --- a/.github/workflows/deploy-frontend.yml +++ b/.github/workflows/deploy-frontend.yml @@ -1,7 +1,6 @@ name: Deploy Frontend to AWS ECR on: - workflow_dispatch: push: branches: - main From 2bf8113d4a503039b1ce17a7a6398b509f9c7052 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 27 Feb 2024 21:18:44 +0530 Subject: [PATCH 16/25] Update test_api.py From 010712e8ba5c0ba4561d9e5ac4e2a2c875adad60 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Tue, 27 Feb 2024 21:19:45 +0530 Subject: [PATCH 17/25] Update requirements.txt --- analytics/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/analytics/requirements.txt b/analytics/requirements.txt index 73ae4171..66a40e33 100644 --- a/analytics/requirements.txt +++ b/analytics/requirements.txt @@ -3,4 +3,5 @@ pymongo==4.2.0 gunicorn==20.1.0 python-dotenv==0.19.0 Flask-PyMongo==2.3.0 -Flask-CORS==3.0.10 \ No newline at end of file +Flask-CORS==3.0.10 +mongomock==3.22.0 From e628533d64d5458d804678ce349e5fc0314fa1ad Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Wed, 28 Feb 2024 19:01:18 +0530 Subject: [PATCH 18/25] Update deploy-activity-tracking.yml --- .github/workflows/deploy-activity-tracking.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-activity-tracking.yml b/.github/workflows/deploy-activity-tracking.yml index 56de33d4..88e82f32 100644 --- a/.github/workflows/deploy-activity-tracking.yml +++ b/.github/workflows/deploy-activity-tracking.yml @@ -1,20 +1,21 @@ -name: Deploy Activity Tracking to AWS ECR +name: Deploy to AWS ECR on: push: branches: - main - paths: + paths: - "activity-tracking/**" jobs: build: runs-on: ubuntu-latest steps: + - run: | + echo The PR was merged - name: Checkout code uses: actions/checkout@v2 - # Configuring AWS Credentials - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: @@ -22,12 +23,10 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: eu-west-2 - # Login to Amazon ECR - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 - # Build, tag, and push image for Activity Tracking - name: Build, tag, and push image to Amazon ECR (Activity Tracking) env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} From c3752a06cbd5de77f099b70845c4c39262c24476 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Wed, 28 Feb 2024 19:02:09 +0530 Subject: [PATCH 19/25] Update deploy-analytics.yml --- .github/workflows/deploy-analytics.yml | 38 ++++---------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/.github/workflows/deploy-analytics.yml b/.github/workflows/deploy-analytics.yml index 4d62ff13..bd7b5625 100644 --- a/.github/workflows/deploy-analytics.yml +++ b/.github/workflows/deploy-analytics.yml @@ -1,10 +1,10 @@ -name: Deploy Analytics to AWS ECR +name: Deploy to AWS ECR on: push: branches: - main - paths: + paths: - "analytics/**" jobs: @@ -14,53 +14,25 @@ jobs: - run: | echo The PR was merged - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v2 - # Set up Python environment - - name: Set up Python - uses: actions/setup-python@v3 - with: - python-version: "3.8" - - # Navigate to analytics directory - - name: Change to analytics directory - run: cd analytics - - # Install dependencies - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - # Run unit tests - - name: Run unit tests - run: pytest - - # Enforce code coverage - - name: Check code coverage - run: | - coverage run -m pytest - coverage report -m --fail-under=80 - - # Configuring AWS Credentials - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 + uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: eu-west-2 - # Login to Amazon ECR - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 - # Build, tag, and push image for Analytics - name: Build, tag, and push image to Amazon ECR (Analytics) env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: mla-fitnessapp-analytics IMAGE_TAG: latest run: | + cd analytics docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG From 9d372a37499855033f49f5539b65d41c5234e4c4 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Wed, 28 Feb 2024 19:02:43 +0530 Subject: [PATCH 20/25] Update deploy-auth.yml --- .github/workflows/deploy-auth.yml | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/.github/workflows/deploy-auth.yml b/.github/workflows/deploy-auth.yml index 89c93c28..1f426d5a 100644 --- a/.github/workflows/deploy-auth.yml +++ b/.github/workflows/deploy-auth.yml @@ -1,35 +1,21 @@ -name: Deploy AuthService to AWS ECR +name: Deploy to AWS ECR on: push: branches: - main - paths: + paths: - "authservice/**" jobs: build: runs-on: ubuntu-latest steps: + - run: | + echo The PR was merged - name: Checkout code uses: actions/checkout@v2 - # Set up JDK 8 - - name: Set up JDK 8 - uses: actions/setup-java@v2 - with: - distribution: "adopt" - java-version: "8" - - # Navigate to authservice directory - - name: Change to authservice directory - run: cd authservice - - # Run Gradle tests - - name: Run Gradle tests - run: ./gradlew clean test - - # Configuring AWS Credentials - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: @@ -37,17 +23,16 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: eu-west-2 - # Login to Amazon ECR - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 - # Build, tag, and push image for AuthService - name: Build, tag, and push image to Amazon ECR (AuthService) env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: mla-fitnessapp-authservice IMAGE_TAG: latest run: | + cd authservice docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG From c3de60202a9aa43195c1f60ad357b48f0dee5a02 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Wed, 28 Feb 2024 19:03:16 +0530 Subject: [PATCH 21/25] Update deploy-frontend.yml --- .github/workflows/deploy-frontend.yml | 32 +++++---------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/.github/workflows/deploy-frontend.yml b/.github/workflows/deploy-frontend.yml index 362436fd..2fc8c61c 100644 --- a/.github/workflows/deploy-frontend.yml +++ b/.github/workflows/deploy-frontend.yml @@ -1,42 +1,21 @@ -name: Deploy Frontend to AWS ECR +name: Deploy to AWS ECR on: push: branches: - main - paths: + paths: - "frontend/**" jobs: build: runs-on: ubuntu-latest steps: + - run: | + echo The PR was merged - name: Checkout code uses: actions/checkout@v2 - # Set up Node.js - - name: Set up Node.js - uses: actions/setup-node@v2 - with: - node-version: "14" # - - # Navigate to frontend directory - - name: Change to frontend directory - run: cd frontend - - # Install dependencies - - name: Install dependencies - run: npm ci # Using `npm ci` for more reliable builds in CI/CD pipelines - - # Run unit tests - - name: Run unit tests - run: npm test - - # Build React project (Optional but recommended to catch build-time errors) - - name: Build React project - run: npm run build - - # Configuring AWS Credentials - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: @@ -44,17 +23,16 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: eu-west-2 - # Login to Amazon ECR - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 - # Build, tag, and push image for Frontend - name: Build, tag, and push image to Amazon ECR (Frontend) env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: mla-fitnessapp-fe IMAGE_TAG: latest run: | + cd frontend docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG From 76ebfa9c22ff502555d53e59d3e14ff85d1e097e Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Mon, 1 Apr 2024 16:44:29 +0530 Subject: [PATCH 22/25] Update requirements.txt --- analytics/requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/analytics/requirements.txt b/analytics/requirements.txt index 66a40e33..836a6bd0 100644 --- a/analytics/requirements.txt +++ b/analytics/requirements.txt @@ -5,3 +5,5 @@ python-dotenv==0.19.0 Flask-PyMongo==2.3.0 Flask-CORS==3.0.10 mongomock==3.22.0 +graphene==2.1.8 +graphene-sqlalchemy==2.3.0 From 9424cb019cf14e50ad6dfa6f89bd64f339562e9d Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Mon, 1 Apr 2024 16:47:58 +0530 Subject: [PATCH 23/25] Update requirements.txt --- analytics/requirements.txt | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/analytics/requirements.txt b/analytics/requirements.txt index 836a6bd0..3c49192c 100644 --- a/analytics/requirements.txt +++ b/analytics/requirements.txt @@ -5,5 +5,23 @@ python-dotenv==0.19.0 Flask-PyMongo==2.3.0 Flask-CORS==3.0.10 mongomock==3.22.0 -graphene==2.1.8 -graphene-sqlalchemy==2.3.0 +anyio==4.2.0 +ariadne==0.11.0 +blinker==1.7.0 +click==8.1.7 +dnspython==2.4.2 +Flask-SQLAlchemy==3.1.1 +graphql-core==3.0.5 +idna==3.6 +itsdangerous==2.1.2 +Jinja2==3.1.2 +MarkupSafe==2.1.3 +packaging==23.2 +sniffio==1.3.0 +SQLAlchemy==2.0.25 +starlette<0.14 +typing_extensions==4.9.0 +Werkzeug==3.0.1 + + + From 2dcf22a7c6f74ae7ee6ebc91c9200dd75d3cf25c Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Mon, 1 Apr 2024 17:19:24 +0530 Subject: [PATCH 24/25] Update app.py --- analytics/app.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/analytics/app.py b/analytics/app.py index cdd57579..3a6bacb6 100644 --- a/analytics/app.py +++ b/analytics/app.py @@ -9,18 +9,78 @@ import logging import os from datetime import datetime, timedelta +from ariadne import load_schema_from_path, make_executable_schema, graphql_sync, ObjectType, QueryType +from ariadne.constants import PLAYGROUND_HTML app = Flask(__name__) CORS(app, resources={r"/*": {"origins": "*"}}, methods="GET,HEAD,POST,OPTIONS,PUT,PATCH,DELETE") load_dotenv() +title = "Weekly Exercise Tracker Statistics" +heading = "MLA Flask Microservice" +user = "testuser" mongo_uri = os.getenv('MONGO_URI') mongo_db = os.getenv('MONGO_DB') client = MongoClient(mongo_uri) db = client[mongo_db] +query = QueryType() +type_defs = load_schema_from_path("schema.graphql") + +@app.route('/api/graphql', methods=['GET']) +def graphql_playground(): + print("Received a get request") + return PLAYGROUND_HTML, 200 + +@app.route('/api/graphql', methods=['POST']) +def graphql_server(): + print("Getting a request...") + data = request.get_json() + success, result = graphql_sync( + schema, + data, + context_value=request, + debug=True + ) + status_code = 200 if success else 400 + return jsonify(result), status_code + +@query.field("stats") +def resolve_stats(_, info): + try: + print("Resolving the list stats info") + loadedStats = stats() + print(loadedStats) + payload = { + "success": True, + "results": loadedStats + } + except Exception as error: + payload = { + "success": False, + "errors": [str(error)] + } + return payload + +@query.field("filteredStats") +def resolve_filteredStats(*_, name=None): + try: + print("Resolving the list stats info") + loadedStats = user_stats(name) + print(loadedStats) + payload = { + "success": True, + "results": loadedStats + } + except Exception as error: + payload = { + "success": False, + "errors": [str(error)] + } + return payload + @app.route('/') def index(): @@ -103,6 +163,7 @@ def user_stats(username): stats = list(db.exercises.aggregate(pipeline)) return jsonify(stats=stats) +schema = make_executable_schema(type_defs, query) @app.route('/stats/weekly/', methods=['GET']) def weekly_user_stats(): @@ -158,4 +219,4 @@ def weekly_user_stats(): if __name__ == "__main__": - app.run(debug=True, host='0.0.0.0', port=5050) \ No newline at end of file + app.run(debug=True, host='0.0.0.0', port=5050) From 87dd65cb49e17d459c2da129730cfe626cb40a72 Mon Sep 17 00:00:00 2001 From: Harini Ramesh Date: Mon, 1 Apr 2024 17:20:42 +0530 Subject: [PATCH 25/25] Create schema.graphql --- analytics/schema.graphql | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 analytics/schema.graphql diff --git a/analytics/schema.graphql b/analytics/schema.graphql new file mode 100644 index 00000000..04dd77a7 --- /dev/null +++ b/analytics/schema.graphql @@ -0,0 +1,23 @@ +schema { + query: Query +} +type Stats{ + username: String! + exercises: [Exercise] +} + +type Exercise { + exerciseType: String + totalDuration: Int +} + +type StatsResult { + success: Boolean! + errors: [String] + results: [Stats] +} + +type Query { + stats: StatsResult + filteredStats(name: String): StatsResult +}