How do I start the Hasura cluster locally?
Context
The local Hasura cluster runs two services, a postgres database and the hasura server. Every time the cluster is started, it starts from zero, brand new. Part of the initialization is to run migrations, which will populate the empty hasura database with the structure it needs as well as the hasura metadata and seed data.
Make sure you have installed the Hasura CLI. Here are instructions from the Hasura docs.
Hasura-Cluster Helper Tool
There is a tool we've created that has a few shortcuts available, it's called hasura-cluster. This just a bash script that runs a few docker-compose commands.
Syntax:
[1] Set your environment:
[2] Start the cluster:
[3] Start the hasura console (press Ctrl+C to stop)
[4] Stop the cluster (whenever you are finished):
Hasura-Cluster Reference
run_migration
: Runs all 3 hasura migrations: database, metadata, seed data.start_only
: Starts the cluster and does NOT run migrations.start
: Starts the cluster and runs all migrations.restart
: Stops the running cluster, and starts cluster, then applies all migrationsstop
: Stops the cluster, removes any volumes left out.prune
: Deletes any volumes left out by the cluster.follow
: Shows the logs for the running cluster.status
: Displays the current status of the clustersetenv
: Changes the current environment.console
: It's an alias forhasura console
Hasura-Cluster SetEnv:
What setenv
really does is to copy an existing file from the ./config folder into the current folder and renames it into config.yaml
. The hasura
command (CLI) will read its settings from config.yaml
.
For example, there should only be a file in the ./config folder called hasura.local.yaml
which contains the connection information for the local cluster. Notice the format hasura.<environment>.yaml
. If for example, you need to connect the Hasura Staging cluster, you would need to create a new file called hasura.staging.yaml
, provide all the info, then run $ hasura-cluster setenv staging
and hasura console
.
AWS Cognito Integration (or lack thereof)
At the moment, the local environment does not really need to integrate with AWS cognito. You can still pass an admin key or a JWT token to the local instance, but hasura will just ignore them.
Docker
The local hasura cluster runs on top of docker. The docker-compose file looks like this, where we define a postgres 12 database saving data to a volume and port 5432, and a hasura node running on port 8080:
The above file is incomplete, you can see the full file here: <file url>
Hasura Cluster Tool
I've created a script that provides docker shortcuts to start the cluster, stop the cluster, clean up, etc.
Docker-compose
You can still run docker compose, this command will start the cluster without migrations:
The command above runs the cluster in detached mode, the --volume
flag means it will remove any volumes running, in our case it will remove the postgresql volume, and with it any stored data. After running this command, you can now manually run the hasura migrations.
Last updated