-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial smoke test and associated GHA pipeline
- Loading branch information
Showing
13 changed files
with
350 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: Publish & Deploy Smoke Test to S3 | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
workflow_dispatch: | ||
inputs: | ||
environment: | ||
type: environment | ||
description: The environment to deploy to. | ||
|
||
jobs: | ||
detect-environments: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
environments: ${{ steps.environments.outputs.result }} | ||
steps: | ||
- uses: actions/github-script@v6 | ||
id: environments | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
result-encoding: json | ||
script: | | ||
if (context.payload?.inputs?.environment) return [context.payload?.inputs?.environment]; | ||
const {data: {environments}} = | ||
await github.request(`GET /repos/${process.env.GITHUB_REPOSITORY}/environments`); | ||
return environments.map(e => e.name) | ||
publish-deploy: | ||
runs-on: ubuntu-latest | ||
needs: [detect-environments] | ||
strategy: | ||
matrix: | ||
environment: ${{ fromJSON(needs.detect-environments.outputs.environments) }} | ||
environment: ${{ matrix.environment }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.12 | ||
|
||
- name: Install aws cli | ||
run: | | ||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | ||
unzip -q awscliv2.zip | ||
sudo ./aws/install --update | ||
sudo apt-get update | ||
sudo apt-get install -y rsync | ||
- name: Set up AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1-node16 | ||
with: | ||
aws-access-key-id: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.DEPLOY_AWS_SECRET_ACCESS_KEY }} | ||
aws-region: eu-west-2 | ||
|
||
- name: Upload Smoke Canary function to S3 | ||
run: | | ||
aws s3 cp src/smoke_canary.py s3://${{ matrix.environment }}-canary-code-bucket/main/smoke_canary.py | ||
- name: Get S3 Object version | ||
id: canary-code-s3-version | ||
run: | | ||
S3_OBJECT_VERSION=$(aws s3api list-object-versions --bucket ${{ matrix.environment }}-canary-code-bucket --prefix main/smoke_canary.py --query 'Versions[?IsLatest].[VersionId]' --output text) | ||
echo "VERSION=$S3_OBJECT_VERSION" >> "$GITHUB_OUTPUT" | ||
- name: Update AWS Synthetics Canary function code in development environment | ||
if: ${{ matrix.environment == 'development' }} | ||
run: | | ||
aws synthetics update-canary \ | ||
--function-name development-main \ | ||
--code=S3Bucket=${{ matrix.environment }}-canary-code-bucket,S3Key=main/smoke_canary.py,S3Version=${{ steps.canary-code-s3-version.outputs.VERSION }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.12.4 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
name = "digital-land-info-smoke-tests" | ||
version = "0.0.1" | ||
|
||
[tool.pytest.ini_options] | ||
pythonpath = "src" | ||
# Necessary to prevent pytest loading conftest.py in parent directories since the Smoke tests are standalone | ||
testpaths = "." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Faker | ||
selenium==4.15.1 | ||
urllib3==1.26.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.10 | ||
# by the following command: | ||
# | ||
# pip-compile requirements.in | ||
# | ||
attrs==24.2.0 | ||
# via | ||
# outcome | ||
# trio | ||
certifi==2024.8.30 | ||
# via selenium | ||
exceptiongroup==1.2.2 | ||
# via | ||
# trio | ||
# trio-websocket | ||
faker==28.0.0 | ||
# via -r requirements.in | ||
h11==0.14.0 | ||
# via wsproto | ||
idna==3.8 | ||
# via trio | ||
outcome==1.3.0.post0 | ||
# via trio | ||
pysocks==1.7.1 | ||
# via urllib3 | ||
python-dateutil==2.9.0.post0 | ||
# via faker | ||
selenium==4.15.1 | ||
# via -r requirements.in | ||
six==1.16.0 | ||
# via python-dateutil | ||
sniffio==1.3.1 | ||
# via trio | ||
sortedcontainers==2.4.0 | ||
# via trio | ||
trio==0.26.2 | ||
# via | ||
# selenium | ||
# trio-websocket | ||
trio-websocket==0.11.1 | ||
# via selenium | ||
urllib3[socks]==1.26.18 | ||
# via | ||
# -r requirements.in | ||
# selenium | ||
wsproto==1.2.0 | ||
# via trio-websocket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-r requirements.txt | ||
pytest==8.3.2 | ||
aws-cdk-lib==2.154.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.9 | ||
# by the following command: | ||
# | ||
# pip-compile requirements_test.in | ||
# | ||
attrs==24.2.0 | ||
# via | ||
# -r requirements.txt | ||
# cattrs | ||
# jsii | ||
# outcome | ||
# trio | ||
aws-cdk-asset-awscli-v1==2.2.202 | ||
# via aws-cdk-lib | ||
aws-cdk-asset-kubectl-v20==2.1.2 | ||
# via aws-cdk-lib | ||
aws-cdk-asset-node-proxy-agent-v6==2.0.3 | ||
# via aws-cdk-lib | ||
aws-cdk-cloud-assembly-schema==36.0.20 | ||
# via aws-cdk-lib | ||
aws-cdk-lib==2.154.1 | ||
# via -r requirements_test.in | ||
cattrs==23.2.3 | ||
# via jsii | ||
certifi==2024.8.30 | ||
# via | ||
# -r requirements.txt | ||
# selenium | ||
constructs==10.3.0 | ||
# via aws-cdk-lib | ||
exceptiongroup==1.2.2 | ||
# via | ||
# -r requirements.txt | ||
# cattrs | ||
# pytest | ||
# trio | ||
# trio-websocket | ||
faker==28.0.0 | ||
# via -r requirements.txt | ||
h11==0.14.0 | ||
# via | ||
# -r requirements.txt | ||
# wsproto | ||
idna==3.8 | ||
# via | ||
# -r requirements.txt | ||
# trio | ||
importlib-resources==6.4.4 | ||
# via jsii | ||
iniconfig==2.0.0 | ||
# via pytest | ||
jsii==1.103.0 | ||
# via | ||
# aws-cdk-asset-awscli-v1 | ||
# aws-cdk-asset-kubectl-v20 | ||
# aws-cdk-asset-node-proxy-agent-v6 | ||
# aws-cdk-cloud-assembly-schema | ||
# aws-cdk-lib | ||
# constructs | ||
outcome==1.3.0.post0 | ||
# via | ||
# -r requirements.txt | ||
# trio | ||
packaging==24.1 | ||
# via pytest | ||
pluggy==1.5.0 | ||
# via pytest | ||
publication==0.0.3 | ||
# via | ||
# aws-cdk-asset-awscli-v1 | ||
# aws-cdk-asset-kubectl-v20 | ||
# aws-cdk-asset-node-proxy-agent-v6 | ||
# aws-cdk-cloud-assembly-schema | ||
# aws-cdk-lib | ||
# constructs | ||
# jsii | ||
pysocks==1.7.1 | ||
# via | ||
# -r requirements.txt | ||
# urllib3 | ||
pytest==8.3.2 | ||
# via -r requirements_test.in | ||
python-dateutil==2.9.0.post0 | ||
# via | ||
# -r requirements.txt | ||
# faker | ||
# jsii | ||
selenium==4.15.1 | ||
# via -r requirements.txt | ||
six==1.16.0 | ||
# via | ||
# -r requirements.txt | ||
# python-dateutil | ||
sniffio==1.3.1 | ||
# via | ||
# -r requirements.txt | ||
# trio | ||
sortedcontainers==2.4.0 | ||
# via | ||
# -r requirements.txt | ||
# trio | ||
tomli==2.0.1 | ||
# via pytest | ||
trio==0.26.2 | ||
# via | ||
# -r requirements.txt | ||
# selenium | ||
# trio-websocket | ||
trio-websocket==0.11.1 | ||
# via | ||
# -r requirements.txt | ||
# selenium | ||
typeguard==2.13.3 | ||
# via | ||
# aws-cdk-asset-awscli-v1 | ||
# aws-cdk-asset-kubectl-v20 | ||
# aws-cdk-asset-node-proxy-agent-v6 | ||
# aws-cdk-cloud-assembly-schema | ||
# aws-cdk-lib | ||
# constructs | ||
# jsii | ||
typing-extensions==4.12.2 | ||
# via | ||
# cattrs | ||
# jsii | ||
urllib3[socks]==1.26.18 | ||
# via | ||
# -r requirements.txt | ||
# selenium | ||
wsproto==1.2.0 | ||
# via | ||
# -r requirements.txt | ||
# trio-websocket | ||
zipp==3.20.1 | ||
# via importlib-resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from aws_synthetics.selenium import synthetics_webdriver as syn_webdriver | ||
from aws_synthetics.common import synthetics_logger as logger | ||
from faker import Faker | ||
|
||
faker = Faker() | ||
|
||
|
||
def main(): | ||
logger.info("UUID: " + faker.uuid4()) | ||
url = "https://planning.data.gov.uk/" | ||
browser = syn_webdriver.Chrome() | ||
browser.get(url) | ||
browser.save_screenshot("loaded.png") | ||
|
||
response_code = syn_webdriver.get_http_response(url) | ||
if not response_code or response_code < 200 or response_code > 299: | ||
raise Exception("Failed to load page!") | ||
|
||
logger.info("Canary successfully executed.") | ||
|
||
|
||
def visit_and_screenshot(browser, url): | ||
browser = syn_webdriver.Chrome() | ||
browser.get(url) | ||
browser.save_screenshot("loaded.png") | ||
response_code = syn_webdriver.get_http_response(url) | ||
if not response_code or response_code < 200 or response_code > 299: | ||
raise Exception("Failed to load page!") | ||
|
||
|
||
def handler(event, context): | ||
return main() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
# Local wrapper for AWS synthetics_logger | ||
# Delegates interactions to local logger | ||
synthetics_logger = logging.getLogger(__name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from selenium import webdriver | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
# Local wrapper for AWS synthetics_webdriver | ||
# Delegates interactions to Selenium WebDriver Chrome | ||
class LocalSyntheticsWebdriver: | ||
@staticmethod | ||
def get_http_response(url): | ||
""" | ||
Get response code from http request to url | ||
""" | ||
import urllib.request as http_client | ||
|
||
request = http_client.Request(url, headers={"User-Agent": "Chrome"}) | ||
response_code = "" | ||
try: | ||
with http_client.urlopen(request) as response: | ||
response_code = response.code | ||
except Exception as ex: | ||
logger.error(ex) | ||
response_code = "error" | ||
finally: | ||
return response_code | ||
|
||
@staticmethod | ||
def Chrome(chrome_options=None): | ||
return webdriver.Chrome(options=chrome_options) | ||
|
||
|
||
synthetics_webdriver = LocalSyntheticsWebdriver() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from heartbeat_canary import main | ||
|
||
|
||
def test_heartbeat_canary_main(monkeypatch): | ||
main() |