#Executing "git rev-parse --short HEAD" crashes deployment

18 messages · Page 1 of 1 (latest)

mental forum
#

Hey there,

I'm creating another instance of my project, currently it's running on AWS and I intend to create the Railway one too.
In my NestJS project I have a line that "Health Check" status route that returns some data and alongside it a git hash.
revision: child_process.execSync('git rev-parse --short HEAD').toString().trim()

I'm using Docker as my builder, and in it I have a RUN apk add --no-cache git

Deploy Logs are saying next:

> [email protected] start:prod
> node dist/main.js
fatal: not a git repository (or any of the parent directories): .git
node:child_process:960
throw err;
^
Error: Command failed: git rev-parse --short HEAD

fatal: not a git repository (or any of the parent directories): .git

at checkExecSyncError (node:child_process:885:11)
at Object.execSync (node:child_process:957:15)
at Object.<anonymous> (/usr/src/app/dist/app.module.js:121:63)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:110:18) {
status: 128,
signal: null,
output: [
null,
Buffer(0) [Uint8Array] [],
Buffer(69) [Uint8Array] [...],
pid: 24,
stdout: Buffer(0) [Uint8Array] [],
stderr: Buffer(69) [Uint8Array] [...]

}

Node.js v18.16.1

I saw that Railway provides the env RAILWAY_GIT_COMMIT_SHA but , I'm not sure if I can refactor it and make it work on AWS too. I fetch the shortened SHA inside a config object of an imported module.

tough knollBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

agile eagleBOT
#

Project ID: f62c745f-4126-4c82-9c45-02417891d65e

mental forum
#

project-id: f62c745f-4126-4c82-9c45-02417891d65e

broken wing
#

just slap in some logic like if railway return RAILWAY_GIT_COMMIT_SHA else return git hash

mental forum
#

You're right!

What about


process.env.RAILWAY_STATIC_URL ? RAILWAY_GIT_COMMIT_SHA?.substring(0,7).trim() : child_process.execSync('git rev-parse --short HEAD').toString().trim()


broken wing
#

looks good to me

#

but this raises the question, do you really need to be returning the git hash?

mental forum
#

In a health check route?

broken wing
#

yeah

mental forum
#

🤷‍♂️
That's the way it worked for a loooong time

broken wing
#

whats the purpose of returning the git hash?

mental forum
#

Checking if it deployed the right commit

broken wing
#

fair enough

mental forum
#

I'm trying out the logic and I hope that it will work 💪

#

@broken wing You sir, are a gentleman and a scholar! Thanks a lot!

broken wing
#

pseudo code ftw

tough knollBOT