Skip to content

Commit a2ee00b

Browse files
committed
dismantled the backends from dockerfiles and chnaged the REAME
1 parent 34f36a1 commit a2ee00b

File tree

6 files changed

+68
-453
lines changed

6 files changed

+68
-453
lines changed

README.md

Lines changed: 22 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -32,133 +32,34 @@
3232
- For changes, see the [Changelog](CHANGELOG.md)
3333
- We are always welcoming contributions. For the development notes: [Contributing](CONTRIBUTING.md)
3434

35-
## Installation and Running:
3635

37-
### **Method 1: Install via PyPI and Use Docker/Podman Compose for Backend**
36+
### To install from PyPI:
3837

39-
#### **Prerequisites**
40-
41-
- [**Docker Compose**](https://docs.docker.com/compose/install/) or [**Podman Compose**](https://podman-desktop.io/docs/compose) installed and running on your machine. In all the follwoing steps instead of `docker-compose` you can use `podman-compose` as well.
42-
43-
This approach is for users who want to install the Python package separately before running the app.
44-
45-
#### **Step 1: Install STAC-FastAPI**
46-
47-
- **For Elasticsearch backend:**
48-
49-
```bash
50-
pip install stac_fastapi.elasticsearch
51-
```
52-
53-
- **For OpenSearch backend:**
54-
55-
```bash
56-
pip install stac_fastapi.opensearch
57-
```
58-
59-
#### **Step 2: Start Elasticsearch/OpenSearch Backend**
60-
61-
Launch Elasticsearch using Docker Compose:
62-
63-
```bash
64-
# For ElasticSearch
65-
docker-compose up -d elasticsearch
66-
# For OpenSearch
67-
docker-compose up -d opensearch
38+
```shell
39+
pip install stac_fastapi.elasticsearch
6840
```
69-
70-
#### **Step 3: Run the Application**
71-
72-
With Elasticsearch running, you can now run the application:
73-
74-
```bash
75-
uvicorn stac_fastapi.elasticsearch.app:app \
76-
--host localhost \
77-
--port 8080 \
78-
--workers 10 \
79-
--reload
41+
or
42+
```
43+
pip install stac_fastapi.opensearch
8044
```
8145

82-
and with OpenSearch running:
46+
## Run Elasticsearch API backend on localhost:8080
47+
48+
You need to ensure [**Docker Compose**](https://docs.docker.com/compose/install/) or [**Podman Compose**](https://podman-desktop.io/docs/compose) installed and running on your machine. In the follwoing command instead of `docker-compose` you can use `podman-compose` as well.
8349

84-
```bash
85-
uvicorn stac_fastapi.opensearch.app:app \
86-
--host localhost \
87-
--port 8080 \
88-
--workers 10 \
89-
--reload
50+
```shell
51+
docker-compose up elasticsearch app-elasticsearch
9052
```
9153

92-
By default, Docker Compose uses Elasticsearch 8.x and OpenSearch 2.11.1. If you prefer to use different versions, create a file named `.env` in the same directory where you run Docker Compose and include the following lines:
54+
By default, docker-compose uses Elasticsearch 8.x and OpenSearch 2.11.1.
55+
If you wish to use a different version, put the following in a
56+
file named `.env` in the same directory you run docker-compose from:
9357

94-
```env
58+
```shell
9559
ELASTICSEARCH_VERSION=7.17.1
9660
OPENSEARCH_VERSION=2.11.0
9761
```
98-
99-
Most recent Elasticsearch 7.x versions should also be compatible. For detailed compatibility information, please refer to the [opensearch-py documentation](https://github.com/opensearch-project/opensearch-py/blob/main/COMPATIBILITY.md).
100-
101-
### **Method 2: Install and run only with Docker or podman**
102-
103-
#### Prerequisites
104-
105-
- [**Docker**](https://docs.docker.com/get-started/) or [**Podman**](https://podman.io/docs) installed and running on your machine. In all the follwoing steps instead of `docker` you can use `podman` as well.
106-
107-
> [!IMPORTANT]
108-
> The variables `RUN_LOCAL_ES` and `RUN_LOCAL_OS` correspond to **different Docker backend images**. By default, both are set to `0`, indicating that the backend systems are expected to run externally. In this case, you must configure the appropriate `ES_HOST` and `ES_PORT` environment variables to connect to the external Elasticsearch or OpenSearch instance. Alternatively, if you do not have an external backend and wish to run Elasticsearch or OpenSearch alongside the STAC-FastAPI within the container, set the respective variable to `1`:
109-
> - Use `RUN_LOCAL_ES` with the `ghcr.io/stac-utils/stac-fastapi-es` image.
110-
> - Use `RUN_LOCAL_OS` with the `ghcr.io/stac-utils/stac-fastapi-os` image.
111-
112-
#### **Step 1: Run the Docker Container**
113-
114-
- **For Elasticsearch Backend:**
115-
116-
- **Connecting to External Instance:**
117-
118-
```shell
119-
docker run -d -p 8080:8080 -e ES_HOST=external_host -e ES_PORT=external_port ghcr.io/stac-utils/stac-fastapi-es:latest
120-
```
121-
122-
- **Running Locally:**
123-
124-
```shell
125-
docker run -d -p 8080:8080 -p 9200:9200 -e RUN_LOCAL_ES=1 ghcr.io/stac-utils/stac-fastapi-es:latest
126-
```
127-
128-
- **For OpenSearch Backend:**
129-
130-
- **Connecting to External Instance:**
131-
132-
```shell
133-
docker run -d -p 8080:8080 -e ES_HOST=external_host -e ES_PORT=external_port ghcr.io/stac-utils/stac-fastapi-os:latest
134-
```
135-
136-
- **Running Locally:**
137-
138-
```shell
139-
docker run -d -p 8080:8080 -p 9202:9202 -e RUN_LOCAL_OS=1 ghcr.io/stac-utils/stac-fastapi-os:latest
140-
```
141-
> [!Note]
142-
> For external instances of both **Elasticsearch** and **OpenSearch**, configure the following
143-
> environment variables as needed:
144-
> - `-e ES_USE_SSL=false` — Set to `true` if SSL is enabled.
145-
> - `-e ES_VERIFY_CERTS=false` — Set to `true` to enable SSL certificate verification.
146-
147-
> [!TIP]
148-
> If you need to mount a volume, use the [`-v`](https://docs.docker.com/engine/storage/volumes/#choose-the--v-or---mount-flag) flag. To specify an environment file, use the [`--env-file`](https://docs.docker.com/reference/cli/docker/container/run/#env) flag.
149-
150-
151-
#### **Step 2: Verify and Access**
152-
153-
- **Check if the container is running:**
154-
155-
```shell
156-
docker ps
157-
```
158-
159-
- **Access the API:**
160-
161-
Visit `http://localhost:8080` in your browser or use it as the base URL for API requests.
62+
The most recent Elasticsearch 7.x versions should also work. See the [opensearch-py docs](https://github.com/opensearch-project/opensearch-py/blob/main/COMPATIBILITY.md) for compatibility information.
16263

16364
#### **Configuration reference keys:**
16465

@@ -167,10 +68,8 @@ You can customize additional settings in your `.env` file:
16768

16869
| Variable | Description | Default | Required |
16970
|------------------------------|--------------------------------------------------------------------------------------|--------------------------|---------------------------------------------------------------------------------------------|
170-
| `RUN_LOCAL_ES` | Enable local Elasticsearch in the container. | `0` | Optional (set to `1` to run local Elasticsearch) |
171-
| `RUN_LOCAL_OS` | Enable local OpenSearch in the container. | `0` | Optional (set to `1` to run local OpenSearch) |
172-
| `ES_HOST` | Hostname for external Elasticsearch/OpenSearch. | `localhost` | **Required if `RUN_LOCAL_ES=0` or `RUN_LOCAL_OS=0`** |
173-
| `ES_PORT` | Port for Elasticsearch/OpenSearch. | `9200` (ES) / `9202` (OS)| **Required if `RUN_LOCAL_ES=0` or `RUN_LOCAL_OS=0`** |
71+
| `ES_HOST` | Hostname for external Elasticsearch/OpenSearch. | `localhost` | Optional |
72+
| `ES_PORT` | Port for Elasticsearch/OpenSearch. | `9200` (ES) / `9202` (OS)| Optional |
17473
| `ES_USE_SSL` | Use SSL for connecting to Elasticsearch/OpenSearch. | `false` | Optional |
17574
| `ES_VERIFY_CERTS` | Verify SSL certificates when connecting. | `false` | Optional |
17675
| `STAC_FASTAPI_TITLE` | Title of the API in the documentation. | `stac-fastapi-elasticsearch` or `stac-fastapi-opensearch` | Optional |
@@ -182,11 +81,12 @@ You can customize additional settings in your `.env` file:
18281
| `WEB_CONCURRENCY` | Number of worker processes. | `10` | Optional |
18382
| `RELOAD` | Enable auto-reload for development. | `true` | Optional |
18483
| `STAC_FASTAPI_RATE_LIMIT` | API rate limit per client. | `200/minute` | Optional |
185-
84+
| `BACKEND` | Tests-related variable | `elasticsearch` or `opensearch` based on the backend | Optional |
85+
| `ELASTICSEARCH_VERSION` | ElasticSearch version | `7.17.1` | Optional |
86+
| `OPENSEARCH_VERSION` | OpenSearch version | `2.11.0` | Optional |
18687

18788
> [!NOTE]
188-
> The variables `ES_HOST`, `ES_PORT`, `ES_USE_SSL`, and `ES_VERIFY_CERTS` apply to both Elasticsearch and OpenSearch, so there is no need to rename the key names to `OS_` even if you're using OpenSearch.
189-
89+
> The variables `ES_HOST`, `ES_PORT`, `ES_USE_SSL`, and `ES_VERIFY_CERTS` apply to both Elasticsearch and OpenSearch backends, so there is no need to rename the key names to `OS_` even if you're using OpenSearch.
19090
19191
## Interacting with the API
19292

docker-compose.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ version: '3.9'
33
services:
44
app-elasticsearch:
55
container_name: stac-fastapi-es
6-
image: stac-utils/stac-fastapi-es
6+
image: stac-es
77
restart: always
8-
build:
9-
context: .
10-
dockerfile: dockerfiles/Dockerfile.dev.es
118
environment:
129
- STAC_FASTAPI_TITLE=stac-fastapi-elasticsearch
1310
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Elasticsearch backend
@@ -35,11 +32,8 @@ services:
3532

3633
app-opensearch:
3734
container_name: stac-fastapi-os
38-
image: stac-utils/stac-fastapi-os
35+
image: ghcr.io/stac-utils/stac-fastapi-os
3936
restart: always
40-
build:
41-
context: .
42-
dockerfile: dockerfiles/Dockerfile.dev.os
4337
environment:
4438
- STAC_FASTAPI_TITLE=stac-fastapi-opensearch
4539
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Opensearch backend

dockerfiles/Dockerfile.ci.es

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,34 @@
1-
FROM debian:bookworm-slim AS base
1+
FROM python:3.12-slim
2+
3+
ENV APP_HOST="0.0.0.0"
4+
ENV APP_PORT="8080"
5+
ENV WEB_CONCURRENCY="10"
6+
ENV RELOAD="true"
7+
ENV ES_HOST="localhost"
8+
ENV ES_PORT="9200"
9+
ENV ES_USE_SSL="false"
10+
ENV ES_VERIFY_CERTS="false"
11+
ENV STAC_FASTAPI_TITLE="stac-fastapi-elasticsearch"
12+
ENV STAC_FASTAPI_DESCRIPTION="A STAC FastAPI with an Elasticsearch backend"
13+
ENV STAC_FASTAPI_VERSION="2.1"
14+
ENV ENVIRONMENT="local"
15+
ENV BACKEND="elasticsearch"
16+
ENV STAC_FASTAPI_RATE_LIMIT="200/minute"
217

3-
ENV RUN_LOCAL_ES=0
18+
WORKDIR /app
419

520
RUN apt-get update && \
621
apt-get install -y --no-install-recommends \
722
gcc \
823
curl \
9-
python3 \
10-
python3-pip \
11-
python3-venv \
1224
&& apt-get clean && \
1325
rm -rf /var/lib/apt/lists/*
1426

15-
# set non-root user
16-
RUN groupadd -g 1000 elasticsearch && \
17-
useradd -u 1000 -g elasticsearch -s /bin/bash -m elasticsearch
18-
19-
# elasticsearch binaries and libraries
20-
COPY --from=docker.elastic.co/elasticsearch/elasticsearch:8.11.0 /usr/share/elasticsearch /usr/share/elasticsearch
21-
22-
# ser ownership
23-
RUN chown -R elasticsearch:elasticsearch /usr/share/elasticsearch
24-
25-
WORKDIR /app
26-
COPY . /app
27-
28-
# stac-fastapi-es installation
29-
RUN pip3 install --no-cache-dir --break-system-packages -e ./stac_fastapi/core && \
30-
pip3 install --no-cache-dir --break-system-packages ./stac_fastapi/elasticsearch[server]
31-
32-
COPY elasticsearch/config/elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml
33-
34-
COPY dockerfiles/entrypoint-es.sh /entrypoint.sh
35-
RUN chmod +x /entrypoint.sh
36-
37-
38-
ENV ES_JAVA_OPTS="-Xms512m -Xmx1g" \
39-
PATH="/usr/share/elasticsearch/bin:${PATH}"
40-
27+
COPY . /app/
4128

42-
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD \
43-
curl --silent --fail http://${APP_HOST}:${APP_PORT}/api.html || exit 1
29+
RUN pip3 install --no-cache-dir -e ./stac_fastapi/core && \
30+
pip3 install --no-cache-dir ./stac_fastapi/elasticsearch[server]
4431

32+
USER root
4533

46-
USER elasticsearch
47-
ENTRYPOINT ["/entrypoint.sh"]
34+
CMD ["python", "-m", "stac_fastapi.elasticsearch.app"]

dockerfiles/Dockerfile.ci.os

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,34 @@
1-
FROM debian:bookworm-slim AS base
1+
FROM python:3.12-slim
2+
3+
ENV STAC_FASTAPI_TITLE="stac-fastapi-opensearch"
4+
ENV STAC_FASTAPI_DESCRIPTION="A STAC FastAPI with an Opensearch backend"
5+
ENV STAC_FASTAPI_VERSION="3.0.0a2"
6+
ENV APP_HOST="0.0.0.0"
7+
ENV APP_PORT="8082"
8+
ENV RELOAD="true"
9+
ENV ENVIRONMENT="local"
10+
ENV WEB_CONCURRENCY="10"
11+
ENV ES_HOST="localhost"
12+
ENV ES_PORT="9202"
13+
ENV ES_USE_SSL="false"
14+
ENV ES_VERIFY_CERTS="false"
15+
ENV BACKEND="opensearch"
16+
ENV STAC_FASTAPI_RATE_LIMIT="200/minute"
217

3-
ENV RUN_LOCAL_OS=0
18+
WORKDIR /app
419

520
RUN apt-get update && \
621
apt-get install -y --no-install-recommends \
722
gcc \
823
curl \
9-
python3 \
10-
python3-pip \
11-
python3-venv \
1224
&& apt-get clean && \
1325
rm -rf /var/lib/apt/lists/*
1426

15-
# set non-root user
16-
RUN groupadd -g 1000 opensearch && \
17-
useradd -u 1000 -g opensearch -s /bin/bash -m opensearch
18-
19-
# opensearch binaries and libraries
20-
COPY --from=opensearchproject/opensearch:2.11.1 /usr/share/opensearch /usr/share/opensearch
21-
22-
# ser ownership
23-
RUN chown -R opensearch:opensearch /usr/share/opensearch
24-
25-
WORKDIR /app
26-
COPY . /app
27-
28-
# stac-fastapi-os installation
29-
RUN pip3 install --no-cache-dir --break-system-packages -e ./stac_fastapi/core && \
30-
pip3 install --no-cache-dir --break-system-packages ./stac_fastapi/opensearch[server]
31-
32-
COPY opensearch/config/opensearch.yml /usr/share/opensearch/config/opensearch.yml
33-
34-
COPY dockerfiles/entrypoint-os.sh /entrypoint.sh
35-
RUN chmod +x /entrypoint.sh
27+
COPY . /app/
3628

37-
ENV OPENSEARCH_JAVA_OPTS="-Xms512m -Xmx1g" \
38-
PATH="/usr/share/opensearch/bin:${PATH}"
29+
RUN pip3 install --no-cache-dir -e ./stac_fastapi/core && \
30+
pip3 install --no-cache-dir ./stac_fastapi/opensearch[server]
3931

40-
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD \
41-
curl --silent --fail http://${APP_HOST}:${APP_PORT}/api.html || exit 1
32+
USER root
4233

43-
USER opensearch
44-
ENTRYPOINT ["/entrypoint.sh"]
34+
CMD ["python", "-m", "stac_fastapi.opensearch.app"]

0 commit comments

Comments
 (0)