From 9ae57d5963591984ca3d1b3ffd1db114b3fde8a1 Mon Sep 17 00:00:00 2001 From: Gabriel Koo Date: Sat, 31 May 2025 22:25:06 +0800 Subject: [PATCH 1/8] ci: Add GitHub Actions workflow to test deploy.sh in different environments --- .github/workflows/test-deploy.yml | 43 +++++++++++++++++++++++++++++++ deploy.sh | 5 ++++ 2 files changed, 48 insertions(+) create mode 100644 .github/workflows/test-deploy.yml diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml new file mode 100644 index 0000000..a75cc8e --- /dev/null +++ b/.github/workflows/test-deploy.yml @@ -0,0 +1,43 @@ +name: Test Deploy Script + +on: + push: + branches: + - main + pull_request: + branches: + - '*' + +jobs: + test-deploy-script: + runs-on: ubuntu-latest + strategy: + matrix: + environment: + - name: with-cloudshell + aws_execution_env: CloudShell + - name: without-cloudshell + aws_execution_env: '' + + name: Test deploy.sh in ${{ matrix.environment.name }} environment + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + + - name: Install AWS SAM CLI + run: pip install aws-sam-cli + + - name: Make sh scripts executable + run: chmod +x deploy.sh prepare_source.sh + + - name: Test deploy.sh script + env: + AWS_EXECUTION_ENV: ${{ matrix.environment.aws_execution_env }} + CI: true + run: ./deploy.sh diff --git a/deploy.sh b/deploy.sh index b747297..19b0689 100755 --- a/deploy.sh +++ b/deploy.sh @@ -27,4 +27,9 @@ fi ./prepare_source.sh $NO_EMBEDDINGS sam build $USE_CONTAINER + +if [[ ! -z "$CI" ]]; then + exit +fi + sam deploy --guided From c987e205a59b9382157b03dd3675ca00f80e91b3 Mon Sep 17 00:00:00 2001 From: Gabriel Koo Date: Sat, 31 May 2025 22:40:06 +0800 Subject: [PATCH 2/8] fix: split into two jobs instead --- .github/workflows/test-deploy.yml | 31 ++++++++++++++++--------------- deploy.sh | 1 + 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index a75cc8e..b450f67 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -9,17 +9,9 @@ on: - '*' jobs: - test-deploy-script: + test-deploy-standard: runs-on: ubuntu-latest - strategy: - matrix: - environment: - - name: with-cloudshell - aws_execution_env: CloudShell - - name: without-cloudshell - aws_execution_env: '' - - name: Test deploy.sh in ${{ matrix.environment.name }} environment + name: Test deploy.sh in standard environment steps: - name: Checkout code @@ -33,11 +25,20 @@ jobs: - name: Install AWS SAM CLI run: pip install aws-sam-cli - - name: Make sh scripts executable - run: chmod +x deploy.sh prepare_source.sh + - name: Test deploy.sh script + run: ./deploy.sh + + test-deploy-cloudshell: + runs-on: ubuntu-latest + name: Test deploy.sh in CloudShell environment + container: + image: public.ecr.aws/sam/build-provided.al2023:latest-x86_64 + env: + AWS_EXECUTION_ENV: CloudShell + + steps: + - name: Checkout code + uses: actions/checkout@v3 - name: Test deploy.sh script - env: - AWS_EXECUTION_ENV: ${{ matrix.environment.aws_execution_env }} - CI: true run: ./deploy.sh diff --git a/deploy.sh b/deploy.sh index 19b0689..9990a1a 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,6 +1,7 @@ #!/bin/bash PYTHON_VERSION=3.12 +SAM_CLI_TELEMETRY=0 # Parse command line arguments while [[ $# -gt 0 ]]; do From c0d7a67b61cbee033d4a9744d0305270f9cc3ad9 Mon Sep 17 00:00:00 2001 From: Gabriel Koo Date: Sat, 31 May 2025 22:55:39 +0800 Subject: [PATCH 3/8] fix: base image for testing --- .github/workflows/test-deploy.yml | 7 ++++++- deploy.sh | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index b450f67..fd5af06 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -32,7 +32,7 @@ jobs: runs-on: ubuntu-latest name: Test deploy.sh in CloudShell environment container: - image: public.ecr.aws/sam/build-provided.al2023:latest-x86_64 + image: public.ecr.aws/amazonlinux/amazonlinux:2023 env: AWS_EXECUTION_ENV: CloudShell @@ -40,5 +40,10 @@ jobs: - name: Checkout code uses: actions/checkout@v3 + - name: Install dependencies + run: | + yum install -y sudo python3-pip + pip3 install aws-sam-cli + - name: Test deploy.sh script run: ./deploy.sh diff --git a/deploy.sh b/deploy.sh index 9990a1a..ec35178 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,7 +1,7 @@ #!/bin/bash -PYTHON_VERSION=3.12 -SAM_CLI_TELEMETRY=0 +export PYTHON_VERSION=3.12 +export SAM_CLI_TELEMETRY=0 # Parse command line arguments while [[ $# -gt 0 ]]; do From 0f9de4084497a9dd1b5a661a53dfc3bf96db79e1 Mon Sep 17 00:00:00 2001 From: Gabriel Koo Date: Sun, 1 Jun 2025 01:42:51 +0800 Subject: [PATCH 4/8] feat: add e2e --- .../{test-deploy.yml => test-build.yml} | 21 ++++++++++++------- app/run.sh | 0 2 files changed, 14 insertions(+), 7 deletions(-) rename .github/workflows/{test-deploy.yml => test-build.yml} (68%) mode change 100644 => 100755 app/run.sh diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-build.yml similarity index 68% rename from .github/workflows/test-deploy.yml rename to .github/workflows/test-build.yml index fd5af06..eb40643 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-build.yml @@ -1,4 +1,4 @@ -name: Test Deploy Script +name: Test Build Script on: push: @@ -9,7 +9,7 @@ on: - '*' jobs: - test-deploy-standard: + test-local-build-and-e2e: runs-on: ubuntu-latest name: Test deploy.sh in standard environment @@ -28,7 +28,14 @@ jobs: - name: Test deploy.sh script run: ./deploy.sh - test-deploy-cloudshell: + - name: Test local uvicorn/FastAPI server + run: | + mv .aws-sam/build/BedrockAccessGatewayLayer/python ./api + (cd app && ./run.sh &) + curl localhost:8000/health | jq + curl localhost:8000/api/v1/models -H 'Authorization: Bearer bedrock' | jq + + test-cloudshell-build: runs-on: ubuntu-latest name: Test deploy.sh in CloudShell environment container: @@ -37,13 +44,13 @@ jobs: AWS_EXECUTION_ENV: CloudShell steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Install dependencies run: | - yum install -y sudo python3-pip + yum install -y sudo python3-pip tar pip3 install aws-sam-cli + - name: Checkout code + uses: actions/checkout@v3 + - name: Test deploy.sh script run: ./deploy.sh diff --git a/app/run.sh b/app/run.sh old mode 100644 new mode 100755 From 2e642de1091ead04df8395ccefdee291454f52af Mon Sep 17 00:00:00 2001 From: Gabriel Koo Date: Sun, 1 Jun 2025 01:48:01 +0800 Subject: [PATCH 5/8] fix: install git --- .github/workflows/test-build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index eb40643..df1aa96 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -30,8 +30,8 @@ jobs: - name: Test local uvicorn/FastAPI server run: | - mv .aws-sam/build/BedrockAccessGatewayLayer/python ./api - (cd app && ./run.sh &) + mv .aws-sam/build/BedrockAccessGatewayLayer/python ./app + (cd app && ls -la && ./run.sh &) curl localhost:8000/health | jq curl localhost:8000/api/v1/models -H 'Authorization: Bearer bedrock' | jq @@ -46,7 +46,7 @@ jobs: steps: - name: Install dependencies run: | - yum install -y sudo python3-pip tar + yum install -y sudo python3-pip tar git pip3 install aws-sam-cli - name: Checkout code From 6b2a4b610127a265890b16816ff4c807758884bc Mon Sep 17 00:00:00 2001 From: Gabriel Koo Date: Sun, 1 Jun 2025 01:57:47 +0800 Subject: [PATCH 6/8] fix test --- .github/workflows/test-build.yml | 2 +- prepare_source.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index df1aa96..bd74929 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -30,7 +30,7 @@ jobs: - name: Test local uvicorn/FastAPI server run: | - mv .aws-sam/build/BedrockAccessGatewayLayer/python ./app + mv .aws-sam/build/BedrockAccessGatewayLayer/python/* ./app (cd app && ls -la && ./run.sh &) curl localhost:8000/health | jq curl localhost:8000/api/v1/models -H 'Authorization: Bearer bedrock' | jq diff --git a/prepare_source.sh b/prepare_source.sh index 25deb3e..ad56f44 100755 --- a/prepare_source.sh +++ b/prepare_source.sh @@ -63,6 +63,9 @@ fi cp -r $REPO_DIR/src/api app/api +# To surpress warnings +echo "" > app/requirements.txt + # Remove "Manum" from requirements.txt, as LWA is used instead. grep -v "mangum" $REPO_DIR/src/requirements.txt > layer/requirements.txt grep -v "Mangum" $REPO_DIR/src/api/app.py > app/api/app.py From e21e3e2a20d490810bae82c805b688145a8228d6 Mon Sep 17 00:00:00 2001 From: Gabriel Koo Date: Sun, 1 Jun 2025 02:04:09 +0800 Subject: [PATCH 7/8] fix: wait for local server to be ready --- .github/workflows/test-build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index bd74929..6e4eddc 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -31,7 +31,8 @@ jobs: - name: Test local uvicorn/FastAPI server run: | mv .aws-sam/build/BedrockAccessGatewayLayer/python/* ./app - (cd app && ls -la && ./run.sh &) + (cd app && ./run.sh &) + timeout 30 bash -c 'while ! nc -z localhost 8000; do sleep 1; done' curl localhost:8000/health | jq curl localhost:8000/api/v1/models -H 'Authorization: Bearer bedrock' | jq From a2fddea0107cfcbb3df81f0aa37b37c532868ad7 Mon Sep 17 00:00:00 2001 From: Gabriel Koo <16297877+gabrielkoo@users.noreply.github.com> Date: Sun, 1 Jun 2025 02:11:54 +0800 Subject: [PATCH 8/8] Update test-build.yml --- .github/workflows/test-build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index 6e4eddc..ad8ba95 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -1,6 +1,8 @@ name: Test Build Script on: + schedule: + - cron: "0 0 * * 0" push: branches: - main