Skip to content

Commit 96e3ba1

Browse files
authored
Merge pull request #24 from GNS-Science/merge_deploy_test_to_main
Merge deplo- test to main - latest THS Chore/update to latest ths #8 - ECR deployment [14] update ECR base image and upstream libs #15 - yarn lock file Chore/17 yarn2 and node lock file #18 - serverless V4 migration Chore/20 serverless v4 migration #21
2 parents d5ba102 + edea1ae commit 96e3ba1

29 files changed

Lines changed: 7753 additions & 3531 deletions

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.2.2
2+
current_version = 0.3.0
33
commit = True
44
tag = False
55

.github/workflows/deploy-to-aws.yaml

Lines changed: 13 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,79 +10,16 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13-
# call-test-workflow:
14-
# uses: GNS-Science/nshm-github-actions/.github/workflows/python-run-tests.yml@main
15-
# with:
16-
# operating-systems: "['ubuntu-latest']"
17-
# python-versions: "['3.11']"
18-
# secrets: inherit
19-
20-
deploy:
21-
# needs: call-test-workflow
22-
runs-on: ubuntu-latest
23-
strategy:
24-
matrix:
25-
node-version: [22]
26-
python-version: [3.11]
27-
28-
steps:
29-
- uses: actions/checkout@v4
30-
- uses: actions/setup-python@v5
31-
with:
32-
python-version: ${{ matrix.python-version }}
33-
34-
- name: Install and configure Poetry
35-
uses: GNS-Science/install-poetry@main
36-
with:
37-
virtualenvs-create: true
38-
virtualenvs-in-project: true
39-
installer-parallel: true
40-
41-
- name: Ensure latest requiremments.txt
42-
run: |
43-
poetry self add poetry-plugin-export
44-
poetry export --without-hashes --format=requirements.txt > requirements.txt
45-
46-
- name: Use Node.js ${{ matrix.node-version }}
47-
uses: actions/setup-node@v3
48-
with:
49-
node-version: ${{ matrix.node-version }}
50-
check-latest: true
51-
52-
- name: upgrade NPM
53-
run: npm install --location=global npm@latest
54-
55-
- name: Verify NPM
56-
run: npm doctor
57-
58-
- name: Install Dependencies
59-
run: npm install
60-
61-
- name: List packages
62-
run: npm ls
63-
64-
- name: Serverless Doctor
65-
run: npm run-script sls_doctor
66-
67-
- name: Configure AWS Credentials
68-
uses: aws-actions/configure-aws-credentials@v4
69-
with:
70-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
71-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
72-
aws-region: ap-southeast-2
73-
74-
- name: Login to ECR
75-
uses: docker/login-action@v3
76-
with:
77-
registry: 461564345538.dkr.ecr.ap-southeast-2.amazonaws.com
78-
79-
- name: Serverless Deploy ....
80-
env:
81-
ENABLE_METRICS: 1
82-
run: |
83-
if [[ "${{github.base_ref}}" == "main" || "${{github.ref}}" == 'refs/heads/main' ]]; then
84-
STAGE=prod REGION=ap-southeast-2 npm run-script deploy
85-
else
86-
STAGE=test REGION=ap-southeast-2 npm run-script deploy
87-
fi
88-
13+
call-test-workflow:
14+
uses: ./.github/workflows/dev.yml
15+
secrets: inherit
16+
17+
call-deploy-workflow:
18+
needs: call-test-workflow
19+
uses: GNS-Science/nshm-github-actions/.github/workflows/deploy-to-aws.yml@main
20+
with:
21+
python-version: '3.12'
22+
node-version: '22'
23+
docker: true
24+
node-pkg-manager: 'yarn2'
25+
secrets: inherit

.github/workflows/dev.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ on:
99
# Allows you to run this workflow manually from the Actions tab
1010
workflow_dispatch:
1111

12+
workflow_call:
13+
1214
jobs:
1315
call-test-workflow:
1416
uses: GNS-Science/nshm-github-actions/.github/workflows/python-run-tests.yml@main
1517
with:
1618
operating-systems: "['ubuntu-latest']"
17-
python-versions: "['3.10', '3.11']"
19+
python-versions: "['3.12']"
1820
delete-poetry-lock: ${{ github.event_name == 'schedule' }} # the scheduled build tests against newer dependencies
21+
optional-dependency-groups: dev
1922
secrets: inherit

.github/workflows/release.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Publish package on main branch if it's tagged with 'v*'
2+
3+
name: Release & publish workflow
4+
5+
# Controls when the action will run.
6+
on:
7+
# Triggers the workflow on push events but only for the master branch
8+
push:
9+
tags: 'v*'
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
jobs:
15+
16+
release-and-distribute:
17+
uses: GNS-Science/nshm-github-actions/.github/workflows/python-release.yml@main
18+
with:
19+
python-version: '3.12'
20+
pypi-publish: false
21+
secrets: inherit
22+
23+
# deploy-docs:
24+
# uses: GNS-Science/nshm-github-actions/.github/workflows/python-deploy-docs.yml@main
25+
# with:
26+
# python-version: '3.12'
27+
# optional-dependency-groups: 'doc'
28+
# secrets: inherit

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ wheels/
3636
*.egg-info/
3737
.installed.cfg
3838
*.egg
39+
requirements.txt
40+
audit.txt
3941

4042
# PyInstaller
4143
# Usually these files are written by a python script from a template

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# Changelog
22

3+
## [0.3.0] - 2025-10-20
4+
5+
### Changed
6+
- migrate to serverless 4
7+
- set serverless to python 3.12
8+
- migrate pyproject.toml to PEP508
9+
- ensureCI/CD workflows use minimum install footprints
10+
11+
### Added
12+
- tox audit step
13+
14+
## Removed
15+
- doc dependency group
16+
17+
## [0.2.3] - 2025-09-23
18+
19+
### Changed
20+
- pinned import on graphql_server library to 3.0.0b7 until upstream release is fixed.
21+
- upgraded to Python 3.12
22+
- move to yarn2 for node package management
23+
- update python packages with security warnings
24+
325
## [0.2.2] - 2025-07-23
426

527
### Changed

Containerise-00.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,35 @@ Login Succeeded
1313

1414
## Get a base image
1515

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

1818
```
19-
docker pull public.ecr.aws/lambda/python:3.11
19+
docker pull public.ecr.aws/lambda/python:3.12
2020
3.12: Pulling from lambda/python
2121
.....
22-
Status: Downloaded newer image for public.ecr.aws/lambda/python:3.11
23-
public.ecr.aws/lambda/python:3.11
22+
Status: Downloaded newer image for public.ecr.aws/lambda/python:3.12
23+
public.ecr.aws/lambda/python:3.12
2424
```
2525

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

2929
### test wsgi handlers
3030

31-
`poetry run npx serverless wsgi serve`
31+
```
32+
ENABLE_METRICS=0 poetry run yarn sls wsgi serve
33+
```
3234

3335
## A Dockerfile
3436

3537
see [Dockerfile](./Dockerfile)
3638

3739
### build it
40+
```
41+
BUILDX_NO_DEFAULT_ATTESTATIONS=1 yarn sls package
42+
```
3843

39-
`BUILDX_NO_DEFAULT_ATTESTATIONS=1 npx serverless package`
40-
41-
### and/or deploy it
42-
43-
this will push the image
44-
45-
`BUILDX_NO_DEFAULT_ATTESTATIONS=1 npx serverless deploy --stage dev --region us-east-1`
44+
### and/or just deploy it
45+
```
46+
BUILDX_NO_DEFAULT_ATTESTATIONS=1 yarn sls deploy --stage dev --region ap-southeast-2
47+
```

DEVELOPMENT.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
# DEVELOPMENT
22

3-
This application uses serverless.com.
4-
3+
This application uses serverless.com.
54

65
### Environment setup
76

87
- clone the repo
9-
- check/install a recent node version >=17.8
10-
- check/install a recent npm version >=8.11
11-
- install serverless `npm install --save serverless` [more info]()
12-
- install `npm install --save serverless-python-requirements` [more info](https://www.serverless.com/blog/serverless-python-packaging/)
13-
- install `npm install -save serverless-wsgi` [more info](https://www.serverless.com/plugins/serverless-wsgi)
14-
- `serverless plugin install -n serverless-python-requirements`
15-
- `serverless plugin install -n serverless-wsgi`
8+
- check/install a recent node version >=22
9+
`nvm use 22`
10+
11+
- setup python env
12+
```
13+
pyenv local 3.12
14+
poetry env use 3.12
15+
```
1616

17+
setup yarn 2 ...
18+
```
19+
corepack enable
20+
yarn set version berry
21+
yarn install
22+
```
1723

18-
Now `sls info` should print something like ...
24+
Now `yarn sls info` should print something like ...
1925

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

31-
You'll problably see an error, if youtr AWS credentials are not thise required for SLS.
32-
37+
You'll problably see an error, if your AWS credentials are not thise required for SLS.
3338

3439
### AWS credentials
3540

3641
## TESTING
3742

38-
### Run API locally
39-
`$> ENABLE_METRICS=0 AWS_PROFILE=toshi_batch_devops sls wsgi serve --region ap-southeast-2 --stage PROD`
40-
41-
4243
### API Feature tests
43-
`$>poetry run pytest`
44+
`poetry run pytest`
45+
46+
### Run API locally
47+
`ENABLE_METRICS=0 poetry run yarn sls wsgi serve`
48+
poetry run yarn serverless wsgi serve
4449

4550

4651

Dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
#Dockerfile
2-
FROM public.ecr.aws/lambda/python:3.11
2+
FROM public.ecr.aws/lambda/python:3.12
33

44
ARG FUNCTION_ROOT_DIR="/var/task"
55

6-
# GIT
7-
RUN yum install git-core -y
8-
96
# Create function directory
107
RUN mkdir -p ${FUNCTION_ROOT_DIR}/nshm_hazard_graphql_api
118

129
# The lamba service functions
1310
COPY ./nshm_hazard_graphql_api/ ${FUNCTION_ROOT_DIR}/nshm_hazard_graphql_api
14-
COPY requirements.txt ${FUNCTION_DIR}
11+
COPY requirements.txt ${FUNCTION_ROOT_DIR}
1512

1613
WORKDIR ${FUNCTION_ROOT_DIR}
17-
RUN pip install --upgrade pip
18-
RUN pip3 install -r requirements.txt
14+
15+
RUN dnf install git-core -y &&\
16+
pip install --upgrade pip &&\
17+
pip3 install -r requirements.txt &&\
18+
pip cache purge &&\
19+
dnf remove git-core -y &&\
20+
dnf clean all
1921

2022
# lambda entry point
2123
CMD ["nshm_hazard_graphql_api.nshm_hazard_graphql_api.app"]

nshm_hazard_graphql_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__author__ = """GNS Science New Zealand"""
44
__email__ = 'nshm@gns.cri.nz'
5-
__version__ = '0.2.2'
5+
__version__ = '0.3.0'

0 commit comments

Comments
 (0)