Skip to content

Commit f9d99fc

Browse files
committed
cabotage support
1 parent 8a66b2f commit f9d99fc

File tree

7 files changed

+47
-13
lines changed

7 files changed

+47
-13
lines changed

β€ŽDockerfileβ€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.11-slim
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
4+
5+
WORKDIR /app
6+
COPY requirements.txt .
7+
RUN pip install --no-cache-dir -r requirements.txt
8+
COPY miss_islington miss_islington
9+
10+
CMD ["python", "-m", "miss_islington"]

β€Žmiss_islington/__main__.pyβ€Ž

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,19 @@ async def repo_installation_added(event, gh, *args, **kwargs):
7171
print(f"App installed by {event.data['installation']['account']['login']}, installation_id: {event.data['installation']['id']}")
7272

7373

74-
sentry_sdk.init(dsn=os.environ.get("SENTRY_DSN"), integrations=[AioHttpIntegration()])
75-
app = web.Application()
76-
app.router.add_post("/", main)
77-
port = os.environ.get("PORT")
78-
if port is not None:
79-
port = int(port)
80-
81-
web.run_app(app, port=port)
74+
async def health_check(request):
75+
"""Health check endpoint for container orchestration."""
76+
return web.Response(status=200, text="OK")
77+
78+
79+
if __name__ == "__main__": # pragma: no cover
80+
sentry_sdk.init(dsn=os.environ.get("SENTRY_DSN"), integrations=[AioHttpIntegration()])
81+
app = web.Application()
82+
app.router.add_post("/", main)
83+
app.router.add_get("/health", health_check)
84+
85+
if os.path.isdir("/var/run/cabotage"):
86+
web.run_app(app, path="/var/run/cabotage/cabotage.sock")
87+
else:
88+
port = os.environ.get("PORT")
89+
web.run_app(app, port=int(port) if port else None)

β€Žmiss_islington/tasks.pyβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
app = celery.Celery("backport_cpython")
2020

2121
app.conf.update(
22-
broker_url=os.environ["HEROKU_REDIS_MAROON_URL"],
23-
result_backend=os.environ["HEROKU_REDIS_MAROON_URL"],
22+
broker_url=os.environ.get("REDIS_URL", ""),
23+
result_backend=os.environ.get("REDIS_URL", ""),
2424
broker_connection_retry_on_startup=True,
2525
broker_use_ssl={"ssl_cert_reqs": ssl.CERT_NONE},
2626
redis_backend_use_ssl={"ssl_cert_reqs": ssl.CERT_NONE},

β€Žruntime.txtβ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.

β€Žtests/test___main__.pyβ€Ž

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os
2+
3+
os.environ.setdefault("REDIS_URL", "redis://localhost")
4+
5+
from aiohttp import web
6+
7+
from miss_islington import __main__ as main
8+
9+
10+
# simple heallth check to amke sure /health works
11+
async def test_health_check(aiohttp_client):
12+
app = web.Application()
13+
app.router.add_get("/health", main.health_check)
14+
client = await aiohttp_client(app)
15+
response = await client.get("/health")
16+
assert response.status == 200
17+
assert await response.text() == "OK"

β€Žtests/test_backport_pr.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import redis
88
import kombu
99

10-
os.environ["HEROKU_REDIS_MAROON_URL"] = "someurl"
10+
os.environ.setdefault("REDIS_URL", "redis://localhost")
1111

1212
from miss_islington import backport_pr
1313

β€Žtests/test_delete_branch.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from gidgethub import sansio
55
import pytest
66

7-
os.environ.setdefault("HEROKU_REDIS_MAROON_URL", "someurl")
7+
os.environ.setdefault("REDIS_URL", "redis://localhost")
88

99
from miss_islington import delete_branch, tasks
1010

0 commit comments

Comments
Β (0)