From 81a9579627c87d42b879124062aaa9617fd2997b Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 14:30:41 +0800 Subject: [PATCH 01/14] update --- app/backend/Dockerfile.prod | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/backend/Dockerfile.prod b/app/backend/Dockerfile.prod index 0b425b5..0553b8a 100644 --- a/app/backend/Dockerfile.prod +++ b/app/backend/Dockerfile.prod @@ -13,8 +13,6 @@ ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV ENVIRONMENT=dev ENV TESTING=1 -ENV DEEPSEEK_API_KEY=sk-XXXXXXXXXX -ENV TAVILY_API_KEY=tvly-dev-wXXXXXX # install python dependencies RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv && rm -rf ~/.cache/pip From 2075536a66557d86be0e230de16e840702fd69dd Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 15:25:11 +0800 Subject: [PATCH 02/14] try --- .github/workflows/build.yml | 8 ++++---- .github/workflows/template_test.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ce6a484..def3c2b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -73,17 +73,17 @@ jobs: testContainerName: tests-aimingmedai # Pass test environment variables as JSON string testEnvs: > - '[ + [ "FRONTEND_URL=http://frontend:80", "BACKEND_URL=http://backend:80", "ENVIRONMENT=dev", "TESTING=1", - ]' + ] # Pass test directories as JSON string tests: > - '[ + [ "tests/integration/backend", - ]' + ] # Pass image definitions for compose setup as JSON string # Sensitive values should be passed via secrets and referenced within the template images: > diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index dd23217..c5cb4a8 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -146,8 +146,8 @@ jobs: - name: Run Tests shell: bash run: | - TEST_DIRS='["tests/integration/backend"]' - TEST_ENVS_JSON='["FRONTEND_URL=http://frontend:80","BACKEND_URL=http://backend:80","ENVIRONMENT=dev","TESTING=1"]' + TEST_DIRS='${ inputs.tests }' # JSON string of test directories/commands + TEST_ENVS_JSON='${ inputs.testEnvs }' # JSON string of environment variables RESULTS_PATH="${{ inputs.testResultsPath }}" STAGING_DIR="${{ runner.temp }}/test-results" # Use runner temp dir for results mkdir -p "$STAGING_DIR" From ad8ab8ee8c07eef716100326a8a519731ed9ea6e Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 15:29:41 +0800 Subject: [PATCH 03/14] add container_name --- .github/workflows/template_test.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index c5cb4a8..bf9eb4a 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -95,9 +95,10 @@ jobs: # Generate services Section Based on Images inputs foreach ($img in $images) { - $serviceName = $img.name - $svc = @{} - $svc.image = "${{ steps.tags.outputs.image_repo_path }}/$($serviceName):${{ env.TAG }}" # Use run_id tag + $serviceName = $img.name + $svc = @{} + $svc.container_name = $serviceName + $svc.image = "${{ steps.tags.outputs.image_repo_path }}/$($serviceName):${{ env.TAG }}" # Use run_id tag if ($img.depends_on) { $svc.depends_on = $img.depends_on From 1f0a52f3ae9606e4217df91cf52977faef0211eb Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 16:04:15 +0800 Subject: [PATCH 04/14] changed --- .github/workflows/build.yml | 8 ++++---- .github/workflows/template_test.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index def3c2b..ce6a484 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -73,17 +73,17 @@ jobs: testContainerName: tests-aimingmedai # Pass test environment variables as JSON string testEnvs: > - [ + '[ "FRONTEND_URL=http://frontend:80", "BACKEND_URL=http://backend:80", "ENVIRONMENT=dev", "TESTING=1", - ] + ]' # Pass test directories as JSON string tests: > - [ + '[ "tests/integration/backend", - ] + ]' # Pass image definitions for compose setup as JSON string # Sensitive values should be passed via secrets and referenced within the template images: > diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index bf9eb4a..f7c1fba 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -147,8 +147,8 @@ jobs: - name: Run Tests shell: bash run: | - TEST_DIRS='${ inputs.tests }' # JSON string of test directories/commands - TEST_ENVS_JSON='${ inputs.testEnvs }' # JSON string of environment variables + TEST_DIRS=${ inputs.tests } # JSON string of test directories/commands + TEST_ENVS_JSON=${ inputs.testEnvs } # JSON string of environment variables RESULTS_PATH="${{ inputs.testResultsPath }}" STAGING_DIR="${{ runner.temp }}/test-results" # Use runner temp dir for results mkdir -p "$STAGING_DIR" From 44ffe18f185300fa503a1a8850025dfe776ebba9 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 16:06:06 +0800 Subject: [PATCH 05/14] changed --- .github/workflows/build.yml | 8 ++++---- .github/workflows/template_test.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ce6a484..def3c2b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -73,17 +73,17 @@ jobs: testContainerName: tests-aimingmedai # Pass test environment variables as JSON string testEnvs: > - '[ + [ "FRONTEND_URL=http://frontend:80", "BACKEND_URL=http://backend:80", "ENVIRONMENT=dev", "TESTING=1", - ]' + ] # Pass test directories as JSON string tests: > - '[ + [ "tests/integration/backend", - ]' + ] # Pass image definitions for compose setup as JSON string # Sensitive values should be passed via secrets and referenced within the template images: > diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index f7c1fba..a2bc0f4 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -147,8 +147,8 @@ jobs: - name: Run Tests shell: bash run: | - TEST_DIRS=${ inputs.tests } # JSON string of test directories/commands - TEST_ENVS_JSON=${ inputs.testEnvs } # JSON string of environment variables + TEST_DIRS='${{ inputs.tests }}' # JSON string of test directories/commands + TEST_ENVS_JSON='${{ inputs.testEnvs }}' # JSON string of environment variables RESULTS_PATH="${{ inputs.testResultsPath }}" STAGING_DIR="${{ runner.temp }}/test-results" # Use runner temp dir for results mkdir -p "$STAGING_DIR" From d323026f75bc5af4ba615d4a95319c7aa0ba0e17 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 16:27:49 +0800 Subject: [PATCH 06/14] update --- .github/workflows/build.yml | 8 ++++---- .github/workflows/template_test.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index def3c2b..ce6a484 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -73,17 +73,17 @@ jobs: testContainerName: tests-aimingmedai # Pass test environment variables as JSON string testEnvs: > - [ + '[ "FRONTEND_URL=http://frontend:80", "BACKEND_URL=http://backend:80", "ENVIRONMENT=dev", "TESTING=1", - ] + ]' # Pass test directories as JSON string tests: > - [ + '[ "tests/integration/backend", - ] + ]' # Pass image definitions for compose setup as JSON string # Sensitive values should be passed via secrets and referenced within the template images: > diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index a2bc0f4..6293697 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -147,8 +147,8 @@ jobs: - name: Run Tests shell: bash run: | - TEST_DIRS='${{ inputs.tests }}' # JSON string of test directories/commands - TEST_ENVS_JSON='${{ inputs.testEnvs }}' # JSON string of environment variables + TEST_DIRS=${{ inputs.tests }} # JSON string of test directories/commands + TEST_ENVS_JSON=${{ inputs.testEnvs }} # JSON string of environment variables RESULTS_PATH="${{ inputs.testResultsPath }}" STAGING_DIR="${{ runner.temp }}/test-results" # Use runner temp dir for results mkdir -p "$STAGING_DIR" From 568c9c52c27720f3f0b494b2c6488eba343997d2 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 16:57:32 +0800 Subject: [PATCH 07/14] update --- .github/workflows/template_test.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index 6293697..dd23217 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -95,10 +95,9 @@ jobs: # Generate services Section Based on Images inputs foreach ($img in $images) { - $serviceName = $img.name - $svc = @{} - $svc.container_name = $serviceName - $svc.image = "${{ steps.tags.outputs.image_repo_path }}/$($serviceName):${{ env.TAG }}" # Use run_id tag + $serviceName = $img.name + $svc = @{} + $svc.image = "${{ steps.tags.outputs.image_repo_path }}/$($serviceName):${{ env.TAG }}" # Use run_id tag if ($img.depends_on) { $svc.depends_on = $img.depends_on @@ -147,8 +146,8 @@ jobs: - name: Run Tests shell: bash run: | - TEST_DIRS=${{ inputs.tests }} # JSON string of test directories/commands - TEST_ENVS_JSON=${{ inputs.testEnvs }} # JSON string of environment variables + TEST_DIRS='["tests/integration/backend"]' + TEST_ENVS_JSON='["FRONTEND_URL=http://frontend:80","BACKEND_URL=http://backend:80","ENVIRONMENT=dev","TESTING=1"]' RESULTS_PATH="${{ inputs.testResultsPath }}" STAGING_DIR="${{ runner.temp }}/test-results" # Use runner temp dir for results mkdir -p "$STAGING_DIR" From 8342b33dae6afc41aaede36446bccf33b1906c70 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 17:24:02 +0800 Subject: [PATCH 08/14] container_name added --- .github/workflows/build.yml | 2 ++ .github/workflows/template_test.yml | 1 + 2 files changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ce6a484..9f6f2e7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,6 +71,7 @@ jobs: projectName: aimingmed-ai image_repo: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]') testContainerName: tests-aimingmedai + # Todos: This part is not working the testEnvs is not being taken up corrrectly by Run Tests # Pass test environment variables as JSON string testEnvs: > '[ @@ -79,6 +80,7 @@ jobs: "ENVIRONMENT=dev", "TESTING=1", ]' + # Todos: This part is not working the testEnvs is not being taken up corrrectly by Run Tests # Pass test directories as JSON string tests: > '[ diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index dd23217..c19f87c 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -97,6 +97,7 @@ jobs: foreach ($img in $images) { $serviceName = $img.name $svc = @{} + $svc.container_name = $serviceName $svc.image = "${{ steps.tags.outputs.image_repo_path }}/$($serviceName):${{ env.TAG }}" # Use run_id tag if ($img.depends_on) { From a47cb3ade438940e7aeabd9f140c2ee0dcce8c75 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 21:36:19 +0800 Subject: [PATCH 09/14] check health --- .github/workflows/template_test.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index c19f87c..0140c2c 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -144,6 +144,18 @@ jobs: echo "Compose logs after wait:" docker compose -f "${{ steps.create_compose.outputs.COMPOSE_FILE_PATH }}" logs + - name: Check Docker Services Health + run: | + echo "Checking health of Docker services..." + # Check if all services are healthy + docker compose -f "${{ steps.create_compose.outputs.COMPOSE_FILE_PATH }}" ps --filter "status=running" --filter "health=healthy" | grep -q 'healthy' + if [ $? -ne 0 ]; then + echo "Error: One or more services are not healthy." + exit 1 + fi + echo "All services are healthy." + docker compose ps + - name: Run Tests shell: bash run: | From e40aa841ac4684be6c67c7e7d43c72f2d9366d67 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 21:36:42 +0800 Subject: [PATCH 10/14] update --- .github/workflows/template_test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index 0140c2c..cabeb6a 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -154,7 +154,6 @@ jobs: exit 1 fi echo "All services are healthy." - docker compose ps - name: Run Tests shell: bash From 19a8c7e7ae7b5a84f393878fe8c895016234a595 Mon Sep 17 00:00:00 2001 From: leehk Date: Fri, 18 Apr 2025 05:52:14 +0800 Subject: [PATCH 11/14] update --- .github/workflows/template_test.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index cabeb6a..813751a 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -148,12 +148,7 @@ jobs: run: | echo "Checking health of Docker services..." # Check if all services are healthy - docker compose -f "${{ steps.create_compose.outputs.COMPOSE_FILE_PATH }}" ps --filter "status=running" --filter "health=healthy" | grep -q 'healthy' - if [ $? -ne 0 ]; then - echo "Error: One or more services are not healthy." - exit 1 - fi - echo "All services are healthy." + docker compose -f "${{ steps.create_compose.outputs.COMPOSE_FILE_PATH }}" ps - name: Run Tests shell: bash From 5aa717aff7699f1ef162a8b96699c1f0c390e7fb Mon Sep 17 00:00:00 2001 From: leehk Date: Fri, 18 Apr 2025 07:07:15 +0800 Subject: [PATCH 12/14] update --- .github/workflows/build.yml | 2 ++ .github/workflows/template_test.yml | 5 ++++- .../tests/integration/backend/test_frontend_backend.py | 10 ++++------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9f6f2e7..ee098ea 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -92,6 +92,7 @@ jobs: [ { "name": "backend-aimingmedai", + "ports" : ["8004:80"], "env": { "ENVIRONMENT": "dev", "TESTING": "1", @@ -102,6 +103,7 @@ jobs: }, { "name": "frontend-aimingmedai", + "ports" : ["3004:80"], "depends_on": ["backend-aimingmedai"], "env": { "ENVIRONMENT": "dev", diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index 813751a..3545db7 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -109,6 +109,9 @@ jobs: $svc.environment = @{} } $svc.networks = @("test") # Assign service to the custom network + if ($img.ports) { + $svc.ports = $img.ports + } $compose.services.$serviceName = $svc } @@ -154,7 +157,7 @@ jobs: shell: bash run: | TEST_DIRS='["tests/integration/backend"]' - TEST_ENVS_JSON='["FRONTEND_URL=http://frontend:80","BACKEND_URL=http://backend:80","ENVIRONMENT=dev","TESTING=1"]' + TEST_ENVS_JSON='["ENVIRONMENT=dev","TESTING=1"]' RESULTS_PATH="${{ inputs.testResultsPath }}" STAGING_DIR="${{ runner.temp }}/test-results" # Use runner temp dir for results mkdir -p "$STAGING_DIR" diff --git a/app/tests/tests/integration/backend/test_frontend_backend.py b/app/tests/tests/integration/backend/test_frontend_backend.py index 42563b8..964e3d0 100644 --- a/app/tests/tests/integration/backend/test_frontend_backend.py +++ b/app/tests/tests/integration/backend/test_frontend_backend.py @@ -1,17 +1,15 @@ import pytest -import subprocess -import requests import json -import time -import os -import asyncio import websockets +import os +backend_host = os.getenv("BACKEND_URL", "backend-aimingmedai") + @pytest.mark.asyncio async def test_chatbot_integration(): # Send a request to the chatbot endpoint - url = "ws://backend-aimingmedai:80/ws" + url = f"ws://{backend_host}:80/ws" data = [{"content": "Hello"}] try: async with websockets.connect(url) as websocket: From f77d704a5778b67cfa68e17318abc5dca390da68 Mon Sep 17 00:00:00 2001 From: leehk Date: Fri, 18 Apr 2025 08:14:20 +0800 Subject: [PATCH 13/14] test update --- app/tests/tests/integration/backend/test_frontend_backend.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/tests/tests/integration/backend/test_frontend_backend.py b/app/tests/tests/integration/backend/test_frontend_backend.py index 964e3d0..fe62d3e 100644 --- a/app/tests/tests/integration/backend/test_frontend_backend.py +++ b/app/tests/tests/integration/backend/test_frontend_backend.py @@ -1,15 +1,12 @@ import pytest import json import websockets -import os -backend_host = os.getenv("BACKEND_URL", "backend-aimingmedai") - @pytest.mark.asyncio async def test_chatbot_integration(): # Send a request to the chatbot endpoint - url = f"ws://{backend_host}:80/ws" + url = "ws://backend-aimingmedai:80/ws" data = [{"content": "Hello"}] try: async with websockets.connect(url) as websocket: From 730ea3d12b75d004a02ec582597c9f50fe53b795 Mon Sep 17 00:00:00 2001 From: leehk Date: Fri, 18 Apr 2025 09:15:49 +0800 Subject: [PATCH 14/14] update --- app/tests/tests/integration/backend/test_frontend_backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/tests/tests/integration/backend/test_frontend_backend.py b/app/tests/tests/integration/backend/test_frontend_backend.py index fe62d3e..b4e8613 100644 --- a/app/tests/tests/integration/backend/test_frontend_backend.py +++ b/app/tests/tests/integration/backend/test_frontend_backend.py @@ -6,7 +6,7 @@ import websockets @pytest.mark.asyncio async def test_chatbot_integration(): # Send a request to the chatbot endpoint - url = "ws://backend-aimingmedai:80/ws" + url = "ws://localhost:8004/ws" data = [{"content": "Hello"}] try: async with websockets.connect(url) as websocket: