Skip to content

Commit 34593d2

Browse files
authored
Merge pull request #169 from practical-python-org/feature/hash-in-healthcheck
2 parents 0f591f4 + c4fe3b8 commit 34593d2

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/Dockerfile-bot

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@ COPY src/bot/pyproject.toml src/bot/pyproject.toml
1616
RUN --mount=type=cache,target=/root/.cache/uv \
1717
uv sync --frozen --no-install-project --no-dev --package eos-bot
1818

19+
RUN apt-get update \
20+
&& apt-get install -y --no-install-recommends git \
21+
&& rm -rf /var/lib/apt/lists/*
22+
1923
COPY src/bot ./src/bot
2024

2125
RUN --mount=type=cache,target=/root/.cache/uv \
2226
uv sync --frozen --no-dev --package eos-bot
2327

28+
RUN --mount=source=../.git,target=.git,type=bind \
29+
git rev-parse --short HEAD > /commit_hash.txt
30+
2431
RUN useradd -r -M botuser && chown -R botuser:botuser /bot
2532
USER botuser
2633

27-
CMD ["uv", "run", "--frozen", "--no-cache", "--no-dev", "--package", "eos-bot", "python", "src/bot/main.py"]
34+
ENTRYPOINT ["./src/bot/botrunner.sh"]

src/bot/botrunner.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
export GIT_HASH=$(cat /commit_hash.txt)
4+
uv run --frozen --no-cache --no-dev --package eos-bot python src/bot/main.py

src/bot/cogs/admin/healthchecks.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import datetime
22
import logging
3+
import os
34

45
import discord
56
from discord.ext import commands
67

78
logger = logging.getLogger(__name__)
89

910

10-
def embed_hc(api, db, uptime):
11+
def embed_hc(api, db, uptime, git_hash):
1112
"""
1213
Embedding for avatar change alerts.
1314
"""
@@ -25,6 +26,7 @@ def embed_hc(api, db, uptime):
2526
embed.add_field(name=api.get("message"), value=api.get("status_code"), inline=False)
2627
embed.add_field(name=db.get("message"), value=db.get("status_code"), inline=False)
2728
embed.add_field(name="Uptime:", value=uptime, inline=False)
29+
embed.add_field(name="Commit Hash:", value=git_hash, inline=False)
2830
return embed
2931

3032

@@ -77,7 +79,10 @@ async def hc(self, ctx: commands.Context) -> None:
7779

7880
uptime = self.get_uptime(self.bot.boot_time)
7981

80-
await ctx.reply(embed=embed_hc(api_info, db_info, uptime))
82+
# Get commit hash from .env file
83+
git_hash = os.getenv("GIT_HASH", default="Spam, Spam, Spam, Egg, and Spam!")
84+
85+
await ctx.reply(embed=embed_hc(api_info, db_info, uptime, git_hash))
8186

8287
def get_uptime(self, boot_time: datetime.datetime) -> str:
8388
"""Get uptime from bot"""

0 commit comments

Comments
 (0)