From b567826243b9e34466a2310abd57357521c5da65 Mon Sep 17 00:00:00 2001 From: Rohan Dudam Date: Fri, 21 Jul 2023 12:03:58 +0530 Subject: [PATCH] Added job to run the lambda tests on localstack before staging and production deployment --- .../workflows/url_filtering_lambda_rohini.yml | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/.github/workflows/url_filtering_lambda_rohini.yml b/.github/workflows/url_filtering_lambda_rohini.yml index 0570439..25cd38c 100644 --- a/.github/workflows/url_filtering_lambda_rohini.yml +++ b/.github/workflows/url_filtering_lambda_rohini.yml @@ -5,10 +5,49 @@ on: paths: - 'url_filtering_lambda_rohini/**' - '.github/workflows/url_filtering_lambda_rohini.yml' + - 'tests/docker-compose.yaml' + - 'tests/test_url_filter_lambda_on_localstack.py' + - 'tests/testutils.py' jobs: + test-lambda: + name: Test Lambda on LocalStack + environment: + name: localstack-url-filter + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Set up Docker Compose + run: | + sudo apt-get update + sudo apt-get install -y docker-compose + - name: Start LocalStack + run: | + cd tests/ + docker-compose -f docker-compose.yaml up -d + - name: Wait for LocalStack to be ready + run: | + timeout 300 bash -c 'until echo > /dev/tcp/localhost/4566; do sleep 1; done' + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.8" # Replace with your desired Python version + - name: Install dependencies + run: | + cd tests/ + pip install -r requirements.txt # Replace with your actual requirements file + - name: Run tests + run: | + cd tests/ + pytest -v -s test_url_filter_lambda_on_localstack.py + - name: Stop LocalStack + run: | + cd tests/ + docker-compose -f docker-compose.yaml down deply-staging: name: Deploy to staging + needs: test-lambda if: contains(github.event.ref, '-sprint-') environment: name: staging-url-filter @@ -28,16 +67,20 @@ jobs: AWS_DEFAULT_REGION: ${{ secrets.REGION }} deploy-production: - runs-on: ubuntu-latest + name: Deploy to production + needs: test-lambda if: github.event.ref == 'refs/heads/master' + environment: + name: production-url-filter + runs-on: ubuntu-latest steps: - uses: actions/checkout@master - name: Deploy code to Lambda uses: qxf2/py-lambda-action@v1.0.3 with: lambda_directory: 'url_filtering_lambda_rohini' - lambda_function_name: 'arn:aws:lambda:ap-south-1:285993504765:function:URLFilteringLambdaRohini' - lambda_layer_arn: 'arn:aws:lambda:ap-south-1:285993504765:layer:rohinilayer' + lambda_function_name: ${{secrets.ARN }} + lambda_layer_arn: ${{ secrets.LAYER_ARN }} requirements_txt: 'url_filtering_lambda_rohini/requirements.txt' env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}