Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
61b9cfc
Chore/update to latest ths (#8)
chrisbc Jul 22, 2025
f0b0cb7
update library import; changelog entry;
chrisbc Aug 24, 2025
0d44ed8
Merge pull request #12 from GNS-Science/chore/11_graphql_server_api_u…
chrisbc Aug 24, 2025
e5efe74
revert api change; pin flask-graphql; update changelog;
chrisbc Aug 27, 2025
4518676
Merge pull request #13 from GNS-Science/chore/11_revert_graphql_server
chrisbc Aug 28, 2025
9c6199c
[14] upgrade to 3.12 (#16)
voj Sep 5, 2025
037fd1a
migrate from npm to yarn2
chrisbc Sep 22, 2025
98f940b
use yarn2 packagemgr for deployments;
chrisbc Sep 22, 2025
5d509d8
package updates; commit yarn lock file;
chrisbc Sep 22, 2025
b5bf58a
update docs;
chrisbc Sep 22, 2025
a17a160
remove script entry;
chrisbc Sep 22, 2025
307ada5
remove script entry;
chrisbc Sep 22, 2025
2d45229
python security updates;
chrisbc Sep 22, 2025
e35c694
python security updates;
chrisbc Sep 22, 2025
c5f3f2c
new black version whitespace updates;
chrisbc Sep 22, 2025
d6a0768
Bump version: 0.2.2 → 0.2.3
chrisbc Sep 22, 2025
c7ced85
add version date; ``` makes commands easier to copy;
chrisbc Sep 22, 2025
33e9311
Merge pull request #18 from GNS-Science/chore/17_yarn2_and_node_lock_…
chrisbc Sep 22, 2025
e30f11c
update serverless pacakge; python version 3.12;
chrisbc Oct 19, 2025
c6e28c2
update .gitignore; upgrade pypropject.toml PEP508; Tweak docstring ru…
chrisbc Oct 19, 2025
70e18fb
update poetry.lock; test tweaks;
chrisbc Oct 19, 2025
d09ddfa
add dev group to dev.yml
chrisbc Oct 19, 2025
9f1ffb0
whitespace;
chrisbc Oct 19, 2025
21c1e8a
Bump version: 0.2.3 → 0.3.0
chrisbc Oct 19, 2025
67d4195
add the release workflow; update poetry version;
chrisbc Oct 20, 2025
92321af
update lock file;
chrisbc Oct 20, 2025
956717e
Add organization and app configuration to serverless.yml
chrisbc Oct 20, 2025
f2f1de2
Merge pull request #21 from GNS-Science/chore/20-serverless-V4-migration
chrisbc Oct 20, 2025
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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.1
current_version = 0.3.0
commit = True
tag = False

Expand Down
89 changes: 13 additions & 76 deletions .github/workflows/deploy-to-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,79 +10,16 @@ on:
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

- 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

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

call-deploy-workflow:
needs: call-test-workflow
uses: GNS-Science/nshm-github-actions/.github/workflows/deploy-to-aws.yml@main
with:
python-version: '3.12'
node-version: '22'
docker: true
node-pkg-manager: 'yarn2'
secrets: inherit
5 changes: 4 additions & 1 deletion .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

workflow_call:

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.10', '3.11']"
python-versions: "['3.12']"
delete-poetry-lock: ${{ github.event_name == 'schedule' }} # the scheduled build tests against newer dependencies
optional-dependency-groups: dev
secrets: inherit
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Publish package on main branch if it's tagged with 'v*'

name: Release & publish workflow

# Controls when the action will run.
on:
# Triggers the workflow on push events but only for the master branch
push:
tags: 'v*'

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

jobs:

release-and-distribute:
uses: GNS-Science/nshm-github-actions/.github/workflows/python-release.yml@main
with:
python-version: '3.12'
pypi-publish: false
secrets: inherit

# deploy-docs:
# uses: GNS-Science/nshm-github-actions/.github/workflows/python-deploy-docs.yml@main
# with:
# python-version: '3.12'
# optional-dependency-groups: 'doc'
# secrets: inherit
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ wheels/
*.egg-info/
.installed.cfg
*.egg
requirements.txt
audit.txt

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Changelog

## [0.3.0] - 2025-10-20

### Changed
- migrate to serverless 4
- set serverless to python 3.12
- migrate pyproject.toml to PEP508
- ensureCI/CD workflows use minimum install footprints

### Added
- tox audit step

## Removed
- doc dependency group

## [0.2.3] - 2025-09-23

### Changed
- pinned import on graphql_server library to 3.0.0b7 until upstream release is fixed.
- upgraded to Python 3.12
- move to yarn2 for node package management
- update python packages with security warnings

## [0.2.2] - 2025-07-23

### Changed
- update to THS 1.2.1
- migrate to THS hazard queries

## [0.2.1] - 2025-07-17

### Added
Expand Down
26 changes: 14 additions & 12 deletions Containerise-00.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,35 @@ Login Succeeded

## Get a base image

Using the AWS official python lambda image: `public.ecr.aws/lambda/python:3.11`
Using the AWS official python lambda image: `public.ecr.aws/lambda/python:3.12`

```
docker pull public.ecr.aws/lambda/python:3.11
docker pull public.ecr.aws/lambda/python:3.12
3.12: Pulling from lambda/python
.....
Status: Downloaded newer image for public.ecr.aws/lambda/python:3.11
public.ecr.aws/lambda/python:3.11
Status: Downloaded newer image for public.ecr.aws/lambda/python:3.12
public.ecr.aws/lambda/python:3.12
```

### get the requirements
poetry export --without-hashes --format=requirements.txt > requirements.txt

### test wsgi handlers

`poetry run npx serverless wsgi serve`
```
ENABLE_METRICS=0 poetry run yarn sls wsgi serve
```

## A Dockerfile

see [Dockerfile](./Dockerfile)

### build it
```
BUILDX_NO_DEFAULT_ATTESTATIONS=1 yarn sls package
```

`BUILDX_NO_DEFAULT_ATTESTATIONS=1 npx serverless package`

### and/or deploy it

this will push the image

`BUILDX_NO_DEFAULT_ATTESTATIONS=1 npx serverless deploy --stage dev --region us-east-1`
### and/or just deploy it
```
BUILDX_NO_DEFAULT_ATTESTATIONS=1 yarn sls deploy --stage dev --region ap-southeast-2
```
39 changes: 22 additions & 17 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# DEVELOPMENT

This application uses serverless.com.

This application uses serverless.com.

### Environment setup

- clone the repo
- check/install a recent node version >=17.8
- check/install a recent npm version >=8.11
- install serverless `npm install --save serverless` [more info]()
- install `npm install --save serverless-python-requirements` [more info](https://www.serverless.com/blog/serverless-python-packaging/)
- install `npm install -save serverless-wsgi` [more info](https://www.serverless.com/plugins/serverless-wsgi)
- `serverless plugin install -n serverless-python-requirements`
- `serverless plugin install -n serverless-wsgi`
- check/install a recent node version >=22
`nvm use 22`

- setup python env
```
pyenv local 3.12
poetry env use 3.12
```

setup yarn 2 ...
```
corepack enable
yarn set version berry
yarn install
```

Now `sls info` should print something like ...
Now `yarn sls info` should print something like ...

```
chrisbc@tryharder-ubuntu:/GNSDATA/API/kororaa-graphql-api$ sls info
Expand All @@ -28,19 +34,18 @@ Bugs: github.com/serverless/serverless/issue

```

You'll problably see an error, if youtr AWS credentials are not thise required for SLS.

You'll problably see an error, if your AWS credentials are not thise required for SLS.

### AWS credentials

## TESTING

### Run API locally
`$> ENABLE_METRICS=0 AWS_PROFILE=toshi_batch_devops sls wsgi serve --region ap-southeast-2 --stage PROD`


### API Feature tests
`$>poetry run pytest`
`poetry run pytest`

### Run API locally
`ENABLE_METRICS=0 poetry run yarn sls wsgi serve`
poetry run yarn serverless wsgi serve



Expand Down
16 changes: 9 additions & 7 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.12

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

RUN dnf install git-core -y &&\
pip install --upgrade pip &&\
pip3 install -r requirements.txt &&\
pip cache purge &&\
dnf remove git-core -y &&\
dnf clean all

# lambda entry point
CMD ["nshm_hazard_graphql_api.nshm_hazard_graphql_api.app"]
Expand Down
2 changes: 1 addition & 1 deletion nshm_hazard_graphql_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = """GNS Science New Zealand"""
__email__ = 'nshm@gns.cri.nz'
__version__ = '0.2.1'
__version__ = '0.3.0'
4 changes: 1 addition & 3 deletions nshm_hazard_graphql_api/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This module exports comfiguration for the current system
"""

import os

from dotenv import load_dotenv
Expand All @@ -21,6 +22,3 @@ def boolean_env(environ_name, default='FALSE'):
LOGGING_CFG = os.getenv('LOGGING_CFG', 'nshm_hazard_graphql_api/logging_aws.yaml')
ENABLE_METRICS = bool(os.getenv('ENABLE_METRICS', '').upper() in ["1", "Y", "YES", "TRUE"])
CW_METRICS_RESOLUTION = os.getenv('CW_METRICS_RESOLUTION', 60) # 1 for high resolution or 60

DATASET_AGGR_ENABLED = bool(os.getenv('DATASET_AGGR_ENABLED', '').upper() in ["1", "Y", "YES", "TRUE"])
DATASET_AGGR_URI = os.getenv('DATASET_AGGR_URI', '')
Loading
Loading