3.14ki
3.14ki
RRailway
Created by 3.14ki on 7/14/2023 in #✋|help
Executing "git rev-parse --short HEAD" crashes deployment
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
> [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.
19 replies