Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
90 changes: 13 additions & 77 deletions .github/workflows/deploy-to-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,82 +7,18 @@ on:
- main

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
# call-test-workflow:
# uses: GNS-Science/nshm-github-actions/.github/workflows/python-run-tests.yml@main
# with:
# operating-systems: "['ubuntu-latest']"
# python-versions: "['3.11']"
# secrets: inherit

deploy:
# needs: call-test-workflow
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [22]
python-version: [3.11]

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install and configure Poetry
uses: GNS-Science/install-poetry@main
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Ensure latest requiremments.txt
run: |
poetry self add poetry-plugin-export
poetry export --without-hashes --format=requirements.txt > requirements.txt

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
check-latest: true

- name: upgrade NPM
run: npm install --location=global npm@latest
workflow_dispatch:

- name: Verify NPM
run: npm doctor

- name: Install Dependencies
run: npm install

- name: List packages
run: npm ls

- name: Serverless Doctor
run: npm run-script sls_doctor

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-southeast-2

- name: Login to ECR
uses: docker/login-action@v3
with:
registry: 461564345538.dkr.ecr.ap-southeast-2.amazonaws.com

- name: Serverless Deploy ....
env:
ENABLE_METRICS: 1
run: |
if [[ "${{github.base_ref}}" == "main" || "${{github.ref}}" == 'refs/heads/main' ]]; then
STAGE=prod REGION=ap-southeast-2 npm run-script deploy
else
STAGE=test REGION=ap-southeast-2 npm run-script deploy
fi
jobs:

call-test-workflow:
uses: ./.github/workflows/dev.yml
secrets: inherit

call-deploy-workflow:
uses: GNS-Science/nshm-github-actions/.github/workflows/deploy-to-aws.yml@main
with:
python-version: '3.13'
node-version: '22'
docker: true
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
uses: GNS-Science/nshm-github-actions/.github/workflows/python-run-tests.yml@main
with:
operating-systems: "['ubuntu-latest']"
python-versions: "['3.10', '3.11']"
python-versions: "['3.13']"
delete-poetry-lock: ${{ github.event_name == 'schedule' }} # the scheduled build tests against newer dependencies
secrets: inherit
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Changed
- pinned import on graphql_server library to 3.0.0b7 until upstream release is fixed.
- update to python 3.13 ECR image base to resolve pyproj build issues (and get better doc support)
- updated upstream toshi-hazard-store

## [0.2.2] - 2025-07-23

Expand Down
18 changes: 10 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#Dockerfile
FROM public.ecr.aws/lambda/python:3.11
FROM public.ecr.aws/lambda/python:3.13

ARG FUNCTION_ROOT_DIR="/var/task"

# GIT
RUN yum install git-core -y

# Create function directory
RUN mkdir -p ${FUNCTION_ROOT_DIR}/nshm_hazard_graphql_api

# The lamba service functions
COPY ./nshm_hazard_graphql_api/ ${FUNCTION_ROOT_DIR}/nshm_hazard_graphql_api
COPY requirements.txt ${FUNCTION_DIR}

COPY requirements.txt ${FUNCTION_ROOT_DIR}
WORKDIR ${FUNCTION_ROOT_DIR}
RUN pip install --upgrade pip
RUN pip3 install -r requirements.txt
# add gcc because some packages might need to be built (contourpy)
# add git to be able to install NZSHM libraries from git
RUN dnf install git-core gcc gcc-c++ -y &&\
pip install --upgrade pip &&\
pip3 install --no-deps -r requirements.txt &&\
pip cache purge &&\
dnf remove gcc-c++ git-core -y &&\
dnf clean all

# lambda entry point
CMD ["nshm_hazard_graphql_api.nshm_hazard_graphql_api.app"]
Expand Down
1,270 changes: 551 additions & 719 deletions poetry.lock

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ packages = [
]

[tool.poetry.dependencies]
python = ">=3.10,<3.13"
python = ">=3.13,<3.14"
flask = "^3.0.3"
flask-cors = "^4.0.1"
pyyaml = "^6.0.1"
Expand All @@ -31,25 +31,24 @@ graphene = "^3.3"

boto3 = "^1.24.57"
python-dateutil = "^2.8.2"
nzshm-model = "^0.13.6"
nzshm-common = "^0.8.4"
matplotlib = "^3.10.3"
pyproj = "^3.7.1"
geopandas = "^1.0.1"
werkzeug = "^3.1.3"
poetry-plugin-export = "^1.9.0"
serverless-wsgi = "^3.0.5"
python-dotenv = "^1.1.0"
toshi-hazard-store = "^1.2.1"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably worth doing the release cycle to get rid of git ref before merging

toshi-hazard-store = {git = "https://github.com/GNS-Science/toshi-hazard-store.git", rev = "1e7729542ecfd34c95a34902b58c9adfd910212a"}

[tool.poetry.group.dev.dependencies]
tox = "^4.2.8"
black = { version = "^22.3"}
black = { version = "^25.1.0"}
isort = { version = "^5.8.0"}
flake8 = { version = "^3.9.2"}
flake8-docstrings = { version = "^1.6.0", optional = true }
flake8 = { version = "^7.3.0"}
flake8-docstrings = { version = "^1.7.0", optional = true }
virtualenv = { version = "^20.2.2", optional = true}
pip = { version = "^20.3.1", optional = true}
poetry-plugin-export = "^1.9.0"

mkdocs = { version = "^1.1.2"}
mkdocs-include-markdown-plugin = { version = "^1.0.0"}
Expand All @@ -62,7 +61,7 @@ pymdown-extensions = {version = "^9.4"}
mkdocstrings-python = {version = "^0.6.5"}
mkdocs-pymdownx-material-extras = "^2.0.3"

twine = { version = "^3.3.0"}
twine = { version = "^6.1.0"}

pre-commit = {version = "^2.12.0", optional = true}
toml = {version = "^0.10.2", optional = true}
Expand Down Expand Up @@ -103,7 +102,7 @@ doc = [
[tool.black]
line-length = 120
skip-string-normalization = true
target-version = ['py37', 'py38', 'py39']
target-version = ['py313']
include = '\.pyi?$'
exclude = '''
/(
Expand Down
Binary file modified requirements.txt
Binary file not shown.
5 changes: 2 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ exclude_lines =

[tox:tox]
isolated_build = true
envlist = py311, py310, format, lint, build
envlist = py313, format, lint, build

[gh-actions]
python =
3.10: py310
3.11: py311, format, lint, build
3.13: py313, format, lint, build

[testenv]
allowlist_externals = pytest
Expand Down
20 changes: 12 additions & 8 deletions tests/test_hazard_resolve_franz_josef.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ def test_get_by_shortcode(self, mock_query_response, monkeypatch, graphql_client

assert res['ok'] is True
assert mocked_qry.call_count == 1
assert mocked_qry.called_with(
mocked_qry.assert_called_with(
["-43.376~170.188"], # the resolved codes for the respective cities by ID
[400],
[HAZARD_MODEL_ID],
HAZARD_MODEL_ID,
['PGA'],
aggs=["mean"],
strategy='d2'
)

# TODO this will be deprecated
Expand Down Expand Up @@ -125,12 +126,13 @@ def test_get_wlg_by_shortcode_with_lowres(self, mock_query_response, monkeypatch

assert res['ok'] is True
assert mocked_qry.call_count == 1
assert mocked_qry.called_with(
mocked_qry.assert_called_with(
["-43.376~170.188"], # the resolved codes for the respective cities by ID
[400],
[HAZARD_MODEL_ID],
HAZARD_MODEL_ID,
['PGA'],
aggs=["mean"],
strategy='d2'
)

def test_get_franz_josef_by_latlon(self, mock_query_response, monkeypatch, graphql_client):
Expand Down Expand Up @@ -169,12 +171,13 @@ def test_get_franz_josef_by_latlon(self, mock_query_response, monkeypatch, graph

assert res['ok'] is True
assert mocked_qry.call_count == 1
assert mocked_qry.called_with(
mocked_qry.assert_called_with(
["-43.376~170.188"], # the resolved codes for the respective cities by ID
[400],
[HAZARD_MODEL_ID],
HAZARD_MODEL_ID,
['PGA'],
aggs=["mean"],
strategy='d2'
)

def test_get_franz_josef_by_latlon_default_resolution(self, mock_query_response, monkeypatch, graphql_client):
Expand Down Expand Up @@ -212,12 +215,13 @@ def test_get_franz_josef_by_latlon_default_resolution(self, mock_query_response,

assert res['ok'] is True
assert mocked_qry.call_count == 1
assert mocked_qry.called_with(
mocked_qry.assert_called_with(
["-43.376~170.188"], # the resolved codes for the respective cities by ID
[400],
[HAZARD_MODEL_ID],
HAZARD_MODEL_ID,
['PGA'],
aggs=["mean"],
strategy='d2'
)

def test_get_franz_josef_by_latlon_low_hazard_resolution(self, mock_query_response, monkeypatch, graphql_client):
Expand Down