Skip to content

Commit 5208179

Browse files
authored
Merge pull request #186 from stac-utils/common_core
Create Common opensearch/ elasticsearch core package
2 parents 610d800 + d530cb8 commit 5208179

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+964
-230
lines changed

.github/workflows/cicd.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,29 +88,39 @@ jobs:
8888
run: |
8989
pip install ./stac_fastapi/elasticsearch[dev,server]
9090
91+
- name: Install opensearch stac-fastapi
92+
run: |
93+
pip install ./stac_fastapi/opensearch[dev,server]
94+
95+
- name: Install core library stac-fastapi
96+
run: |
97+
pip install ./stac_fastapi/core
98+
9199
- name: Run test suite against Elasticsearch 7.x
92100
run: |
93-
cd stac_fastapi/elasticsearch && pipenv run pytest -svvv
101+
pipenv run pytest -svvv
94102
env:
95103
ENVIRONMENT: testing
96104
ES_PORT: 9200
97105
ES_HOST: 172.17.0.1
98106
ES_USE_SSL: false
99107
ES_VERIFY_CERTS: false
108+
BACKEND: elasticsearch
100109

101110
- name: Run test suite against Elasticsearch 8.x
102111
run: |
103-
cd stac_fastapi/elasticsearch && pipenv run pytest -svvv
112+
pipenv run pytest -svvv
104113
env:
105114
ENVIRONMENT: testing
106115
ES_PORT: 9400
107116
ES_HOST: 172.17.0.1
108117
ES_USE_SSL: false
109118
ES_VERIFY_CERTS: false
119+
BACKEND: elasticsearch
110120

111121
- name: Run test suite against OpenSearch 2.11.1
112122
run: |
113-
cd stac_fastapi/elasticsearch && pipenv run pytest -svvv
123+
pipenv run pytest -svvv
114124
env:
115125
ENVIRONMENT: testing
116126
ES_PORT: 9202

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Added
1111

12+
- Added core library package for common logic [#186](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/186)
13+
1214
### Changed
1315

16+
- Moved Elasticsearch and Opensearch backends into separate packages [#186](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/186)
17+
1418
### Fixed
1519

20+
- Allow additional top-level properties on collections [#191](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/191)
21+
1622
## [v1.1.0]
1723

1824
### Added
@@ -28,7 +34,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2834

2935
### Fixed
3036

31-
- Allow additional top-level properties on collections [#191](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/191)
3237
- Exclude unset fields in search response [#166](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/166)
3338
- Upgrade stac-fastapi to v2.4.9 [#172](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/172)
3439
- Set correct default filter-lang for GET /search requests [#179](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/179)
@@ -115,4 +120,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
115120
[v1.0.0]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.3.0...v1.0.0>
116121
[v0.3.0]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.2.0...v0.3.0>
117122
[v0.2.0]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.1.0...v0.2.0>
118-
[v0.1.0]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.1.0>
123+
[v0.1.0]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.1.0>

Dockerfile.deploy renamed to Dockerfile.deploy.es

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ WORKDIR /app
1212

1313
COPY . /app
1414

15+
RUN pip install --no-cache-dir -e ./stac_fastapi/core
1516
RUN pip install --no-cache-dir ./stac_fastapi/elasticsearch[server]
1617

1718
EXPOSE 8080

Dockerfile.deploy.os

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM python:3.10-slim
2+
3+
RUN apt-get update && \
4+
apt-get -y upgrade && \
5+
apt-get -y install gcc && \
6+
apt-get clean && \
7+
rm -rf /var/lib/apt/lists/*
8+
9+
ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
10+
11+
WORKDIR /app
12+
13+
COPY . /app
14+
15+
RUN pip install --no-cache-dir -e ./stac_fastapi/core
16+
RUN pip install --no-cache-dir ./stac_fastapi/opensearch[server]
17+
18+
EXPOSE 8080
19+
20+
CMD ["uvicorn", "stac_fastapi.opensearch.app:app", "--host", "0.0.0.0", "--port", "8080"]

Dockerfile.dev renamed to Dockerfile.dev.es

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ WORKDIR /app
1515

1616
COPY . /app
1717

18+
RUN pip install --no-cache-dir -e ./stac_fastapi/core
1819
RUN pip install --no-cache-dir -e ./stac_fastapi/elasticsearch[dev,server]

Dockerfile.dev.os

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM python:3.10-slim
2+
3+
4+
# update apt pkgs, and install build-essential for ciso8601
5+
RUN apt-get update && \
6+
apt-get -y upgrade && \
7+
apt-get install -y build-essential && \
8+
apt-get clean && \
9+
rm -rf /var/lib/apt/lists/*
10+
11+
# update certs used by Requests
12+
ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
13+
14+
WORKDIR /app
15+
16+
COPY . /app
17+
18+
RUN pip install --no-cache-dir -e ./stac_fastapi/core
19+
RUN pip install --no-cache-dir -e ./stac_fastapi/opensearch[dev,server]

Makefile

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#!make
22
APP_HOST ?= 0.0.0.0
3-
ES_APP_PORT ?= 8080
43
EXTERNAL_APP_PORT ?= ${APP_PORT}
54

65
ES_APP_PORT ?= 8080
76
ES_HOST ?= docker.for.mac.localhost
87
ES_PORT ?= 9200
98

109
OS_APP_PORT ?= 8082
11-
ES_HOST ?= docker.for.mac.localhost
10+
OS_HOST ?= docker.for.mac.localhost
1211
OS_PORT ?= 9202
1312

1413
run_es = docker-compose \
@@ -27,9 +26,13 @@ run_os = docker-compose \
2726
-e APP_PORT=${OS_APP_PORT} \
2827
app-opensearch
2928

30-
.PHONY: image-deploy
31-
image-deploy:
32-
docker build -f Dockerfile.deploy -t stac-fastapi-elasticsearch:latest .
29+
.PHONY: image-deploy-es
30+
image-deploy-es:
31+
docker build -f Dockerfile.dev.es -t stac-fastapi-elasticsearch:latest .
32+
33+
.PHONY: image-deploy-os
34+
image-deploy-os:
35+
docker build -f Dockerfile.dev.os -t stac-fastapi-opensearch:latest .
3336

3437
.PHONY: run-deploy-locally
3538
run-deploy-locally:
@@ -44,30 +47,38 @@ run-deploy-locally:
4447
image-dev:
4548
docker-compose build
4649

47-
.PHONY: docker-run
48-
docker-run: image-dev
50+
.PHONY: docker-run-es
51+
docker-run-es: image-dev
4952
$(run_es)
5053

51-
.PHONY: docker-shell
52-
docker-shell:
54+
.PHONY: docker-run-os
55+
docker-run-os: image-dev
56+
$(run_os)
57+
58+
.PHONY: docker-shell-es
59+
docker-shell-es:
5360
$(run_es) /bin/bash
5461

62+
.PHONY: docker-shell-os
63+
docker-shell-os:
64+
$(run_os) /bin/bash
65+
5566
.PHONY: test-elasticsearch
56-
test:
57-
-$(run_es) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh elasticsearch:9200 && cd /app/stac_fastapi/elasticsearch/tests/ && pytest'
67+
test-elasticsearch:
68+
-$(run_es) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh elasticsearch:9200 && cd stac_fastapi/tests/ && pytest'
5869
docker-compose down
5970

6071
.PHONY: test-opensearch
6172
test-opensearch:
62-
-$(run_os) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh opensearch:9202 && cd /app/stac_fastapi/elasticsearch/tests/ && pytest'
73+
-$(run_os) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh opensearch:9202 && cd stac_fastapi/tests/ && pytest'
6374
docker-compose down
6475

6576
.PHONY: test
6677
test:
67-
-$(run_es) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh elasticsearch:9200 && cd /app/stac_fastapi/elasticsearch/tests/ && pytest'
78+
-$(run_es) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh elasticsearch:9200 && cd stac_fastapi/tests/ && pytest'
6879
docker-compose down
6980

70-
-$(run_os) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh opensearch:9202 && cd /app/stac_fastapi/elasticsearch/tests/ && pytest'
81+
-$(run_os) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh opensearch:9202 && cd stac_fastapi/tests/ && pytest'
7182
docker-compose down
7283

7384
.PHONY: run-database-es
@@ -83,12 +94,17 @@ pybase-install:
8394
pip install wheel && \
8495
pip install -e ./stac_fastapi/api[dev] && \
8596
pip install -e ./stac_fastapi/types[dev] && \
86-
pip install -e ./stac_fastapi/extensions[dev]
97+
pip install -e ./stac_fastapi/extensions[dev] && \
98+
pip install -e ./stac_fastapi/core
8799

88-
.PHONY: install
89-
install: pybase-install
100+
.PHONY: install-es
101+
install-es: pybase-install
90102
pip install -e ./stac_fastapi/elasticsearch[dev,server]
91103

104+
.PHONY: install-os
105+
install-os: pybase-install
106+
pip install -e ./stac_fastapi/opensearch[dev,server]
107+
92108
.PHONY: ingest
93109
ingest:
94110
python3 data_loader/data_loader.py

README.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
# STAC FastAPI Elasticsearch (sfes)
1+
# stac-fastapi-elasticsearch-opensearch (sfeos)
22

3-
## Elasticsearch backend for stac-fastapi with Opensearch support
3+
## Elasticsearch and Opensearch backends for the stac-fastapi project
44

5-
#### Join our [Gitter](https://gitter.im/stac-fastapi-elasticsearch/community) page
5+
[![PyPI version](https://badge.fury.io/py/stac-fastapi.elasticsearch.svg)](https://badge.fury.io/py/stac-fastapi.elasticsearch)
66

7-
#### Check out the public Postman documentation [Postman](https://documenter.getpostman.com/view/12888943/2s8ZDSdRHA)
7+
To install from PyPI:
88

9-
#### Check out the examples folder for deployment options, ex. running sfes from pip in docker
9+
```shell
10+
pip install stac_fastapi.elasticsearch
11+
```
12+
or
13+
```
14+
pip install stac_fastapi.opensearch
15+
```
1016

1117
#### For changes, see the [Changelog](CHANGELOG.md)
1218

@@ -19,6 +25,13 @@ To install the classes in your local Python env, run:
1925
pip install -e 'stac_fastapi/elasticsearch[dev]'
2026
```
2127

28+
or
29+
30+
```shell
31+
pip install -e 'stac_fastapi/opensearch[dev]'
32+
```
33+
34+
2235
### Pre-commit
2336

2437
Install [pre-commit](https://pre-commit.com/#install).
@@ -29,17 +42,17 @@ Prior to commit, run:
2942
pre-commit run --all-files
3043
```
3144

32-
33-
## Building
45+
## Build Elasticsearh API backend
3446

3547
```shell
36-
docker-compose build
48+
docker-compose up elasticsearch
49+
docker-compose build app-elasticsearch
3750
```
3851

39-
## Running API on localhost:8080
52+
## Running Elasticsearh API on localhost:8080
4053

4154
```shell
42-
docker-compose up
55+
docker-compose up app-elasticsearch
4356
```
4457

4558
By default, docker-compose uses Elasticsearch 8.x and OpenSearch 2.11.1.

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
restart: always
88
build:
99
context: .
10-
dockerfile: Dockerfile.dev
10+
dockerfile: Dockerfile.dev.es
1111
environment:
1212
- APP_HOST=0.0.0.0
1313
- APP_PORT=8080
@@ -36,7 +36,7 @@ services:
3636
restart: always
3737
build:
3838
context: .
39-
dockerfile: Dockerfile.dev
39+
dockerfile: Dockerfile.dev.os
4040
environment:
4141
- APP_HOST=0.0.0.0
4242
- APP_PORT=8082
@@ -57,7 +57,7 @@ services:
5757
depends_on:
5858
- opensearch
5959
command:
60-
bash -c "./scripts/wait-for-it-es.sh os-container:9202 && python -m stac_fastapi.elasticsearch.app"
60+
bash -c "./scripts/wait-for-it-es.sh os-container:9202 && python -m stac_fastapi.opensearch.app"
6161

6262
elasticsearch:
6363
container_name: es-container

examples/pip_docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ WORKDIR /app
1515

1616
COPY . /app
1717

18-
RUN pip install stac-fastapi.elasticsearch==0.3.0
18+
RUN pip install stac-fastapi.elasticsearch==1.1.0

stac_fastapi/core/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# stac-fastapi core library for Elasticsearch and Opensearch backends

stac_fastapi/core/setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[metadata]
2+
version = attr: stac_fastapi.core.version.__version__

stac_fastapi/core/setup.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""stac_fastapi: core elasticsearch/ opensearch module."""
2+
3+
from setuptools import find_namespace_packages, setup
4+
5+
with open("README.md") as f:
6+
desc = f.read()
7+
8+
install_requires = [
9+
"fastapi",
10+
"attrs",
11+
"pydantic[dotenv]<2",
12+
"stac_pydantic==2.0.*",
13+
"stac-fastapi.types==2.4.9",
14+
"stac-fastapi.api==2.4.9",
15+
"stac-fastapi.extensions==2.4.9",
16+
"pystac[validation]",
17+
"orjson",
18+
"overrides",
19+
"geojson-pydantic",
20+
"pygeofilter==0.2.1",
21+
]
22+
23+
setup(
24+
name="stac-fastapi.core",
25+
description="Core library for the Elasticsearch and Opensearch stac-fastapi backends.",
26+
long_description=desc,
27+
long_description_content_type="text/markdown",
28+
python_requires=">=3.8",
29+
classifiers=[
30+
"Intended Audience :: Developers",
31+
"Intended Audience :: Information Technology",
32+
"Intended Audience :: Science/Research",
33+
"Programming Language :: Python :: 3.8",
34+
"Programming Language :: Python :: 3.9",
35+
"Programming Language :: Python :: 3.10",
36+
"Programming Language :: Python :: 3.11",
37+
"License :: OSI Approved :: MIT License",
38+
],
39+
url="https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch",
40+
license="MIT",
41+
packages=find_namespace_packages(),
42+
zip_safe=False,
43+
install_requires=install_requires,
44+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Core library."""

0 commit comments

Comments
 (0)