Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ephemeral environment [Do not merge] #129

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
502c978
UML-2732 Build and use container image for Lambda function
Apr 22, 2024
7a80d20
Remove unused files
Apr 22, 2024
0f55aa1
Integration test fix
Apr 23, 2024
037f319
Allow TF destroy
Apr 25, 2024
e5b9dc6
remove no longer needed logic
nickdavis2001 Apr 29, 2024
7cae7e0
Create a Lambda execution role
Apr 30, 2024
45ee884
Add read permissions for jwt-key
Apr 30, 2024
2548dff
Fail CI if unit tests fail
Apr 30, 2024
8b869f7
Don't exit clean if fail unit tests
Apr 30, 2024
462ba1a
Fix unit tests
Apr 30, 2024
a068f57
test on different python versions
Apr 30, 2024
cb05393
no longer use python matrix for different versions
nickdavis2001 May 1, 2024
d463865
enable specific tests passed in as input (param)
nickdavis2001 May 1, 2024
4220eb7
full url for data lpa in prep for also being able to run against
nickdavis2001 May 1, 2024
5f1e4d9
fix typo and rename
nickdavis2001 May 1, 2024
93c93b5
path to test
nickdavis2001 May 1, 2024
641b26c
fix test path
nickdavis2001 May 1, 2024
2632dd6
typo
nickdavis2001 May 1, 2024
e8bbe91
test the smoke test step against pre-prod during dev build WIP
nickdavis2001 May 1, 2024
68e40e3
WIP experimental - run smoke tests against existing pre-prod to test the
nickdavis2001 May 1, 2024
17c7669
Use preprod details for preprod
May 1, 2024
72c4a75
return a 504 if anything is wrong
nickdavis2001 May 1, 2024
01810d3
remove unnneeded code (is the default)
nickdavis2001 May 1, 2024
8e0dd94
fix unit tests
nickdavis2001 May 1, 2024
aff6964
move smoke test against pre-prod, to path_to_live
nickdavis2001 May 1, 2024
82e55f3
Update README
May 1, 2024
f69460e
Merge pull request #130 from ministryofjustice/UML-3399-smoke-2
May 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/labeller.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
documentation:
- changed-files:
- any-glob-to-any-file: docs/**

terraform:
- changed-files:
- any-glob-to-any-file: terraform/**

github_actions:
- changed-files:
- any-glob-to-any-file: .github/workflows/**

docker:
- changed-files:
- any-glob-to-any-file:
- '**/Dockerfile'
- '**/docker-compose*'

python:
- changed-files:
- any-glob-to-any-file:
- '**/*.py'
- '**/requirements*.txt'

php:
- changed-files:
- any-glob-to-any-file: '**/*.php'

go:
- changed-files:
- any-glob-to-any-file: '**/*.go'

javascript:
- changed-files:
- any-glob-to-any-file: '**/*.js'

dependencies:
- changed-files:
- any-glob-to-any-file:
- '**/requirements*.txt'
- '**/package*.json'
- '**/yarn*.lock'
- '**/Gemfile*'
- '**/composer*.json'
- '**/go.mod'
- '**/go.sum'
- '**/vendor/**'
- '**/node_modules/**'
- '**/vendor/**'
107 changes: 107 additions & 0 deletions .github/workflows/_docker_build_scan_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
permissions:
actions: read
checks: read
contents: read
deployments: none
issues: none
packages: none
pull-requests: none
repository-projects: none
security-events: write
statuses: none

on:
workflow_call:
inputs:
build_latest:
description: Branch name
type: boolean
default: false
semver_tag:
description: Semver tag
required: true
type: string
outputs:
ecr_image_uri:
value: '${{ jobs.docker_build_scan_push.outputs.ecr_image_uri }}'
description: ECR image URI

jobs:
docker_build_scan_push:
name: 'Build, Scan and Push Lambdas'
runs-on: ubuntu-latest
outputs:
ecr_image_uri: ${{ steps.login_ecr.outputs.registry }}/${{ matrix.data.ecr_repository }}/${{ matrix.data.name }}:${{ inputs.semver_tag }}
strategy:
matrix:
data:
- name: lpa-data-lambda
docker_build_directory: lambda_functions/v1
ecr_repository: integrations
dockerfile: Function
env:
sarif_file: trivy-results.sarif
steps:
- uses: actions/checkout@v4

- name: Configure AWS Credentials With Assumed Role to Management
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: '${{ secrets.AWS_ACCESS_KEY_ID_ACTIONS }}'
aws-secret-access-key: '${{ secrets.AWS_SECRET_ACCESS_KEY_ACTIONS }}'
aws-region: eu-west-1
role-to-assume: 'arn:aws:iam::311462405659:role/integrations-ci'
role-duration-seconds: 900
role-session-name: OPGLPADataGithubAction

- name: ECR Login
id: login_ecr
uses: aws-actions/[email protected]
with:
registries: 311462405659

- name: Generate tags for Docker
env:
SEMVER_TAG: '${{ inputs.semver_tag }}'
ECR_REGISTRY: '${{ steps.login_ecr.outputs.registry }}'
ECR_REPOSITORY: '${{ matrix.data.ecr_repository }}/${{ matrix.data.name }}'
id: docker_tags
run: >
if ${{ inputs.build_latest }}; then
echo "tags=$ECR_REGISTRY/$ECR_REPOSITORY:latest,$ECR_REGISTRY/$ECR_REPOSITORY:$SEMVER_TAG" >> $GITHUB_OUTPUT
else
echo "tags=$ECR_REGISTRY/$ECR_REPOSITORY:$SEMVER_TAG" >> $GITHUB_OUTPUT
fi

echo "semver_tag=$ECR_REGISTRY/$ECR_REPOSITORY:$SEMVER_TAG" >>
$GITHUB_OUTPUT

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: 'linux/amd64'
file: >-
${{ matrix.data.docker_build_directory }}/Dockerfile-${{
matrix.data.dockerfile }}
push: true
tags: '${{ steps.docker_tags.outputs.tags }}'
provenance: false

- name: Trivy scan
uses: aquasecurity/[email protected]
with:
image-ref: '${{ steps.docker_tags.outputs.semver_tag }}'
severity: 'HIGH,CRITICAL'
format: sarif
output: '${{ env.sarif_file }}'

- name: Trivy scan upload to github
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: '${{ env.sarif_file }}'
83 changes: 83 additions & 0 deletions .github/workflows/_integration_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
permissions:
actions: read
checks: read
contents: read
deployments: none
issues: none
packages: none
pull-requests: none
repository-projects: none
security-events: write
statuses: none

on:
workflow_call:
inputs:
data_lpa_api_url:
description: 'The url of the data lpa api gateway'
required: true
type: string
working_directory:
description: 'Working Directory to run tests from'
required: true
type: string
tests_directory:
description: 'Directory containing Pytest tests'
required: true
type: string
specific_tests:
description: 'File path to specific Pytest tests - currently used to run 1 test as a smoke test'
required: false
type: string
default: ""
secrets:
AWS_ACCESS_KEY_ID_ACTIONS:
description: 'AWS Access Key ID'
required: false
AWS_SECRET_ACCESS_KEY_ACTIONS:
description: 'AWS Secret Access Key'
required: false

jobs:
integration_tests:
name: Run integration tests
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_ACTIONS }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_ACTIONS }}
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Configure AWS Credentials For integration tests
uses: aws-actions/configure-aws-credentials@v4
if: ${{ env.AWS_ACCESS_KEY_ID != '' && env.AWS_SECRET_ACCESS_KEY != '' }}
with:
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
role-duration-seconds: 900
role-session-name: GitHubActionsIntegrationTests

- name: Setup Python
uses: actions/setup-python@9a7ac94420f42ee15fc60ab88d0dca4be1fd5757
with:
python-version: "3.12"

- name: Install integration test requirements.txt
run: |
python -m pip install --upgrade pip
pip install -r ${{ inputs.tests_directory }}/requirements.txt

- name: Run tests with Pytest
env:
DATA_LPA_API_URL: ${{ inputs.data_lpa_api_url }}
SPECIFIC_TESTS: ${{ inputs.specific_tests}}
working-directory: ${{ inputs.working_directory }}
run: |
coverage run -m pytest $SPECIFIC_TESTS -v -s

- name: Generate Coverage Report
working-directory: ${{ inputs.working_directory }}
run: |
coverage report -m
38 changes: 38 additions & 0 deletions .github/workflows/_python_unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
permissions:
actions: read
checks: read
contents: read
deployments: none
issues: none
packages: none
pull-requests: none
repository-projects: none
security-events: write
statuses: none

on:
workflow_call: null

jobs:
run_unit_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- uses: unfor19/install-aws-cli-action@v1

- name: Install flake8
run: pip3 install flake8

- name: Run Flask8
run: 'flake8 --ignore Q000,W503 lambda_functions'

- name: Build Unit Test Container
run: docker compose build unit-test-lpa-data

- name: Run Unit Tests
run: docker compose up unit-test-lpa-data --abort-on-container-exit --exit-code-from unit-test-lpa-data || exit 1
Loading
Loading