I cant make RAILWAY_GIT_COMMIT_SHA reach my app
ricardovf
PROOP

a year 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.

$20 Bounty

11 Replies

a year ago

A buddy suggested using:

`${CI_COMMIT_SHA:0:7}`

unsure if this is right would you mind testing?


a year ago

Or another method would be. In the "variables" section of your project set

NEXT_PUBLIC_GIT_COMMIT_SHA = ${RAILWAY_GIT_COMMIT_SHA}


a year 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 set NEXT\_PUBLIC\_GIT\_COMMIT\_SHA = ${RAILWAY\_GIT\_COMMIT\_SHA}

ricardovf
PROOP

a year 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.

ricardovf
PROOP

a year ago

Tried this too


noahd

A buddy suggested using: \`${CI\_COMMIT\_SHA:0:7}\` unsure if this is right would you mind testing?

ricardovf
PROOP

a year ago

Is CI_COMMIT_SHA an exported variable from railway?


a year 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?

a year ago

CI_COMMIT_SHA was something a buddy of mine setup for a shared workspace project lol. Not a railway exported variable no


smolpaw
HOBBY

a year ago

...

should've seen the attached images first


smolpaw
HOBBY

a year 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


ricardovf
PROOP

a year ago

I will try with docker as soon as i can i come back here to say if it worked, thanks!


Welcome!

Sign in to your Railway account to join the conversation.

Loading...