diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..5e8bc033 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.11-slim + +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +COPY bedevere bedevere + +CMD ["python", "-m", "bedevere"] diff --git a/bedevere/__main__.py b/bedevere/__main__.py index 4bb678e8..aef92940 100644 --- a/bedevere/__main__.py +++ b/bedevere/__main__.py @@ -68,10 +68,18 @@ async def repo_installation_added(event, gh, *args, **kwargs): ) +async def health_check(request): + """Health check endpoint for container orchestration.""" + return web.Response(status=200, text="OK") + + if __name__ == "__main__": # pragma: no cover app = web.Application() app.router.add_post("/", main) - port = os.environ.get("PORT") - if port is not None: - port = int(port) - web.run_app(app, port=port) + app.router.add_get("/health", health_check) + + if os.path.isdir("/var/run/cabotage"): + web.run_app(app, path="/var/run/cabotage/cabotage.sock") + else: + port = os.environ.get("PORT") + web.run_app(app, port=int(port) if port else None) diff --git a/tests/test___main__.py b/tests/test___main__.py index 397d1339..e9e628fa 100644 --- a/tests/test___main__.py +++ b/tests/test___main__.py @@ -13,6 +13,15 @@ } +async def test_health_check(aiohttp_client): + app = web.Application() + app.router.add_get("/health", main.health_check) + client = await aiohttp_client(app) + response = await client.get("/health") + assert response.status == 200 + assert await response.text() == "OK" + + async def test_ping(aiohttp_client): app = web.Application() app.router.add_post("/", main.main)