From 86433a76ab21380da0b8fd8e6082556c850e773d Mon Sep 17 00:00:00 2001 From: Tom Christian Date: Thu, 18 Jul 2024 15:03:18 -0700 Subject: [PATCH] fix(#103): Fix Docker tests --- Dockerfile-3.9 | 12 +++++----- README.md | 7 +++--- docker-compose.test.yml | 24 +++++++++++++++++++ execute-tests.sh | 10 ++++++++ tests/backends/elasticsearch/test_evaluate.py | 7 ++++-- 5 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 docker-compose.test.yml create mode 100755 execute-tests.sh diff --git a/Dockerfile-3.9 b/Dockerfile-3.9 index 94c019a..8d7ddf9 100644 --- a/Dockerfile-3.9 +++ b/Dockerfile-3.9 @@ -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 @@ -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"] diff --git a/README.md b/README.md index ad770cc..bd60b0f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..d989e3c --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,24 @@ +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 + ES_JAVA_OPTS: -Xms1g -Xmx1g + 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 diff --git a/execute-tests.sh b/execute-tests.sh new file mode 100755 index 0000000..75f7f68 --- /dev/null +++ b/execute-tests.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +pushd $(dirname $0) + +dco="docker compose -f docker-compose.test.yml" +$dco build +$dco run --rm tester pytest +exit_code=$? +$dco down +exit $exit_code diff --git a/tests/backends/elasticsearch/test_evaluate.py b/tests/backends/elasticsearch/test_evaluate.py index e3e8904..1fb033f 100644 --- a/tests/backends/elasticsearch/test_evaluate.py +++ b/tests/backends/elasticsearch/test_evaluate.py @@ -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" @@ -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"), + )], )