From ea43f96898753fc951f8172cfe752d2f0d3fadd9 Mon Sep 17 00:00:00 2001 From: Malaber Date: Sat, 11 Apr 2026 17:00:50 +0200 Subject: [PATCH] Pass app service env and improve health diagnostics --- .gitlab-ci.yml | 9 +++++++++ tasks.py | 13 +++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f6d5abe..9e825c8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,6 +41,15 @@ rails e2e spec: alias: postgres - name: $CI_REGISTRY_IMAGE/production/commits:$CI_COMMIT_SHA alias: app + variables: + POSTGRES_URL: postgres://turniere:turniere@postgres:5432/turniere_blackbox + POSTGRES_USERNAME: turniere + POSTGRES_PASSWORD: turniere + SECRET_KEY_BASE: turniere-blackbox-secret-key-base-please-change-in-real-prod + MAILGUN_API_KEY: blackbox-test-api-key + MAILGUN_DOMAIN: blackbox.example.com + RAILS_LOG_TO_STDOUT: "1" + RAILS_SERVE_STATIC_FILES: "1" command: - bundle - exec diff --git a/tasks.py b/tasks.py index aa85ee6..1b71ac1 100644 --- a/tasks.py +++ b/tasks.py @@ -7,6 +7,7 @@ import signal import subprocess import time import urllib.request +import urllib.error from pathlib import Path @@ -46,16 +47,24 @@ def _wait_for_http(base_url=TEST_BASE_URL, timeout=60): deadline = time.time() + timeout healthz_url = f"{base_url}/healthz" opener = urllib.request.build_opener(urllib.request.ProxyHandler({})) + last_error = None while time.time() < deadline: try: with opener.open(healthz_url) as response: if response.status == 200: return - except Exception: + last_error = f"unexpected status {response.status}" + except urllib.error.HTTPError as error: + body = error.read().decode("utf-8", errors="replace") + last_error = f"http {error.code}: {body}" + time.sleep(0.5) + except Exception as error: + last_error = repr(error) time.sleep(0.5) - raise RuntimeError(f"healthcheck did not become ready within {timeout}s: {healthz_url}") + detail = f" last error: {last_error}" if last_error else "" + raise RuntimeError(f"healthcheck did not become ready within {timeout}s: {healthz_url}.{detail}") def _docker_compose_cmd(project_name=BLACKBOX_PROJECT, compose_file=BLACKBOX_COMPOSE_FILE):