Skip to content

Commit e87a151

Browse files
committed
Implement health check in Docker
1 parent ad79b6c commit e87a151

File tree

7 files changed

+32
-3
lines changed

7 files changed

+32
-3
lines changed

Diff for: Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ COPY bot/ bot/
2828

2929
# NOTE: this must be a list, otherwise signals (eg. SIGINT) are not forwarded to the bot
3030
CMD ["/bin/bash", "-c", "python -m ghutils.app"]
31+
32+
HEALTHCHECK \
33+
--interval=1m \
34+
--timeout=30s \
35+
--start-period=2m \
36+
--start-interval=15s \
37+
--retries=3 \
38+
CMD ["python", "-m", "ghutils.health_check"]

Diff for: bot/src/ghutils/health_check.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
import sys
3+
import traceback
4+
5+
import httpx
6+
7+
8+
def main():
9+
if (url := os.getenv("HEALTH_CHECK_URL")) is None:
10+
raise ValueError("Environment variable not set: HEALTH_CHECK_URL")
11+
httpx.get(url).raise_for_status()
12+
13+
14+
if __name__ == "__main__":
15+
try:
16+
main()
17+
except Exception:
18+
traceback.print_exc()
19+
sys.exit(1)

Diff for: codedeploy/compose.override.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ services:
1010
GITHUB__CLIENT_ID: Iv23li0slKG6vf9kOBef
1111
GITHUB__REDIRECT_URI: https://ghutils.object.gay/api/login
1212
GITHUB__DEFAULT_INSTALLATION_ID: '54847303'
13+
HEALTH_CHECK_URL: https://ghutils.object.gay/api/health
1314

1415
postgres:
1516
restart: unless-stopped

Diff for: compose.override.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ services:
55
environment:
66
ENVIRONMENT: dev
77
API_ROOT_PATH:
8+
HEALTH_CHECK_URL: http://localhost:7100/health
89
develop:
910
watch:
1011
- action: sync

Diff for: infrastructure/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies = [
1010
"ghutils-common",
1111
"aws-cdk-lib>=2.158.0",
1212
"aws-cdk-github-oidc>=2.4.1",
13-
"object-ci[aws-cdk] @ git+https://github.com/object-Object/ci",
13+
"object-ci[aws-cdk] @ git+https://github.com/object-Object/ci@v0",
1414
]
1515

1616
[tool.rye]

Diff for: requirements-dev.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ multidict==6.0.5
127127
# via yarl
128128
nodeenv==1.9.1
129129
# via pre-commit
130-
object-ci @ git+https://github.com/object-Object/ci@681c2a77d4b906df0273e52ff7fe390be4d7b54d
130+
object-ci @ git+https://github.com/object-Object/ci@d49aad2be03e0c6995be20d505d32aa54a6b7f89
131131
# via ghutils-infrastructure
132132
orjson==3.10.5
133133
# via fastapi

Diff for: requirements.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ mdurl==0.1.2
117117
multidict==6.0.5
118118
# via aiohttp
119119
# via yarl
120-
object-ci @ git+https://github.com/object-Object/ci@681c2a77d4b906df0273e52ff7fe390be4d7b54d
120+
object-ci @ git+https://github.com/object-Object/ci@d49aad2be03e0c6995be20d505d32aa54a6b7f89
121121
# via ghutils-infrastructure
122122
orjson==3.10.5
123123
# via fastapi

0 commit comments

Comments
 (0)