Pre-deploy command from Railway config file
scarabcoder
PROOP

a year ago

Love the new pre-deploy command feature!

Question, is it possible to configure this from the railway config file, rather than through the UI?

Solved

0 Replies

brody
EMPLOYEE

a year ago

yep! its part of the json schema already


scarabcoder
PROOP

a year ago

@Brody Can I specify multiple commands? The schema seems to indicate that it's an array, but with a max of 1?


brody
EMPLOYEE

a year ago

you can - command 1 && command 2


scarabcoder
PROOP

a year ago

Alright


pauldps
HOBBY

a year ago

I don't have a startCommand in my railway.toml because I use a Dockerfile. Can I still use a pre-deploy command?


pauldps
HOBBY

a year ago

oh, I see it in the schema file. preDeployCommand
always forget I can just see the entire schema directly


pauldps
HOBBY

a year ago

I just tested this. Multiple commands in preDeployCommand don't seem to work:

startCommand = "./server"
preDeployCommand = "bun db:migrate && bun db:seed"

Only the first command runs.

Logs:

Starting Container
$ bun config/scripts/migrate.ts
Using database: libsql://...
Schema version: 6
[Migrate] Running up [6->all] migrations...
[Migrate] Done.
Stopping Container

Starting Container
Using database: libsql://...
Server is running on http://localhost:8080/graphql

When running bun db:migrate && bun db:seed locally, this is how the logs look like:

$ bun config/scripts/migrate.ts
Using database: file:/...
Schema version: 6
[Migrate] Running up [6->all] migrations...
[Migrate] Done.
$ bun config/seeds.ts
Using database: file:/...
Schema version: 6
[Seeds] Seeding users...
[Seeds] Done.

pauldps
HOBBY

a year ago

I tried moving the commands to a shell script (the file has +x permission):

preDeployCommand = "./config/migrate.sh"

But it failed with:

Starting Container
exec container process `/app/backend/api/./config/migrate.sh`: Exec format error
Stopping Container

brody
EMPLOYEE

a year ago

you are using a dockerfile, you need to wrap the pre-deploy command in a shell


brody
EMPLOYEE

a year ago

/bin/sh -c "bun db:migrate && bun db:seed"

since && is shell specific syntax


pauldps
HOBBY

a year ago

ah I see, lemme try that


pauldps
HOBBY

a year ago

with the double-quotes, how do I actually put that in the toml file? 👀


pauldps
HOBBY

a year ago

this will probably fail, right?

preDeployCommand = "/bin/sh -c "bun db:migrate && bun db:seed""

pauldps
HOBBY

a year ago

can I escape the quotes in toml file?


pauldps
HOBBY

a year ago

Went with:

preDeployCommand = "/bin/sh ./config/migrate.sh"

Which worked 🙂


brody
EMPLOYEE

a year ago

pog


brody
EMPLOYEE

a year ago

backslashes escape quotes btw


brody
EMPLOYEE

a year ago

!s


Status changed to Solved brody 11 months ago


Loading...