Moped Documentation
  • Welcome 👋
  • User Guides
    • Getting started
    • Map a project
  • Product Management
    • User communication
    • User management
    • User analytics
    • Local testing
    • Release process
    • Patch release process
    • MUI X Pro License
    • Integrations
      • Dataset documentation
      • ArcGIS Online
      • eCapris
      • Power BI
    • Features
  • Dev Guides
    • DB Docs & Data dictionary
    • Database backup policy
    • Moped Read Replica
    • How-to's
      • How do I start the Hasura cluster locally?
      • How do I launch the Hasura Console?
      • How do I get a JWT token?
      • How to ping the GraphQL API
      • How to ping the REST API
      • How do I connect a database with Postgres GUIs?
      • How do I connect to the RDS instance?
      • How to load production data into a local instance
      • How do I update seed data?
    • Hasura
      • Hasura Roles
      • Hasura Migrations
        • Getting Started
        • Installing the Hasura CLI
        • Configuration Files
        • Hasura Migration Principles
        • The Migration file format
        • Development
        • Hasura Seed Data
        • Running the Hasura Cluster Locally (video)
        • Create a migration: Exercise 1 (video)
        • Create a migration: Exercise 2 (video)
        • Latest hasura-cluster features
    • User Management
    • Authentication
      • Authentication Architecture
      • DynamoDB & Cognito
      • Secrets Manager & Cognito
      • Hasura & Cognito
      • React & Cognito
      • Flask API & Cognito
      • Single Sign-On with CTM
    • Code organization
    • API
      • Configuration Files
      • Testing
      • User Management API
    • Maps and geospatial data
      • Access tokens and API keys
      • Map libraries
      • Map data
      • Map styles
      • Map layers and basemaps
      • React patterns
      • V1 Archive
        • Map libraries
        • Map data
        • Map custom hooks
        • Map styles
        • Map layers and basemaps
    • UI access control
    • Design system
      • Branding
      • Component styles
      • Text content
    • Activity Log
      • Architecture
      • GitHub Actions and Deployment of Updates
      • Hasura Event Logs and Truncate Cron Job
      • Authentication
  • See also
  • Get Moped support, report a bug, or request an enhancement
  • Data & Technology Services
  • Github repository
Powered by GitBook
On this page
  • Context
  • Hasura-Cluster Helper Tool
  • AWS Cognito Integration (or lack thereof)
  • Docker
  • Hasura Cluster Tool
  • Docker-compose

Was this helpful?

  1. Dev Guides
  2. How-to's

How do I start the Hasura cluster locally?

PreviousHow-to'sNextHow do I launch the Hasura Console?

Last updated 4 years ago

Was this helpful?

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

Hasura-Cluster Helper Tool

There is a tool we've created that has a few shortcuts available, it's called . This just a bash script that runs a few docker-compose commands.

Syntax:

$ ./hasura-cluster <command> <params>

[1] Set your environment:

$ ./hasura-cluster setenv local

[2] Start the cluster:

$ ./hasura-cluster start

[3] Start the hasura console (press Ctrl+C to stop)

$ ./hasura-cluster console
# - or -
$ hasura console

[4] Stop the cluster (whenever you are finished):

$ ./hasura-cluster stop

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 migrations

  • stop: 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 cluster

  • setenv: Changes the current environment.

  • console: It's an alias for hasura 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:

    moped-pgsql:
        image: postgres:12-alpine
        volumes:
            - moped-db-vol:/var/lib/postgresql/data
        expose:
            - 5432
        ports:
            - 5432:5432
        environment:
            - POSTGRES_USER=moped
            - POSTGRES_PASSWORD=moped
            - POSTGRES_DB=moped

    hasura:
        image: hasura/graphql-engine:v1.3.2
        restart: always
        depends_on:
            - moped-pgsql
        expose:
            - 8080
        ports:
            - 8080:8080
        environment:
            - HASURA_GRAPHQL_ENABLE_CONSOLE=false
            - HASURA_GRAPHQL_ENABLE_TELEMETRY=false
            - HASURA_GRAPHQL_DATABASE_URL=postgres://moped:moped@moped-pgsql:5432/moped

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.

$ ./hasura-cluster start        # Start cluster with migrations
$ ./hasura-cluster start_only   # Start without migrations
$ ./hasura-cluster stop         # Stops cluster, removes database data (data).
$ ./hasura-cluster prune        # Removes any database volumes (data)

Docker-compose

You can still run docker compose, this command will start the cluster without migrations:

$ docker-compose -f docker-compose.yaml up -d --volume

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.

Here are instructions from the Hasura docs
hasura-cluster