Skip to content

Commit 033f9ff

Browse files
fix(#103): Fix Docker tests
1 parent e9b6757 commit 033f9ff

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

Dockerfile-3.9

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
FROM python:3.9-buster
1+
FROM python:3.9-slim-bullseye
22

33
LABEL description="Test executor"
44

5-
ENV DEBIAN_FRONTEND noninteractive
5+
ENV DEBIAN_FRONTEND=noninteractive
66
RUN apt-get update --fix-missing \
77
&& apt-get install -y --no-install-recommends \
88
binutils \
99
libproj-dev \
1010
gdal-bin \
11+
libgdal-dev \
1112
libsqlite3-mod-spatialite \
1213
spatialite-bin \
14+
build-essential \
1315
&& rm -rf /var/lib/apt/lists/*
1416

1517
RUN mkdir /app
@@ -19,13 +21,11 @@ COPY requirements-test.txt .
1921
COPY requirements-dev.txt .
2022
RUN pip install -r requirements-test.txt
2123
RUN pip install -r requirements-dev.txt
24+
RUN gdal_version=$(gdal-config --version) && \
25+
pip install pygdal=="$gdal_version.*"
2226

2327
COPY pygeofilter pygeofilter
2428
COPY tests tests
2529
COPY README.md .
2630
COPY setup.py .
2731
RUN pip install -e .
28-
29-
RUN chmod +x tests/execute-tests.sh
30-
31-
CMD ["tests/execute-tests.sh"]

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ pip install -r requirements-dev.txt
180180
pip install -r requirements-test.txt
181181
```
182182

183+
GDAL must also be available in the local environment.
184+
183185
The functionality can be tested using `pytest`.
184186

185187
```bash
@@ -188,11 +190,10 @@ python -m pytest
188190

189191
### Docker
190192

191-
To execute tests in Docker:
193+
To execute tests with Docker Compose:
192194

193195
```
194-
docker build -t pygeofilter/test -f Dockerfile-3.9 .
195-
docker run --rm pygeofilter/test
196+
./execute-tests.sh
196197
```
197198

198199
## Backends

docker-compose.test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
services:
2+
elasticsearch:
3+
image: elasticsearch:8.2.2
4+
ports:
5+
- 9200:9200
6+
- 9300:9300
7+
environment:
8+
discovery.type: single-node
9+
xpack.security.enabled: false
10+
xpack.security.http.ssl.enabled: false
11+
healthcheck:
12+
test: ["CMD-SHELL", "curl -s http://localhost:9200/_cluster/health | grep -q '\"status\":\"green\"'"]
13+
interval: 30s
14+
timeout: 10s
15+
retries: 3
16+
tester:
17+
build:
18+
dockerfile: ./Dockerfile-3.9
19+
environment:
20+
PYGEOFILTER_ELASTIC_HOST: elasticsearch
21+
depends_on:
22+
elasticsearch:
23+
condition: service_healthy

execute-tests.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
pushd $(dirname $0)
6+
7+
dco="docker compose -f docker-compose.test.yml"
8+
$dco build
9+
$dco run --rm tester pytest

tests/backends/elasticsearch/test_evaluate.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from pygeofilter.backends.elasticsearch import to_filter
2323
from pygeofilter.parsers.ecql import parse
2424
from pygeofilter.util import parse_datetime
25-
25+
from os import environ
2626

2727
class Wildcard(Field):
2828
name = "wildcard"
@@ -54,7 +54,10 @@ class Index:
5454
@pytest.fixture(autouse=True, scope="session")
5555
def connection():
5656
connections.create_connection(
57-
hosts=["http://localhost:9200"],
57+
hosts=["http://{}:{}".format(
58+
environ.get("PYGEOFILTER_ELASTIC_HOST", "localhost"),
59+
environ.get("PYGEOFILTER_ELASTIC_PORT", "9200"),
60+
)],
5861
)
5962

6063

0 commit comments

Comments
 (0)