Skip to content

Commit

Permalink
fix(#103): Fix Docker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
captaincoordinates committed Jul 18, 2024
1 parent e9b6757 commit 033f9ff
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
12 changes: 6 additions & 6 deletions Dockerfile-3.9
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
FROM python:3.9-buster
FROM python:3.9-slim-bullseye

LABEL description="Test executor"

ENV DEBIAN_FRONTEND noninteractive
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update --fix-missing \
&& apt-get install -y --no-install-recommends \
binutils \
libproj-dev \
gdal-bin \
libgdal-dev \
libsqlite3-mod-spatialite \
spatialite-bin \
build-essential \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir /app
Expand All @@ -19,13 +21,11 @@ COPY requirements-test.txt .
COPY requirements-dev.txt .
RUN pip install -r requirements-test.txt
RUN pip install -r requirements-dev.txt
RUN gdal_version=$(gdal-config --version) && \
pip install pygdal=="$gdal_version.*"

COPY pygeofilter pygeofilter
COPY tests tests
COPY README.md .
COPY setup.py .
RUN pip install -e .

RUN chmod +x tests/execute-tests.sh

CMD ["tests/execute-tests.sh"]
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ pip install -r requirements-dev.txt
pip install -r requirements-test.txt
```

GDAL must also be available in the local environment.

The functionality can be tested using `pytest`.

```bash
Expand All @@ -188,11 +190,10 @@ python -m pytest

### Docker

To execute tests in Docker:
To execute tests with Docker Compose:

```
docker build -t pygeofilter/test -f Dockerfile-3.9 .
docker run --rm pygeofilter/test
./execute-tests.sh
```

## Backends
Expand Down
23 changes: 23 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
services:
elasticsearch:
image: elasticsearch:8.2.2
ports:
- 9200:9200
- 9300:9300
environment:
discovery.type: single-node
xpack.security.enabled: false
xpack.security.http.ssl.enabled: false
healthcheck:
test: ["CMD-SHELL", "curl -s http://localhost:9200/_cluster/health | grep -q '\"status\":\"green\"'"]
interval: 30s
timeout: 10s
retries: 3
tester:
build:
dockerfile: ./Dockerfile-3.9
environment:
PYGEOFILTER_ELASTIC_HOST: elasticsearch
depends_on:
elasticsearch:
condition: service_healthy
9 changes: 9 additions & 0 deletions execute-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

pushd $(dirname $0)

dco="docker compose -f docker-compose.test.yml"
$dco build
$dco run --rm tester pytest
7 changes: 5 additions & 2 deletions tests/backends/elasticsearch/test_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from pygeofilter.backends.elasticsearch import to_filter
from pygeofilter.parsers.ecql import parse
from pygeofilter.util import parse_datetime

from os import environ

class Wildcard(Field):
name = "wildcard"
Expand Down Expand Up @@ -54,7 +54,10 @@ class Index:
@pytest.fixture(autouse=True, scope="session")
def connection():
connections.create_connection(
hosts=["http://localhost:9200"],
hosts=["http://{}:{}".format(
environ.get("PYGEOFILTER_ELASTIC_HOST", "localhost"),
environ.get("PYGEOFILTER_ELASTIC_PORT", "9200"),
)],
)


Expand Down

0 comments on commit 033f9ff

Please sign in to comment.