Deploying to Railway

Create a project Dockerfile
The first step is to create a Dockerfile for your project. If you're using a
monorepo, place
the Dockerfile in apps/indexers.
FROM quay.io/apibara/sink-postgres:0.7.0-x86_64
WORKDIR /app
COPY ./src/* /app
ENTRYPOINT ["/nix/store/rh1g8pb7wfnyr527jfmkkc5lm3sa1f0l-apibara-sink-postgres-0.7.0/bin/apibara-sink-postgres"]Notice that the base image is build from scratch (not an OS like Ubuntu), so the binary is in a location that depends on the build. For this reason we stick to a specific version and architecture.
When updating the image you also need to update the Docker ENTRYPOINT.
First pull the new version of the image.
docker image pull quay.io/apibara/sink-postgres:0.7.0-x86_642352c28bb4a7: Download complete
979824b603fa: Download complete
quay.io/apibara/sink-postgres:0.7.0-x86_64
Then get the entrypoint path by inspecting the image.
docker image inspect quay.io/apibara/sink-postgres:0.7.0-x86_64 | jq '.[].Config.Entrypoint'[
  "/nix/store/rh1g8pb7wfnyr527jfmkkc5lm3sa1f0l-apibara-sink-postgres-0.7.0/bin/apibara-sink-postgres"
]
Save and push to GitHub.
Create a new Railway service
From the Railway dashboard, create a new service deployment and connect your GitHub repository.
- Change "root directory" to the folder containing your Dockerfile, e.g./apps/indexers.
- Builder should automatically switch to "Dockerfile". If not, just wait a few seconds until it does.
- Change the "custom start command". Since this option changes the Docker's entrypoint, you will need to pass the full path to the apibara-sink-*executable. For example:/nix/store/rh1g8pb7wfnyr527jfmkkc5lm3sa1f0l-apibara-sink-postgres-0.7.0/bin/apibara-sink-postgres run /app/my-indexer.ts
- Change "restart policy" to "Always".
- Set the AUTH_TOKENenvironment variable to your DNA token.
- Set any other relevant environment variable needed by your indexer.
- For Postgres: POSTGRES_CONNECTION_STRING=${{Postgres.DATABASE_URL}}
- For Mongo: MONGO_CONNECTION_STRING=${{MongoDB.MONGO_URL}}
 
- For Postgres: 
- Remember to whitelist environment variables used in your indexer with the
--allow-env-from-envoption or theALLOW_ENV_FROM_ENVenvironment variable. See the environment variables page for more information.
- Once deployed, you should see the indexer starting and running.
Persisting state between restarts
The easiest way to persist state between restarts on Railway is by using Redis.
- Deploy a new Redis instance on Railway, and wait for it to become ready.
- Update the following indexer's environment variables:
- Set PERSIST_TO_REDISto a reference to Redis' url:${{Redis.REDIS_URL}}.
- Set SINK_IDto a unique id for this indexer, e.g.my-indexer.
 
- Set 
After redeploying, you will notice that the indexer will store its state (like latest indexed block) in the provided Redis instance.