Skip to content

Commit 6fa5dbd

Browse files
committed
fix: Use git command to get build SHA in health check
1 parent 1af7354 commit 6fa5dbd

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1+
const { execSync } = require('child_process');
2+
13
const HealthCheckController = {};
24

5+
function getBuildInfo() {
6+
try {
7+
// Try to get git info from the container
8+
const gitSha = execSync('git rev-parse --short HEAD 2>/dev/null || echo "unknown"', {
9+
encoding: 'utf8',
10+
}).trim();
11+
return gitSha;
12+
} catch {
13+
return process.env.BUILD_SHA || 'unknown';
14+
}
15+
}
16+
317
HealthCheckController.isAlive = (_, res) => {
4-
res
5-
.status(200)
6-
.send(`I'm Alive! Build: ${process.env.BUILD_SHA || 'unknown'} - ${new Date().toISOString()}`);
18+
const buildInfo = getBuildInfo();
19+
res.status(200).send(`I'm Alive! Build: ${buildInfo} - ${new Date().toISOString()}`);
720
};
821

922
module.exports = HealthCheckController;

0 commit comments

Comments
 (0)