8 months ago
Hi!
I can't make RAILWAY_GIT_COMMIT_SHA reach my next.js app. Using nixpacks. Trigger via Github connected repo.
I need this so i can use on a websocket worker connection that i need tha SHA of the commit.
The SHA is acctually shown on the build log, but i can't access it in the next.js component. Tried to pass in the build command and other forms, but no success so far.
11 Replies
8 months ago
A buddy suggested using:
`${CI_COMMIT_SHA:0:7}`
unsure if this is right would you mind testing?
8 months ago
Or another method would be. In the "variables" section of your project set
NEXT_PUBLIC_GIT_COMMIT_SHA = ${RAILWAY_GIT_COMMIT_SHA}
8 months ago
Exporting in the install likely doesn't propagate to the actual build step - try prepending NEXT_PUBLIC_GIT_COMMIT_SHA=${RAILWAY_GIT_COMMIT_SHA} to your build command pnpm build . You can add this before the actual command in package.json , or set the nixpacks build command as such.
noahd
Or another method would be. In the "variables" section of your project setNEXT_PUBLIC_GIT_COMMIT_SHA = ${RAILWAY_GIT_COMMIT_SHA}
8 months ago
I did, the value comes empty
six
Exporting in the install likely doesn't propagate to the actual build step - try prepending NEXT_PUBLIC_GIT_COMMIT_SHA=${RAILWAY_GIT_COMMIT_SHA} to your build command pnpm build . You can add this before the actual command in package.json , or set the nixpacks build command as such.
8 months ago
Tried this too
noahd
A buddy suggested using: `${CI_COMMIT_SHA:0:7}`unsure if this is right would you mind testing?
8 months ago
Is CI_COMMIT_SHA an exported variable from railway?
8 months ago
https://docs.railway.com/reference/variables
looking through the railway docks right now.
On another note, Is there a specific reason you are using nixpacks? Would you like help setting up a Dockerfile to rule out it being nixpacks fault?
ricardovf
Is CI_COMMIT_SHA an exported variable from railway?
8 months ago
CI_COMMIT_SHA was something a buddy of mine setup for a shared workspace project lol. Not a railway exported variable no
8 months ago
...
should've seen the attached images first
8 months ago
Can you try with a dockerfile deployment instead ?
Nextjs has a production ready Dockerfile : https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
You need to download this and add to the root of your project next to package.json
Next, add output to standalone in your next config file as described here: https://github.com/vercel/next.js/tree/canary/examples/with-docker#in-existing-projects
Then extend the Dockerfile by adding ARG NEXT_PUBLIC_GIT_COMMIT_SHA just before this line
# Next.js collects completely anonymous telemetry data about general usage.
Then go to your railway dashboard and in Variables add NEXT_PUBLIC_GIT_COMMIT_SHA to ${{RAILWAY_GIT_COMMIT_SHA}}
Deploy. The Dockerfile should get detected and used, if not you may need to remove the nixpacks related file
8 months ago
I will try with docker as soon as i can i come back here to say if it worked, thanks!
