From 773b8a9c56a91b7bd627c602b0dd6d6bd6f0486f Mon Sep 17 00:00:00 2001 From: leehk Date: Wed, 16 Apr 2025 16:52:21 +0800 Subject: [PATCH 01/24] update wiht github lowecse --- .github/workflows/build_new.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index e1756a6..224e332 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.yml @@ -50,7 +50,7 @@ jobs: with: # Pass values from the matrix context and global env project_name: aimingmed-ai - image_repo: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]') + image_repo: ghcr.io/${{ github.repository.toLowerCase() }} image_name: ${{ matrix.image_config.IMAGE_NAME }} build_context: ${{ matrix.image_config.BUILD_CONTEXT }} dockerfile: ${{ matrix.image_config.DOCKERFILE }} @@ -69,7 +69,7 @@ jobs: uses: ./.github/workflows/template_test.yml # Path to the reusable workflow file with: projectName: aimingmed-ai - image_repo: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]') + image_repo: ghcr.io/${{ github.repository.toLowerCase() }} # Pass test environment variables as JSON string testEnvs: > [ From 00bb8b64fc5aea4bb6a5223fa7f30089e21e002e Mon Sep 17 00:00:00 2001 From: leehk Date: Wed, 16 Apr 2025 16:59:00 +0800 Subject: [PATCH 02/24] update --- .github/workflows/build_new.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index 224e332..6ee5af8 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.yml @@ -50,7 +50,7 @@ jobs: with: # Pass values from the matrix context and global env project_name: aimingmed-ai - image_repo: ghcr.io/${{ github.repository.toLowerCase() }} + image_repo: ghcr.io/${{ lower(github.repository) }} image_name: ${{ matrix.image_config.IMAGE_NAME }} build_context: ${{ matrix.image_config.BUILD_CONTEXT }} dockerfile: ${{ matrix.image_config.DOCKERFILE }} From e5ac1c43330a85de0aae320dcf34c23d9cb1e5c2 Mon Sep 17 00:00:00 2001 From: leehk Date: Wed, 16 Apr 2025 16:59:15 +0800 Subject: [PATCH 03/24] update --- .github/workflows/build_new.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index 6ee5af8..b4eaae2 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.yml @@ -69,7 +69,7 @@ jobs: uses: ./.github/workflows/template_test.yml # Path to the reusable workflow file with: projectName: aimingmed-ai - image_repo: ghcr.io/${{ github.repository.toLowerCase() }} + image_repo: ghcr.io/${{ lower(github.repository) }} # Pass test environment variables as JSON string testEnvs: > [ From 783a01c861c96b5b597cafe0836d0d2c12dc181e Mon Sep 17 00:00:00 2001 From: leehk Date: Wed, 16 Apr 2025 16:59:58 +0800 Subject: [PATCH 04/24] update --- .github/workflows/build_new.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index b4eaae2..e1756a6 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.yml @@ -50,7 +50,7 @@ jobs: with: # Pass values from the matrix context and global env project_name: aimingmed-ai - image_repo: ghcr.io/${{ lower(github.repository) }} + image_repo: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]') image_name: ${{ matrix.image_config.IMAGE_NAME }} build_context: ${{ matrix.image_config.BUILD_CONTEXT }} dockerfile: ${{ matrix.image_config.DOCKERFILE }} @@ -69,7 +69,7 @@ jobs: uses: ./.github/workflows/template_test.yml # Path to the reusable workflow file with: projectName: aimingmed-ai - image_repo: ghcr.io/${{ lower(github.repository) }} + image_repo: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]') # Pass test environment variables as JSON string testEnvs: > [ From 98a3d3ebd1bb9d7963192aca81b3867b3dc411a8 Mon Sep 17 00:00:00 2001 From: leehk Date: Wed, 16 Apr 2025 17:02:44 +0800 Subject: [PATCH 05/24] check new exclude backend --- .github/workflows/build_new.yml | 6 +++--- .github/workflows/debug_env.yml | 12 ------------ 2 files changed, 3 insertions(+), 15 deletions(-) delete mode 100644 .github/workflows/debug_env.yml diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index e1756a6..fae28e3 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.yml @@ -34,9 +34,9 @@ jobs: # We wrap the image configuration in a single 'image_config' key # to pass it more easily if needed, but primarily access sub-keys directly. image_config: - - IMAGE_NAME: backend-aimingmedai - BUILD_CONTEXT: ./app/backend - DOCKERFILE: ./app/backend/Dockerfile + # - IMAGE_NAME: backend-aimingmedai + # BUILD_CONTEXT: ./app/backend + # DOCKERFILE: ./app/backend/Dockerfile - IMAGE_NAME: frontend-aimingmedai BUILD_CONTEXT: ./app/frontend DOCKERFILE: ./app/frontend/Dockerfile.test diff --git a/.github/workflows/debug_env.yml b/.github/workflows/debug_env.yml deleted file mode 100644 index 4b1c4a4..0000000 --- a/.github/workflows/debug_env.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: Debug Environment - -on: - workflow_dispatch: # Allows manual triggering - -jobs: - debug: - runs-on: ubuntu-latest - steps: - - name: Print GITHUB_REPOSITORY - run: | - echo "GITHUB_REPOSITORY: ${{ github.repository }}" \ No newline at end of file From 13d5ab4098c77d3c465c84e11038717605f99c24 Mon Sep 17 00:00:00 2001 From: leehk Date: Wed, 16 Apr 2025 17:12:14 +0800 Subject: [PATCH 06/24] solve --- .github/workflows/build_new.yml | 1 + .github/workflows/template_test.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index fae28e3..4bfe812 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.yml @@ -70,6 +70,7 @@ jobs: with: projectName: aimingmed-ai image_repo: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]') + testContainerName: tests-aimingmedai # Pass test environment variables as JSON string testEnvs: > [ diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index 79903e8..f92c083 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -97,7 +97,7 @@ jobs: foreach ($img in $images) { $serviceName = $img.name $svc = @{} - $svc.image = "${{ env.IMAGE_REPO }}/$($serviceName):${{ env.TAG }}" # Use run_id tag + $svc.image = "$env:IMAGE_REPO/$($serviceName):${{ env.TAG }}" # Use run_id tag if ($img.depends_on) { $svc.depends_on = $img.depends_on From bb27bfcfee0ede2394afe6436d2c8ec80e8c8b61 Mon Sep 17 00:00:00 2001 From: leehk Date: Wed, 16 Apr 2025 17:22:25 +0800 Subject: [PATCH 07/24] test --- .github/workflows/build_new.yml | 92 +++++++++++++++++---------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index 4bfe812..78f6194 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.yml @@ -61,51 +61,55 @@ jobs: test: name: Run Integration Tests needs: build # Ensure this job runs after the build job + runs-on: ubuntu-latest # Specify the runner # Define necessary permissions if needed (e.g., for GitHub Packages) permissions: contents: read packages: write # If pushing to GitHub Packages registry - # Call the reusable workflow for testing - uses: ./.github/workflows/template_test.yml # Path to the reusable workflow file - with: - projectName: aimingmed-ai - image_repo: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]') - 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: > - [ - { - "name": "backend-aimingmedai", - "env": { - "ENVIRONMENT": "dev", - "TESTING": "1", - "DEEPSEEK_API_KEY": "", - "TAVILY_API_KEY": "" - - } - }, - { - "name": "frontend-aimingmedai", - "depends_on": ["backend-aimingmedai"], - "env": { - "ENVIRONMENT": "dev", - "TESTING": "1", - "LOG_LEVEL": "DEBUG" - } - } - ] - + steps: + - name: Set Image Repo + id: set_image_repo + run: echo "image_repo=ghcr.io/$(echo "$GITHUB_REPOSITORY" | tr '[A-Z]' '[a-z]')" >> $GITHUB_OUTPUT + shell: bash + # Call the reusable workflow for testing + - uses: ./.github/workflows/template_test.yml # Path to the reusable workflow file + with: + projectName: aimingmed-ai + image_repo: ${{ steps.set_image_repo.outputs.image_repo }} + 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 + images: > + [ + { + "name": "backend-aimingmedai", + "env": { + "ENVIRONMENT": "dev", + "TESTING": "1", + "DEEPSEEK_API_KEY": "", + "TAVILY_API_KEY": "" + + } + }, + { + "name": "frontend-aimingmedai", + "depends_on": ["backend-aimingmedai"], + "env": { + "ENVIRONMENT": "dev", + "TESTING": "1", + "LOG_LEVEL": "DEBUG" + } + } + ] From 9189738e5923717caf19734f063776d74ce26d12 Mon Sep 17 00:00:00 2001 From: leehk Date: Wed, 16 Apr 2025 17:26:07 +0800 Subject: [PATCH 08/24] corrected uses --- .github/workflows/build_new.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index 78f6194..73c9b02 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.yml @@ -72,7 +72,7 @@ jobs: run: echo "image_repo=ghcr.io/$(echo "$GITHUB_REPOSITORY" | tr '[A-Z]' '[a-z]')" >> $GITHUB_OUTPUT shell: bash # Call the reusable workflow for testing - - uses: ./.github/workflows/template_test.yml # Path to the reusable workflow file + - uses: .github/workflows/template_test.yml # Path to the reusable workflow file with: projectName: aimingmed-ai image_repo: ${{ steps.set_image_repo.outputs.image_repo }} From d5e284be3e4ca01229215af9244125266f2dfe6a Mon Sep 17 00:00:00 2001 From: leehk Date: Wed, 16 Apr 2025 17:30:03 +0800 Subject: [PATCH 09/24] up --- .github/workflows/build_new.yml | 94 ++++++++++++++++----------------- 1 file changed, 45 insertions(+), 49 deletions(-) diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index 73c9b02..046b2ca 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.yml @@ -50,7 +50,7 @@ jobs: with: # Pass values from the matrix context and global env project_name: aimingmed-ai - image_repo: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]') + image_repo: "ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]')" image_name: ${{ matrix.image_config.IMAGE_NAME }} build_context: ${{ matrix.image_config.BUILD_CONTEXT }} dockerfile: ${{ matrix.image_config.DOCKERFILE }} @@ -61,55 +61,51 @@ jobs: test: name: Run Integration Tests needs: build # Ensure this job runs after the build job - runs-on: ubuntu-latest # Specify the runner # Define necessary permissions if needed (e.g., for GitHub Packages) permissions: contents: read packages: write # If pushing to GitHub Packages registry - steps: - - name: Set Image Repo - id: set_image_repo - run: echo "image_repo=ghcr.io/$(echo "$GITHUB_REPOSITORY" | tr '[A-Z]' '[a-z]')" >> $GITHUB_OUTPUT - shell: bash - # Call the reusable workflow for testing - - uses: .github/workflows/template_test.yml # Path to the reusable workflow file - with: - projectName: aimingmed-ai - image_repo: ${{ steps.set_image_repo.outputs.image_repo }} - 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 - images: > - [ - { - "name": "backend-aimingmedai", - "env": { - "ENVIRONMENT": "dev", - "TESTING": "1", - "DEEPSEEK_API_KEY": "", - "TAVILY_API_KEY": "" - - } - }, - { - "name": "frontend-aimingmedai", - "depends_on": ["backend-aimingmedai"], - "env": { - "ENVIRONMENT": "dev", - "TESTING": "1", - "LOG_LEVEL": "DEBUG" - } - } - ] + # Call the reusable workflow for testing + uses: ./.github/workflows/template_test.yml # Path to the reusable workflow file + with: + projectName: aimingmed-ai + image_repo: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[A-Z]' '[a-z]') + 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: > + [ + { + "name": "backend-aimingmedai", + "env": { + "ENVIRONMENT": "dev", + "TESTING": "1", + "DEEPSEEK_API_KEY": "", + "TAVILY_API_KEY": "" + + } + }, + { + "name": "frontend-aimingmedai", + "depends_on": ["backend-aimingmedai"], + "env": { + "ENVIRONMENT": "dev", + "TESTING": "1", + "LOG_LEVEL": "DEBUG" + } + } + ] + From 282266174ef8f2651226f2397310a410886460e1 Mon Sep 17 00:00:00 2001 From: leehk Date: Wed, 16 Apr 2025 17:37:21 +0800 Subject: [PATCH 10/24] update --- .github/workflows/template_test.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index f92c083..3a35acf 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -71,6 +71,12 @@ jobs: sudo rm -rf "/usr/local/share/boost" sudo rm -rf "$AGENT_TOOLSDIRECTORY" + - name: Define Image Repo tags + # Define tags consistently using inputs + id: tags + run: | + echo "image_repo_path=${{ inputs.image_repo }}" >> $GITHUB_OUTPUT + - name: Create Docker-Compose File from Inputs id: create_compose shell: pwsh @@ -97,7 +103,7 @@ jobs: foreach ($img in $images) { $serviceName = $img.name $svc = @{} - $svc.image = "$env:IMAGE_REPO/$($serviceName):${{ env.TAG }}" # Use run_id tag + $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 @@ -177,7 +183,7 @@ jobs: $ENV_ARGS \ -v "$STAGING_DIR:$RESULTS_PATH" \ --rm \ - "${{ env.IMAGE_REPO }}/${{ inputs.testContainerName }}:${{ github.run_id }}" \ + "${{ steps.tags.outputs.image_repo_path }}/${{ inputs.testContainerName }}:${{ github.run_id }}" \ "$test_dir" # Add error handling if needed (e.g., exit script if a test run fails) if [ $? -ne 0 ]; then From c29160126266759ea86c1fa6813508b5d9f23780 Mon Sep 17 00:00:00 2001 From: Hong Kai LEE Date: Wed, 16 Apr 2025 18:02:04 +0800 Subject: [PATCH 11/24] Update build_new.yml --- .github/workflows/build_new.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index 046b2ca..290660c 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.yml @@ -34,9 +34,9 @@ jobs: # We wrap the image configuration in a single 'image_config' key # to pass it more easily if needed, but primarily access sub-keys directly. image_config: - # - IMAGE_NAME: backend-aimingmedai - # BUILD_CONTEXT: ./app/backend - # DOCKERFILE: ./app/backend/Dockerfile + - IMAGE_NAME: backend-aimingmedai + BUILD_CONTEXT: ./app/backend + DOCKERFILE: ./app/backend/Dockerfile - IMAGE_NAME: frontend-aimingmedai BUILD_CONTEXT: ./app/frontend DOCKERFILE: ./app/frontend/Dockerfile.test From 9a1bc2f89d4ae24f548f3a055231876cd15ecb8b Mon Sep 17 00:00:00 2001 From: leehk Date: Wed, 16 Apr 2025 21:13:16 +0800 Subject: [PATCH 12/24] try --- .github/workflows/template_test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index 3a35acf..7683154 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -152,8 +152,8 @@ jobs: - name: Run Tests shell: bash run: | - TEST_DIRS='${{ inputs.tests }}' # Get JSON array string - TEST_ENVS_JSON='${{ inputs.testEnvs }}' # Get JSON array string + 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" @@ -175,7 +175,7 @@ jobs: echo "Using Network: $COMPOSE_NETWORK_NAME" # Loop through test directories and execute tests - echo "$TEST_DIRS" | jq -c '.[]' | while read test_dir; do + echo "$TEST_DIRS" | jq -r '.[]' | while read test_dir; do test_dir=$(echo $test_dir | sed 's/"//g') # Remove quotes echo "Running test: $test_dir" docker run \ From eecd552966b14c6c2673448cabf2d135a5606b2e Mon Sep 17 00:00:00 2001 From: leehk Date: Wed, 16 Apr 2025 21:30:15 +0800 Subject: [PATCH 13/24] try with inputs.tests --- .github/workflows/template_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index 7683154..1ffb473 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -152,8 +152,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 }}' # Get JSON array string + TEST_ENVS_JSON='${{ inputs.testEnvs }}' # Get JSON array string RESULTS_PATH="${{ inputs.testResultsPath }}" STAGING_DIR="${{ runner.temp }}/test-results" # Use runner temp dir for results mkdir -p "$STAGING_DIR" From bc5c88796fef3428ddc2ebb2fe030e4fd415026a Mon Sep 17 00:00:00 2001 From: leehk Date: Wed, 16 Apr 2025 21:46:45 +0800 Subject: [PATCH 14/24] update with tags --- .github/workflows/template_test.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index 1ffb473..bcf9f33 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -71,11 +71,14 @@ jobs: sudo rm -rf "/usr/local/share/boost" sudo rm -rf "$AGENT_TOOLSDIRECTORY" - - name: Define Image Repo tags + - name: Define Image Repo and other tags # Define tags consistently using inputs id: tags run: | echo "image_repo_path=${{ inputs.image_repo }}" >> $GITHUB_OUTPUT + echo "TEST_DIRS_TAG=${{ inputs.tests }}" >> $GITHUB_OUTPUT + echo "TEST_ENVS_TAG=${{ inputs.testEnvs }}" >> $GITHUB_OUTPUT + - name: Create Docker-Compose File from Inputs id: create_compose @@ -152,8 +155,8 @@ jobs: - name: Run Tests shell: bash run: | - TEST_DIRS='${{ inputs.tests }}' # Get JSON array string - TEST_ENVS_JSON='${{ inputs.testEnvs }}' # Get JSON array string + TEST_DIRS="${{ steps.tags.outputs.TEST_DIRS_TAG }}" # Get JSON array string + TEST_ENVS_JSON="${{ steps.tags.outputs.TEST_ENVS_TAG }}" # Get JSON array string RESULTS_PATH="${{ inputs.testResultsPath }}" STAGING_DIR="${{ runner.temp }}/test-results" # Use runner temp dir for results mkdir -p "$STAGING_DIR" @@ -175,7 +178,7 @@ jobs: echo "Using Network: $COMPOSE_NETWORK_NAME" # Loop through test directories and execute tests - echo "$TEST_DIRS" | jq -r '.[]' | while read test_dir; do + echo "$TEST_DIRS" | jq -c '.[]' | while read test_dir; do test_dir=$(echo $test_dir | sed 's/"//g') # Remove quotes echo "Running test: $test_dir" docker run \ From 3f00677d866222ac3a366b8f3669f1b25d50caa2 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 05:36:33 +0800 Subject: [PATCH 15/24] test --- .github/workflows/build_new.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index 290660c..7a13ed6 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.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: > From ac8570dd1fe9f99236c3017156bafcee9b3f408e Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 05:51:19 +0800 Subject: [PATCH 16/24] try --- .github/workflows/template_test.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index bcf9f33..0215e7d 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -76,9 +76,6 @@ jobs: id: tags run: | echo "image_repo_path=${{ inputs.image_repo }}" >> $GITHUB_OUTPUT - echo "TEST_DIRS_TAG=${{ inputs.tests }}" >> $GITHUB_OUTPUT - echo "TEST_ENVS_TAG=${{ inputs.testEnvs }}" >> $GITHUB_OUTPUT - - name: Create Docker-Compose File from Inputs id: create_compose @@ -155,8 +152,8 @@ jobs: - name: Run Tests shell: bash run: | - TEST_DIRS="${{ steps.tags.outputs.TEST_DIRS_TAG }}" # Get JSON array string - TEST_ENVS_JSON="${{ steps.tags.outputs.TEST_ENVS_TAG }}" # Get JSON array string + TEST_DIRS="${{ inputs.tests }}" + TEST_ENVS_JSON="${{ inputs.testEnvs }}" # Get JSON array string RESULTS_PATH="${{ inputs.testResultsPath }}" STAGING_DIR="${{ runner.temp }}/test-results" # Use runner temp dir for results mkdir -p "$STAGING_DIR" From de100b02a37521d45ccaf8f39d8f2968692f8d27 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 06:01:21 +0800 Subject: [PATCH 17/24] remove --- .github/workflows/build_new.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index 7a13ed6..290660c 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.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: > From c90b5af6c1b631a15f0a9686fa4b9eb4eb7d9504 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 06:45:05 +0800 Subject: [PATCH 18/24] test --- .github/workflows/template_test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index 0215e7d..e266069 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -161,12 +161,13 @@ jobs: # Prepare environment variables for docker run ENV_ARGS="" if [[ "$TEST_ENVS_JSON" != "[]" ]]; then + # Convert JSON array string to individual env vars while IFS= read -r line; do ENV_ARGS+=" -e \"$line\"" done <<< $(echo "$TEST_ENVS_JSON" | jq -r '.[]') else # Add a dummy env var if none are provided, as required by original script logic - ENV_ARGS+=" -e DUMMY_ENV_TEST_RUN_ID=${{ github.run_id }}" + ENV_ARGS+=" -e DUMMY_ENV_TEST_RUN_ID=${{ github.run_id }}" fi echo "Env args: $ENV_ARGS" # Debugging From 047c01b435652431bd28b6a8b51e8c52ed4a84a7 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 06:52:29 +0800 Subject: [PATCH 19/24] update key --- .github/workflows/template_test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index e266069..a6efda0 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -76,6 +76,8 @@ jobs: id: tags run: | echo "image_repo_path=${{ inputs.image_repo }}" >> $GITHUB_OUTPUT + echo "DEEPSEEK_API_KEY=${{ secrets.DEEPSEEK_API_KEY }}" >> $GITHUB_OUTPUT + echo "TAVILY_API_KEY=${{ secrets.TAVILY_API_KEY }}" >> $GITHUB_OUTPUT - name: Create Docker-Compose File from Inputs id: create_compose @@ -83,8 +85,8 @@ jobs: run: | # Load Inputs (parse JSON strings) $imagesJson = '${{ inputs.images }}' - $deepseekApiKey = '${{ secrets.DEEPSEEK_API_KEY }}' - $tavilyApiKey = '${{ secrets.TAVILY_API_KEY }}' + $deepseekApiKey = "${{ steps.tags.outputs.DEEPSEEK_API_KEY }}" + $tavilyApiKey = "${{ steps.tags.outputs.TAVILY_API_KEY }}" # Substitute secrets *before* parsing JSON using environment variables # Be very careful with escaping if secrets contain special JSON characters $imagesJson = $imagesJson -replace '"DEEPSEEK_API_KEY": ""', "`"DEEPSEEK_API_KEY`": `"$deepseekApiKey`"" From f02bddb2eb05a45c69f393fd26a2d4abf7e7c773 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 07:18:45 +0800 Subject: [PATCH 20/24] update with fake api key --- .github/workflows/build_new.yml | 4 ++-- .github/workflows/template_test.yml | 10 +--------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index 290660c..8186934 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.yml @@ -93,8 +93,8 @@ jobs: "env": { "ENVIRONMENT": "dev", "TESTING": "1", - "DEEPSEEK_API_KEY": "", - "TAVILY_API_KEY": "" + "DEEPSEEK_API_KEY": "sk-XXXXXXXXXX", + "TAVILY_API_KEY": "tvly-dev-wXXXXXX" } }, diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index a6efda0..e384554 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -76,8 +76,6 @@ jobs: id: tags run: | echo "image_repo_path=${{ inputs.image_repo }}" >> $GITHUB_OUTPUT - echo "DEEPSEEK_API_KEY=${{ secrets.DEEPSEEK_API_KEY }}" >> $GITHUB_OUTPUT - echo "TAVILY_API_KEY=${{ secrets.TAVILY_API_KEY }}" >> $GITHUB_OUTPUT - name: Create Docker-Compose File from Inputs id: create_compose @@ -85,12 +83,6 @@ jobs: run: | # Load Inputs (parse JSON strings) $imagesJson = '${{ inputs.images }}' - $deepseekApiKey = "${{ steps.tags.outputs.DEEPSEEK_API_KEY }}" - $tavilyApiKey = "${{ steps.tags.outputs.TAVILY_API_KEY }}" - # Substitute secrets *before* parsing JSON using environment variables - # Be very careful with escaping if secrets contain special JSON characters - $imagesJson = $imagesJson -replace '"DEEPSEEK_API_KEY": ""', "`"DEEPSEEK_API_KEY`": `"$deepseekApiKey`"" - $imagesJson = $imagesJson -replace '"TAVILY_API_KEY": ""', "`"TAVILY_API_KEY`": `"$tavilyApiKey`"" Write-Host "Substituted Images JSON: $imagesJson" # Debugging - remove sensitive info if public $images = $imagesJson | ConvertFrom-Json @@ -155,7 +147,7 @@ jobs: shell: bash run: | TEST_DIRS="${{ inputs.tests }}" - TEST_ENVS_JSON="${{ inputs.testEnvs }}" # Get JSON array string + TEST_ENVS_JSON="${{ inputs.testEnvs }}" RESULTS_PATH="${{ inputs.testResultsPath }}" STAGING_DIR="${{ runner.temp }}/test-results" # Use runner temp dir for results mkdir -p "$STAGING_DIR" From 5e64e3711126699d380d2564e02259d3f4d17ad8 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 07:28:13 +0800 Subject: [PATCH 21/24] try --- .github/workflows/template_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index e384554..e1c1689 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="${{ inputs.tests }}" - TEST_ENVS_JSON="${{ inputs.testEnvs }}" + TEST_DIRS=$(echo '${{ inputs.tests }}' | jq -c) + TEST_ENVS_JSON=$(echo '${{ inputs.testEnvs }}' | jq -c) RESULTS_PATH="${{ inputs.testResultsPath }}" STAGING_DIR="${{ runner.temp }}/test-results" # Use runner temp dir for results mkdir -p "$STAGING_DIR" From 0bf8cfae0a4baf5280682c68773fbcd39b306000 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 08:05:04 +0800 Subject: [PATCH 22/24] update --- .github/workflows/template_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index e1c1689..2476859 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=$(echo '${{ inputs.tests }}' | jq -c) - TEST_ENVS_JSON=$(echo '${{ inputs.testEnvs }}' | jq -c) + TEST_DIRS=$(echo '${{ inputs.tests }}' | jq) + TEST_ENVS_JSON=$(echo '${{ inputs.testEnvs }}' | jq) RESULTS_PATH="${{ inputs.testResultsPath }}" STAGING_DIR="${{ runner.temp }}/test-results" # Use runner temp dir for results mkdir -p "$STAGING_DIR" From 0a79654728c66feec164af7607308a60e6648950 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 09:50:09 +0800 Subject: [PATCH 23/24] update --- .github/workflows/template_test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index 2476859..7011260 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=$(echo '${{ inputs.tests }}' | jq) - TEST_ENVS_JSON=$(echo '${{ inputs.testEnvs }}' | jq) + TEST_DIRS="${{ inputs.tests }}" + TEST_ENVS_JSON="${{ inputs.testEnvs }}" RESULTS_PATH="${{ inputs.testResultsPath }}" STAGING_DIR="${{ runner.temp }}/test-results" # Use runner temp dir for results mkdir -p "$STAGING_DIR" @@ -170,7 +170,7 @@ jobs: echo "Using Network: $COMPOSE_NETWORK_NAME" # Loop through test directories and execute tests - echo "$TEST_DIRS" | jq -c '.[]' | while read test_dir; do + echo "$TEST_DIRS" | jq -r '.[]' | while read test_dir; do test_dir=$(echo $test_dir | sed 's/"//g') # Remove quotes echo "Running test: $test_dir" docker run \ From 3bd2ecbafcfc140cb52cf3e2409bbf5debb40a67 Mon Sep 17 00:00:00 2001 From: leehk Date: Thu, 17 Apr 2025 10:05:10 +0800 Subject: [PATCH 24/24] try --- .github/workflows/template_test.yml | 7 ++++--- app/backend/Dockerfile | 30 +++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index 7011260..30013d1 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -156,9 +156,10 @@ jobs: ENV_ARGS="" if [[ "$TEST_ENVS_JSON" != "[]" ]]; then # Convert JSON array string to individual env vars - while IFS= read -r line; do - ENV_ARGS+=" -e \"$line\"" - done <<< $(echo "$TEST_ENVS_JSON" | jq -r '.[]') + IFS=',' read -r -a env_array <<< $(echo "$TEST_ENVS_JSON" | jq -r '.[][]') + for env in "${env_array[@]}"; do + ENV_ARGS+=" -e \"$env\"" + done else # Add a dummy env var if none are provided, as required by original script logic ENV_ARGS+=" -e DUMMY_ENV_TEST_RUN_ID=${{ github.run_id }}" diff --git a/app/backend/Dockerfile b/app/backend/Dockerfile index 8de3d73..061acf8 100644 --- a/app/backend/Dockerfile +++ b/app/backend/Dockerfile @@ -1,5 +1,5 @@ # pull official base image -FROM python:3.11-slim-bullseye +FROM python:3.11-slim-bullseye AS base # create directory for the app user RUN mkdir -p /home/app @@ -16,16 +16,13 @@ WORKDIR $APP_HOME # set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 -ENV ENVIRONMENT=prod -ENV TESTING=0 - # add app COPY . $APP_HOME # install python dependencies RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv && rm -rf ~/.cache/pip -RUN pipenv install --deploy --dev +RUN pipenv install --deploy # chown all the files to the app user RUN chown -R app:app $APP_HOME @@ -33,8 +30,29 @@ RUN chown -R app:app $APP_HOME # change to the app user USER app + + +# TEST +FROM base AS test + +ENV ENVIRONMENT=dev +ENV TESTING=1 + +RUN pipenv install --deploy --dev + +# run tests +RUN pipenv run pytest tests --disable-warnings + + + +# BUILD +FROM base AS builder + +ENV ENVIRONMENT=prod +ENV TESTING=0 + # expose the port the app runs on EXPOSE 80 # run uvicorn -CMD ["pipenv", "run", "uvicorn", "main:app", "--reload", "--workers", "1", "--host", "0.0.0.0", "--port", "80"] \ No newline at end of file +CMD ["pipenv", "run", "uvicorn", "main:app", "--reload", "--workers", "1", "--host", "0.0.0.0", "--port", "80"]