Skip to content

Commit

Permalink
refactor to ease usage and packaging (#32)
Browse files Browse the repository at this point in the history
* refactor to ease usage and packaging

* Update .gitignore

* add open=True to avoid deprecation

* add compression middleware

* switch to orjson

* Use poetry for dependency management given lambda deployment

* Update CI for poetry dependency management

* Add pre-commit to poetry test dependencies

* Run pip through python

---------

Co-authored-by: Zachary Deziel <zachary.deziel@gmail.com>
  • Loading branch information
vincentsarago and zacdezgeo authored Aug 30, 2024
1 parent 49b7f2a commit 4b51bb4
Show file tree
Hide file tree
Showing 31 changed files with 2,499 additions and 288 deletions.
38 changes: 21 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,38 @@ jobs:
test:
runs-on: ubuntu-latest

env:
DB_HOST: localhost
DB_PORT: 5432
DB_NAME: mydatabase
DB_USER: myuser
DB_PASSWORD: mypassword
DB_TABLE_NAME: space2stats

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install dependencies
- name: Install Poetry
run: |
python -m pip install --upgrade pip
pip install -r space2stats_api/src/requirements.txt
pip install pre-commit pytest
python -m pip install poetry
- name: Set PYTHONPATH
run: echo "PYTHONPATH=$(pwd)/space2stats_api" >> $GITHUB_ENV
- name: Install dependencies
working-directory: ./space2stats_api/src
run: |
poetry install --with test
- name: Run pre-commit
run: pre-commit run --all-files
working-directory: ./space2stats_api/src
run: |
poetry run pre-commit run --all-files
- name: Run tests
run: pytest space2stats_api/tests
working-directory: ./space2stats_api/src
run: |
poetry run pytest -s -vv
env:
DB_HOST: localhost
DB_PORT: 5432
DB_NAME: mydatabase
DB_USER: myuser
DB_PASSWORD: mypassword
DB_TABLE_NAME: space2stats
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ db.env
space2stats_api/space2stats_env
*.env
cdk.out
lambda_layer
lambda_layer
11 changes: 6 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ version: '3'

services:
database:
image: ghcr.io/stac-utils/pgstac:v0.8.5
# at time of writing this, ARM64 is not supported so we make sure to use
# a supported platform: https://github.com/postgis/docker-postgis/issues/216
# Could possibly switch to https://github.com/vincentsarago/containers
platform: linux/amd64
image: postgis/postgis:15-3.4
environment:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=postgis
- PGUSER=username
- PGPASSWORD=password
- PGDATABASE=postgis
ports:
- "${MY_DOCKER_IP:-127.0.0.1}:5439:5432"
command: postgres -N 500
volumes:
- ./.pgdata:/var/lib/postgresql/data
- ./.pgdata:/var/lib/postgresql/data
2 changes: 1 addition & 1 deletion space2stats_api/cdk/aws_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
self, "Space2StatsFunction",
entry="../src",
runtime=_lambda.Runtime.PYTHON_3_11,
index="app/main.py",
index="space2stats/handler.py",
timeout=Duration.seconds(120),
handler="handler",
environment=app_settings.model_dump(),
Expand Down
6 changes: 0 additions & 6 deletions space2stats_api/local_db.env

This file was deleted.

2 changes: 0 additions & 2 deletions space2stats_api/pytest.ini

This file was deleted.

541 changes: 541 additions & 0 deletions space2stats_api/src/LICENSE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions space2stats_api/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## space2stats
Empty file.
23 changes: 0 additions & 23 deletions space2stats_api/src/app/main.py

This file was deleted.

Empty file.
59 changes: 0 additions & 59 deletions space2stats_api/src/app/routers/api.py

This file was deleted.

16 changes: 0 additions & 16 deletions space2stats_api/src/app/settings.py

This file was deleted.

Empty file.
60 changes: 0 additions & 60 deletions space2stats_api/src/app/utils/db_utils.py

This file was deleted.

Loading

0 comments on commit 4b51bb4

Please sign in to comment.