Pre-deploy command from Railway config file

scarabcoder
PRO

7 months 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

7 months ago

yep! its part of the json schema already


scarabcoder
PRO

7 months ago

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


7 months ago

you can - command 1 && command 2


scarabcoder
PRO

7 months ago

Alright


pauldps
HOBBY

7 months 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

7 months ago

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


pauldps
HOBBY

7 months 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

7 months 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

7 months ago

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


7 months ago

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

since && is shell specific syntax


pauldps
HOBBY

7 months ago

ah I see, lemme try that


pauldps
HOBBY

7 months ago

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


pauldps
HOBBY

7 months ago

this will probably fail, right?

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

pauldps
HOBBY

7 months ago

can I escape the quotes in toml file?


pauldps
HOBBY

7 months ago

Went with:

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

Which worked 🙂


7 months ago

pog


7 months ago

backslashes escape quotes btw


7 months ago

!s


Status changed to Solved brody 7 months ago


Pre-deploy command from Railway config file - Railway Help Station