From 4b443f71e3d41a2c0753de3f6e0f9d2e766b1900 Mon Sep 17 00:00:00 2001 From: abuzogan Date: Fri, 23 Feb 2024 11:22:07 +0100 Subject: [PATCH] waiting for postgres service to start before running test scripts and moved env variables --- backend/Dockerfile.test | 6 ------ backend/tests.yaml | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/Dockerfile.test b/backend/Dockerfile.test index 46b7ac47..f975133c 100644 --- a/backend/Dockerfile.test +++ b/backend/Dockerfile.test @@ -11,11 +11,5 @@ RUN apt-get update RUN apt-get install -y --no-install-recommends python3-pip RUN pip3 install --no-cache-dir -r requirements.txt -r dev-requirements.txt -# Set environment variables -ENV POSTGRES_USER=test_user -ENV POSTGRES_PASSWORD=test_password -ENV POSTGRES_DB=test_database -ENV POSTGRES_HOST=postgres - # Command to run the tests CMD ["pytest"] \ No newline at end of file diff --git a/backend/tests.yaml b/backend/tests.yaml index 9a4bb115..43e401c9 100644 --- a/backend/tests.yaml +++ b/backend/tests.yaml @@ -7,15 +7,25 @@ services: POSTGRES_USER: test_user POSTGRES_PASSWORD: test_password POSTGRES_DB: test_database + healthcheck: + test: ["CMD-SHELL", "pg_isready -U test_user -d test_database"] + interval: 5s + timeout: 3s + retries: 3 + start_period: 5s test-runner: build: context: . dockerfile: Dockerfile.test depends_on: - - postgres + postgres: + condition: service_healthy environment: POSTGRES_HOST: postgres # Use the service name defined in Docker Compose + POSTGRES_USER: test_user + POSTGRES_PASSWORD: test_password + POSTGRES_DB: test_database volumes: - .:/app - command: ["pytest"] \ No newline at end of file + command: ["pytest"]