Run a command in production (rake)

Hi there, newcomer from Heroku here — I need to run a command in my production environment (in this instance rake db:seed but other times I need a console i.e. rails c). On Heroku I would do heroku run rake db:seed, how would I do this on Railway?
6 Replies
Percy
Percy14mo ago
Project ID: 8f20bec2-837e-46f0-8721-83eb63749406
richard_21848
richard_2184814mo ago
8f20bec2-837e-46f0-8721-83eb63749406
Brody
Brody14mo ago
railway run rake db:seed most likely https://docs.railway.app/develop/cli
MantisInABox
MantisInABox14mo ago
Make sure you do - railway link select the project - railway service select the actual service - railway shell to inject your env variables - railway run rake db:seed to seed your db
Brody
Brody14mo ago
going the extra mile
richard_21848
richard_2184814mo ago
ok rad, this was slightly more complicated because my app runs in a container locally (and doesn't work outside it), in case it's any use to others I created a new compose service:
railway:
entrypoint: bin/railway_entrypoint
env_file: .railway.env
tty: true
volumes:
- .:/rails
railway:
entrypoint: bin/railway_entrypoint
env_file: .railway.env
tty: true
volumes:
- .:/rails
with bin/railway_entrypoint:
#!/bin/bash -e

bash <(curl -fsSL cli.new) -b ./bin -y > /dev/null
bin/railway $@
#!/bin/bash -e

bash <(curl -fsSL cli.new) -b ./bin -y > /dev/null
bin/railway $@
and added .railway.env with a RAILWAY_TOKEN in . Then it's docker compose run --rm railway run rake db:seed Thanks for confirming this is the recommended way!
Want results from more Discord servers?
Add your server