diff --git a/Dockerfile_test_app b/Dockerfile_test_app index f1bf22f..a4bfb6b 100644 --- a/Dockerfile_test_app +++ b/Dockerfile_test_app @@ -1,14 +1,10 @@ FROM nginx:1.27-alpine -COPY .git /tmp/repo/.git - # Configure nginx to listen on 5001 to match container port expectations. RUN sed -i 's/listen 80;/listen 5001;/' /etc/nginx/conf.d/default.conf -# Build a custom landing page directly in the image and inject git revision. +# Build a custom landing page directly in the image. RUN set -eux; \ - apk add --no-cache --virtual .git-deps git; \ - GIT_REVISION="$(git --git-dir=/tmp/repo/.git rev-parse --short HEAD 2>/dev/null || echo unknown)"; \ { \ echo ''; \ echo ''; \ @@ -21,11 +17,9 @@ RUN set -eux; \ echo '

Nginx Is Running

'; \ echo '

Custom landing page for the Brencher test app container.

'; \ echo '

Port: 5001

'; \ - echo "

Git revision: ${GIT_REVISION}

"; \ + echo '

Git revision: unknown

'; \ echo ''; \ echo ''; \ - } > /usr/share/nginx/html/index.html; \ - rm -rf /tmp/repo/.git; \ - apk del .git-deps + } > /usr/share/nginx/html/index.html EXPOSE 5001 diff --git a/tests/configs/nginx.py b/tests/configs/nginx.py index 095b9b8..d49a033 100644 --- a/tests/configs/nginx.py +++ b/tests/configs/nginx.py @@ -1,8 +1,21 @@ +import subprocess +from pathlib import Path + from enironment import Environment from steps.docker_plain import DockerImageBuild, DockerContainerCheck, DockerContainerDeploy from steps.git import GitClone, CheckoutMerged, GitUnmerge from steps.shared_state import SharedStateHolderInMemory +REPO_ROOT = Path(__file__).resolve().parents[2] +CURRENT_BRANCH = subprocess.check_output( + ["git", "-C", str(REPO_ROOT), "rev-parse", "--abbrev-ref", "HEAD"], + text=True, +).strip() +CURRENT_COMMIT = subprocess.check_output( + ["git", "-C", str(REPO_ROOT), "rev-parse", "HEAD"], + text=True, +).strip() + clone = GitClone(url="https://github.com/rudolf1/brencher.git") container_check = DockerContainerCheck( diff --git a/tests/test_dry_run_playwright.py b/tests/test_dry_run_playwright.py index 44ccc72..85d5649 100644 --- a/tests/test_dry_run_playwright.py +++ b/tests/test_dry_run_playwright.py @@ -38,7 +38,7 @@ class TestDryRunPlaywright: def test_dry_run_prevents_deploy_until_disabled(self, eventually: EventuallyFn) -> None: # Start app with nginx_local1 with main branch pre-selected and dry mode on. env = nginx.test_local1 - env.state.set_branches([("test/main", "HEAD")]) + env.state.set_branches([(nginx.CURRENT_BRANCH, nginx.CURRENT_COMMIT)]) env.state.set_dry(True) app = App({env.id: env}) server_thread = threading.Thread(target=lambda: app.runWeb(APP_PORT), daemon=True) @@ -69,7 +69,6 @@ class TestDryRunPlaywright: page.verify_dry_run_on() page.set_dry_run_off() page.verify_dry_run_off() - page.click_refresh() # TODO Remove it # Wait for pipeline to re-run and actually deploy the container eventually( @@ -77,11 +76,16 @@ class TestDryRunPlaywright: p for p in s[env.id]["pipeline"] if p["name"] =="SharedStateHolderInMemory" )["status"]['dry'], False, "Pipeline step status is not 'running'")), ) - # Wait for pipeline to re-run and actually deploy the container + + # Wait for the real container to be created and started. eventually( - lambda: check_state(APP_URL, lambda s: assert_equal({p["name"] for p in s[env.id]["pipeline"] if bool(p['is_running'])}, set(), "Pipeline still running")), - timeout=20, - interval=1.0, + lambda: assert_equal( + {container.status for container in docker_client.containers.list(filters={"name": CONTAINER_NAME}, all=True)}, + {"running"}, + "Container should exist and be running after deploy", + ), + timeout=180, + interval=5.0, ) # page.verify_pipeline_step_status("DockerContainerDeploy", "running") logger.info("Container deployed and running after dry run disabled") @@ -92,4 +96,6 @@ class TestDryRunPlaywright: assert containers[0].status == "running" finally: app.stop() - server_thread.join(timeout=10) + server_thread.join(timeout=30) + if server_thread.is_alive(): + logger.warning("App server thread did not stop within 30 seconds")