Skip to content

Commit 6df2a51

Browse files
KEH-921 - Post-Migration Cleanup (#57)
* Remove dashboard Terraform * Remove dashboard related files * Update Poetry and remove Streamlit * Remove pandas, matplotlib, plotly * Update and move CODEOWNERS to .github * Copy lambda README to root * Remove dashboard Dockerfile * Update README prerequisites and add makefile and table of contents sections * Remove dashboard dockerignore * Rename lambda folder to src * Add Makefile commands for applying linting * Run linters * Improve README formatting * Refactor lambda - Fix var typo - Capitalise constants - CoPilot -> Copilot - Add missing docstring - Remove unused var * Move terraform * Refactor lambda - Add module docstring - Use isinstance check - Use lazy formatting for logging - Remove unnecessary else and function parameter * Create LICENSE * Fail CI if linting fails * Potential fix for code scanning alert no. 5: Clear-text logging of sensitive information Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Remove old info from docs * Refactor lambda - Use Optional typing - Get Pylint to ignore handler parameters - Extract repeated logic for updating S3 - Extract logic for converting data to dictionary * Reduce linter max line length to 100 to fix Pylint conflict * Replace try except blocks with response type checks * Split handler into separate functions: reached 10/10 on pylint * Add tests folder * Update Makefile - Clean more temp files - Run linters on tests folder - Add new command for running tests * Update README - Add table of contents - Add testing and linting info * feat: update and setup for testing + coverage. - Added pytest-cov and pytest-xdist for enhanced testing capabilities. - Updated Makefile to include new test commands. - Modified .gitignore to exclude coverage reports. - Update README.md table of contents. * chore: update makefile commands - Remove tests directory from linting and formatting commands in Makefile. - Add .coverage to clean command in Makefile. * test: Write some tests for main.py - Test get_team_history - Test get_and_update_copilot_teams - Test update_s3_object - Add VS Code settings to gitignore * chore: remove old commented out tests * Add missing tests to reach 100% coverage * Add tests to ci.yml * Fix failing tests * Install dependencies via Poetry from requirements txt files and update all dependencies * Group Poetry docs dependencies * Use Poetry for mkdocs - Delete requirements txt file - Update deployment workflow - Update setup documentation * Fix Docker run command formatting * Delete requirements.txt * refactor: Update Dockerfile to use Poetry - Moved Dockerfile to root directory for better visibility. - Update Dockerfile to use Poetry for dependency management instead of pip. - Update .dockerignore to exclude unnecessary files from build context. - Update README.md to reflect move of Dockerfile to root directory. * Add option to run lambda outside of a container - Update README with setup instructions - Add commented function call to main.py * Address comments - Specify where to find CI workflow - Update sentence saying linting auto runs on tests - Fix README env vars - Use poetry install --only docs for mkdocs deployment - Add missing docstrings and return types - Return boolean for update_s3_object - Add comment above dev code * Run linting * Update README and .dockerignore - Remove disclaimer from README and update overview section with dashboard repository link - Add .github/ to .dockerignore * Remove and replace sandbox references - Remove and replace sandbox from .sh files, README, example_tfvars, variables.tf - Delete sandbox Terraform and move its example_tfvars to dev folder * Add backticks to README * Address comments - Use lambda full name - Update documentation bash - Move handler function to bottom of script * Address comments - Move logger to end of handler function - Remove Digital Landscape links - Specify Docker endpoint should return message if successful * Add missing type hints and return types * Tidy lambda scripts info in README * Fix function return type --------- Co-authored-by: Kieran Pritchard <kieran.pritchard@ons.gov.uk>
1 parent 64d841f commit 6df2a51

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1749
-16523
lines changed

.dockerignore

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
.github/*
2-
docs/*
3-
lambda_data_logger/*
4-
mkdocs_deployment/*
5-
terraform/*
6-
.gitignore
7-
CODEOWNERS
8-
Makefile
9-
mkdocs_requirements.txt
10-
mkdocs.yml
11-
README.md
12-
venv/*
1+
# Virtual Environment
2+
venv/
3+
4+
# __pycache__
5+
__pycache__/
6+
7+
.github/
8+
concourse/
9+
docs/
10+
terraform/
11+
tests/

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@ONS-Innovation/keh-dev

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ jobs:
3838
- name: Install dependencies
3939
run: make install-dev
4040

41-
- name: Lint Python
41+
- name: Lint Python (check only)
4242
run: make lint
43+
44+
- name: Run tests
45+
run: make test
4346

4447
- name: Cleanup residue file
4548
run: make clean

.github/workflows/deploy_mkdocs.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,5 @@ jobs:
2727
path: .cache
2828
restore-keys: |
2929
mkdocs-material-
30-
- run: pip install mkdocs-material
31-
- run: pip install -r mkdocs_requirements.txt
30+
- run: poetry install --only docs
3231
- run: mkdocs gh-deploy --force

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,11 @@ terraform/dashboard/highest_alb_listener_priority.txt
5959

6060
.env
6161

62+
# Ignore the .DS_Store file created by macOS
63+
.DS_Store
64+
65+
# Pytest Coverage Reports
66+
.coverage
67+
68+
# VS Code settings
69+
.vscode/

.streamlit/config.toml

Lines changed: 0 additions & 6 deletions
This file was deleted.

CODEOWNERS

Lines changed: 0 additions & 3 deletions
This file was deleted.

Dockerfile

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# Get a base image with a slim version of Python 3.10
2-
FROM python:3.12-slim
1+
FROM public.ecr.aws/lambda/python:3.12
32

4-
# run a pip install for poetry 1.5.0
5-
RUN pip install poetry==1.5.0
3+
# Install git using dnf (https://docs.aws.amazon.com/lambda/latest/dg/python-image.html#python-image-base)
4+
# For python 3.12, dnf replaces yum for package management
5+
RUN dnf install git -y
66

7-
# Set the working directory
8-
WORKDIR /app
7+
# Copy required files into the container
8+
COPY pyproject.toml poetry.lock ./
99

10-
# Copy the current directory contents into the container at /app
11-
COPY . /app
10+
# Install Poetry
11+
RUN pip install poetry
1212

13-
# Run poetry install --without dev
14-
RUN poetry install --only main --no-root
13+
# Install dependencies using Poetry
14+
RUN poetry config virtualenvs.create false && \
15+
poetry install --only main --no-root
1516

16-
# Expose the port the app runs on
17-
EXPOSE 8501
17+
# Copy the source code into the container
18+
COPY src/ src/
1819

19-
# Run the dashboard
20-
# Note: ENTRYPOINT cannot be overriden by docker run command
21-
ENTRYPOINT ["poetry", "run", "streamlit", "run", "src/app.py", "--server.port=8501", "--server.address=0.0.0.0"]
20+
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
21+
CMD [ "src.main.handler" ]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 ONS Innovation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,40 @@ all: ## Show the available make targets.
99
clean: ## Clean the temporary files.
1010
rm -rf .mypy_cache
1111
rm -rf .ruff_cache
12+
rm -rf .pytest_cache
13+
rm -rf tests/__pycache__
14+
rm -rf .coverage
1215

13-
.PHONY: black
14-
black: ## Run black.
15-
poetry run black src --check || true
16+
.PHONY: black-check
17+
black-check: ## Run black for code formatting, without fixing.
18+
poetry run black src --check
1619

17-
.PHONY: ruff
18-
ruff: ## Run ruff without fixing.
19-
poetry run ruff check src || true
20+
.PHONY: black-apply
21+
black-apply: ## Run black and fix code formatting.
22+
poetry run black src
23+
24+
.PHONY: ruff-check
25+
ruff-check: ## Run ruff for linting and code formatting, without fixing.
26+
poetry run ruff check src
27+
28+
.PHONY: ruff-apply
29+
ruff-apply: ## Run ruff and fix linting and code formatting.
30+
poetry run ruff check --fix src
2031

2132
.PHONY: pylint
22-
pylint: ## Run pylint.
23-
poetry run pylint src || true
33+
pylint: ## Run pylint for code analysis.
34+
poetry run pylint src
2435

2536
.PHONY: lint
26-
lint: ## Run Python linter
27-
make black
28-
make ruff
37+
lint: ## Run Python linters without fixing.
38+
make black-check
39+
make ruff-check
40+
make pylint
41+
42+
.PHONY: lint-apply
43+
lint-apply: ## Run black and ruff with auto-fix, and Pylint.
44+
make black-apply
45+
make ruff-apply
2946
make pylint
3047

3148
.PHONY: mypy
@@ -40,8 +57,7 @@ install: ## Install the dependencies excluding dev.
4057
install-dev: ## Install the dependencies including dev.
4158
poetry install --no-root
4259

43-
.PHONY: run-local
44-
run-local: ## Install the dependencies including dev.
45-
poetry run streamlit run src/app.py --server.port 8502
46-
60+
.PHONY: test
61+
test: ## Run the lambda tests.
62+
poetry run pytest -n auto --cov=src --cov-report term-missing --cov-fail-under=95
4763

0 commit comments

Comments
 (0)