From 83679f9b1455a40a2e94bc29a27626431007a849 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Wed, 1 Mar 2023 14:07:29 -0800 Subject: [PATCH 1/6] deps: bump pgstac to v0.7.1 --- .github/workflows/cicd.yaml | 5 ++--- docker-compose.yml | 3 +-- docker/docker-compose.pgstac.yml | 3 +-- docker/docker-compose.sqlalchemy.yml | 3 +-- stac_fastapi/pgstac/setup.py | 4 ++-- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index 46aefd88e..0f8f19feb 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -15,7 +15,7 @@ jobs: services: db_service: - image: ghcr.io/stac-utils/pgstac:v0.6.13 + image: ghcr.io/stac-utils/pgstac:v0.7.1 env: POSTGRES_USER: username POSTGRES_PASSWORD: password @@ -130,7 +130,7 @@ jobs: backend: ["sqlalchemy", "pgstac"] services: pgstac: - image: ghcr.io/stac-utils/pgstac:v0.6.13 + image: ghcr.io/stac-utils/pgstac:v0.7.1 env: POSTGRES_USER: username POSTGRES_PASSWORD: password @@ -176,7 +176,6 @@ jobs: POSTGRES_PORT: 5432 PGUSER: username PGPASSWORD: password - PGHOST: localhost PGDATABASE: postgis APP_HOST: 0.0.0.0 APP_PORT: 8080 diff --git a/docker-compose.yml b/docker-compose.yml index 506a4a37b..5637f7e0c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -61,14 +61,13 @@ services: database: container_name: stac-db - image: ghcr.io/stac-utils/pgstac:v0.6.12 + image: ghcr.io/stac-utils/pgstac:v0.7.1 environment: - POSTGRES_USER=username - POSTGRES_PASSWORD=password - POSTGRES_DB=postgis - PGUSER=username - PGPASSWORD=password - - PGHOST=localhost - PGDATABASE=postgis ports: - "5439:5432" diff --git a/docker/docker-compose.pgstac.yml b/docker/docker-compose.pgstac.yml index 63514aab4..b95cba0bd 100644 --- a/docker/docker-compose.pgstac.yml +++ b/docker/docker-compose.pgstac.yml @@ -25,14 +25,13 @@ services: - pgstac pgstac: - image: ghcr.io/stac-utils/pgstac:v0.6.13 + image: ghcr.io/stac-utils/pgstac:v0.7.1 environment: - POSTGRES_USER=username - POSTGRES_PASSWORD=password - POSTGRES_DB=postgis - PGUSER=username - PGPASSWORD=password - - PGHOST=localhost - PGDATABASE=postgis ports: - "5439:5432" diff --git a/docker/docker-compose.sqlalchemy.yml b/docker/docker-compose.sqlalchemy.yml index 70d216305..f69516e4a 100644 --- a/docker/docker-compose.sqlalchemy.yml +++ b/docker/docker-compose.sqlalchemy.yml @@ -19,14 +19,13 @@ services: - pgstac pgstac: - image: ghcr.io/stac-utils/pgstac:v0.6.13 + image: ghcr.io/stac-utils/pgstac:v0.7.1 environment: - POSTGRES_USER=username - POSTGRES_PASSWORD=password - POSTGRES_DB=postgis - PGUSER=username - PGPASSWORD=password - - PGHOST=localhost - PGDATABASE=postgis ports: - "5439:5432" diff --git a/stac_fastapi/pgstac/setup.py b/stac_fastapi/pgstac/setup.py index 8664524d0..6632ff0c4 100644 --- a/stac_fastapi/pgstac/setup.py +++ b/stac_fastapi/pgstac/setup.py @@ -17,12 +17,12 @@ "buildpg", "brotli_asgi", "pygeofilter>=0.2", - "pypgstac==0.6.*", + "pypgstac==0.7.*", ] extra_reqs = { "dev": [ - "pypgstac[psycopg]==0.6.*", + "pypgstac[psycopg]==0.7.*", "pytest", "pytest-cov", "pytest-asyncio>=0.17", From d26c5efeeaa326232b9edfe92fdd07c2b0787f34 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Wed, 1 Mar 2023 14:10:02 -0800 Subject: [PATCH 2/6] ci: only build packages on main or tags --- .github/workflows/cicd.yaml | 38 ---------------------------- .github/workflows/packages.yml | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/packages.yml diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index 0f8f19feb..4d553d69c 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -186,41 +186,3 @@ jobs: - uses: actions/checkout@v3 - name: Test generating docs run: make docs - - docker-build-push: - runs-on: ubuntu-latest - needs: [test, validate, test-docs] - permissions: - contents: read - packages: write - strategy: - fail-fast: true - matrix: - backend: ["sqlalchemy", "pgstac"] - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Log in to the Container registry - uses: docker/login-action@v2.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4.3.0 - with: - images: ghcr.io/stac-utils/stac-fastapi - tags: | - type=schedule,suffix=-${{ matrix.backend }} - type=ref,event=branch,suffix=-${{ matrix.backend }} - type=ref,event=tag,suffix=-${{ matrix.backend }} - type=ref,event=pr,suffix=-${{ matrix.backend }} - - name: Build and push Docker image - uses: docker/build-push-action@v4.0.0 - with: - context: . - file: docker/Dockerfile.${{ matrix.backend }} - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml new file mode 100644 index 000000000..1988af0b2 --- /dev/null +++ b/.github/workflows/packages.yml @@ -0,0 +1,46 @@ +name: packages +on: + push: + branches: + - master + tags: + - "*" + +jobs: + docker-build-push: + runs-on: ubuntu-latest + needs: [test, validate, test-docs] + permissions: + contents: read + packages: write + strategy: + fail-fast: true + matrix: + backend: ["sqlalchemy", "pgstac"] + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Log in to the Container registry + uses: docker/login-action@v2.1.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4.3.0 + with: + images: ghcr.io/stac-utils/stac-fastapi + tags: | + type=schedule,suffix=-${{ matrix.backend }} + type=ref,event=branch,suffix=-${{ matrix.backend }} + type=ref,event=tag,suffix=-${{ matrix.backend }} + type=ref,event=pr,suffix=-${{ matrix.backend }} + - name: Build and push Docker image + uses: docker/build-push-action@v4.0.0 + with: + context: . + file: docker/Dockerfile.${{ matrix.backend }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From c83f040c036560c1147db9d284b0426cb3c9ec8c Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Wed, 1 Mar 2023 15:12:49 -0800 Subject: [PATCH 3/6] ci: don't log on services --- .github/workflows/cicd.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index 4d553d69c..97b540112 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -32,6 +32,7 @@ jobs: --health-interval 10s --health-timeout 10s --health-retries 10 + --log-driver none ports: # Maps tcp port 5432 on service container to the host - 5432:5432 @@ -143,6 +144,7 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + --log-driver none ports: - 5432:5432 steps: From 3e927de728004deae40cfcda21d85eaf738313a1 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Wed, 1 Mar 2023 16:45:09 -0800 Subject: [PATCH 4/6] ci: up timeout minutes --- .github/workflows/cicd.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index 97b540112..9bad92ba9 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -11,7 +11,7 @@ jobs: strategy: matrix: python-version: ["3.8", "3.9", "3.10", "3.11"] - timeout-minutes: 10 + timeout-minutes: 20 services: db_service: From b6405cee67ec02a191f19b0c3444793c5962ab91 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Wed, 1 Mar 2023 14:12:40 -0800 Subject: [PATCH 5/6] chore: update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 64802cc38..174768d97 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ * Updated CI to test against [pgstac v0.6.12](https://github.com/stac-utils/pgstac/releases/tag/v0.6.12) ([#511](https://github.com/stac-utils/stac-fastapi/pull/511)) * Reworked `update_openapi` and added a test for it ([#523](https://github.com/stac-utils/stac-fastapi/pull/523)) * Limit values above 10,000 are now replaced with 10,000 instead of returning a 400 error ([#526](https://github.com/stac-utils/stac-fastapi/pull/526)) +* Updated pgstac to v0.7.1 ([#535](https://github.com/stac-utils/stac-fastapi/pull/535)) ### Removed From 40bbcda24fb00ad05cdb925192f5fbf02701371b Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Fri, 27 Jan 2023 07:46:12 -0700 Subject: [PATCH 6/6] test: add sorting test Confirming that https://github.com/stac-utils/stac-fastapi/issues/514 is fixed with pgstac v0.7.0. --- stac_fastapi/pgstac/tests/api/test_api.py | 45 +++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/stac_fastapi/pgstac/tests/api/test_api.py b/stac_fastapi/pgstac/tests/api/test_api.py index e3baf32c1..ae766eb92 100644 --- a/stac_fastapi/pgstac/tests/api/test_api.py +++ b/stac_fastapi/pgstac/tests/api/test_api.py @@ -1,4 +1,5 @@ from datetime import datetime, timedelta +from typing import Any, Dict, List from urllib.parse import quote_plus import orjson @@ -577,3 +578,47 @@ async def test_deleting_items_with_identical_ids(app_client): response = await app_client.get(f"/collections/{collection.id}/items") assert response.status_code == 200, response.json() assert not response.json()["features"] + + +@pytest.mark.parametrize("direction", ("asc", "desc")) +async def test_sorting_and_paging(app_client, load_test_collection, direction: str): + collection_id = load_test_collection.id + for i in range(10): + item = Item( + id=f"item-{i}", + geometry={"type": "Point", "coordinates": [-105.1019, 40.1672]}, + bbox=[-105.1019, 40.1672, -105.1019, 40.1672], + datetime=datetime.now(), + properties={ + "eo:cloud_cover": 42 + i if i % 3 != 0 else None, + }, + ) + item.collection_id = collection_id + response = await app_client.post( + f"/collections/{collection_id}/items", + json=item.to_dict(include_self_link=False, transform_hrefs=False), + ) + assert response.status_code == 200 + + async def search(query: Dict[str, Any]) -> List[Item]: + items: List[Item] = list() + while True: + response = await app_client.post("/search", json=query) + json = response.json() + assert response.status_code == 200, json + items.extend((Item.from_dict(d) for d in json["features"])) + next_link = next( + (link for link in json["links"] if link["rel"] == "next"), None + ) + if next_link is None: + return items + else: + query = next_link["body"] + + query = { + "collections": [collection_id], + "sortby": [{"field": "properties.eo:cloud_cover", "direction": direction}], + "limit": 5, + } + items = await search(query) + assert len(items) == 10, items