Deploy KeystoneJS on Railway

Oct 29, 2023

To deploy a Keystone project, you will need to:

  1. Create a Railway account. This is where the production server will run.
  2. Create a new Postgresql database in Railway by selecting New Project → Database → Provision PostgreSQL.
  3. When the database is up and running, click on the project and open the Variables tab. You will see a list of Service (Environment) variables. Click on the DATABASE_URL variable and copy its URL for later use.
  4. Go back to your Railway dashboard and create another new Project. New Project → Github repo.
  5. Follow the steps to authenticate the Railway app for your GitHub repo. You'll need to go through the authentication process on Railway using your GitHub account. This step allows Railway to obtain permission to access your GitHub repositories. This access enables Railway to pull your code from your github repo.
  6. Once this is done, return to Railway and select your Keystone Github repo from the list. Railway will try to deploy your repo using its default NodeJS settings, but you will need to make a few changes to the defaults for the deployment to be successful.
  7. Click the project in the dashboard. Under variables, add your environment variables for the DATABASE_URL (Saved in step 3 above). Also add a variable for the PROVIDER: 'postgresql'
  8. Open the Settings tab.
    1. Under networking, select "Generate custome domain" or link an existing domain if you have one for your app.
    2. Under Build, add yarn build for your build command.
    3. Under Deploy, add yarn start as your start command.
    4. Set your preferred restart policy.
  9. As you save your settings, the app will get redeployed.
  10. When the Deployment succeeds, go to your custom-domain/admin to see the Keystone user login/setup page.