Skip to content

Commit ec09c17

Browse files
committed
feat: bake build info into image
The old way of reading the last commit directly using Git was not working anymore with the Docker image.
1 parent 6959d8a commit ec09c17

6 files changed

Lines changed: 35 additions & 59 deletions

File tree

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM node:24 AS build
22

3+
ARG COMMIT_HASH
4+
ARG BUILD_TIME
5+
36
RUN mkdir /zeppelin
47
RUN chown node:node /zeppelin
58

@@ -34,6 +37,9 @@ RUN pnpm run build
3437
WORKDIR /zeppelin
3538
RUN CI=true pnpm install --prod
3639

40+
# Add version info
41+
RUN echo "${COMMIT_HASH}" > /zeppelin/.commit-hash
42+
RUN echo "${BUILD_TIME}" > /zeppelin/.build-time
3743

3844
# --- Main image ---
3945

backend/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"humanize-duration": "^3.15.0",
4646
"js-yaml": "^4.1.0",
4747
"knub-command-manager": "^9.1.0",
48-
"last-commit-log": "^2.1.0",
4948
"lodash-es": "^4.17.21",
5049
"moment-timezone": "^0.5.21",
5150
"multer": "^2.0.2",

backend/src/plugins/Utility/commands/AboutCmd.ts

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import { APIEmbed, GuildChannel } from "discord.js";
2-
import LCL from "last-commit-log";
32
import { shuffle } from "lodash-es";
43
import moment from "moment-timezone";
5-
import { humanizeDuration } from "../../../humanizeDuration.js";
4+
import { accessSync, readFileSync } from "node:fs";
65
import { rootDir } from "../../../paths.js";
7-
import { getCurrentUptime } from "../../../uptime.js";
6+
import { getBotStartTime } from "../../../uptime.js";
87
import { resolveMember, sorter } from "../../../utils.js";
98
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin.js";
109
import { utilityCmd } from "../types.js";
1110

11+
let commitHash: string | null = null;
12+
try {
13+
accessSync(`${rootDir}/.commit-hash`);
14+
commitHash = readFileSync(`${rootDir}/.commit-hash`, "utf-8").trim();
15+
} catch {}
16+
17+
let buildTime: string | null = null;
18+
try {
19+
accessSync(`${rootDir}/.build-time`);
20+
buildTime = readFileSync(`${rootDir}/.build-time`, "utf-8").trim();
21+
} catch {}
22+
1223
export const AboutCmd = utilityCmd({
1324
trigger: "about",
1425
description: "Show information about Zeppelin's status on the server",
@@ -17,39 +28,14 @@ export const AboutCmd = utilityCmd({
1728
async run({ message: msg, pluginData }) {
1829
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
1930

20-
const uptime = getCurrentUptime();
21-
const prettyUptime = humanizeDuration(uptime, { largest: 2, round: true });
22-
23-
let lastCommit;
24-
25-
try {
26-
const lcl = new LCL(rootDir);
27-
lastCommit = await lcl.getLastCommit();
28-
} catch {} // eslint-disable-line no-empty
29-
30-
let lastUpdate;
31-
let version;
32-
33-
if (lastCommit) {
34-
lastUpdate = timeAndDate
35-
.inGuildTz(moment.utc(lastCommit.committer.date, "X"))
36-
.format(pluginData.getPlugin(TimeAndDatePlugin).getDateFormat("pretty_datetime"));
37-
version = lastCommit.shortHash;
38-
} else {
39-
lastUpdate = "?";
40-
version = "?";
41-
}
42-
43-
const lastReload = humanizeDuration(Date.now() - pluginData.state.lastReload, {
44-
largest: 2,
45-
round: true,
46-
});
31+
const botStartTime = getBotStartTime();
32+
const buildTimeMoment = buildTime ? moment.utc(buildTime, "YYYY-MM-DDTHH:mm:ss[Z]") : null;
4733

4834
const basicInfoRows = [
49-
["Uptime", prettyUptime],
50-
["Last config reload", `${lastReload} ago`],
51-
["Last bot update", lastUpdate],
52-
["Version", version],
35+
["Bot start time", `<t:${Math.floor(botStartTime / 1000)}:R>`],
36+
["Last config reload", `<t:${Math.floor(pluginData.state.lastReload / 1000)}:R>`],
37+
["Last bot update", buildTimeMoment ? `<t:${Math.floor(buildTimeMoment.unix())}:f>` : "Unknown"],
38+
["Version", commitHash?.slice(0, 7) || "Unknown"],
5339
["API latency", `${pluginData.client.ws.ping}ms`],
5440
["Server timezone", timeAndDate.getGuildTz()],
5541
];

backend/src/uptime.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ export function startUptimeCounter() {
77
export function getCurrentUptime() {
88
return Date.now() - start;
99
}
10+
11+
export function getBotStartTime() {
12+
return start;
13+
}

build-image.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
docker build -t dragory/zeppelin .
1+
docker build \
2+
-t dragory/zeppelin \
3+
--build-arg COMMIT_HASH=$(git rev-parse HEAD) \
4+
--build-arg BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
5+
.

pnpm-lock.yaml

Lines changed: 0 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)