Skip to main content
Skip table of contents

Deploying Using the SubQuery CLI

Most customers use the @subql/cli to just initialise, build, and run their projects locally, however the CLI can be used deploy their projects too!

You can use the CLI to do the following:

  • Create a new project on the OnFinality Indexing Service

  • Deploy a new version of your SubQuery project to the OnFinality Indexing Service

  • Promote a staging deployment to the production slot in the OnFinality Indexing Service

  • and more! Type subql help to read the docs

The commands and parameters shown here may change, we suggest reviewing the current command and parameter list by using the --help command with your CLI

Installation

Install SubQuery CLI globally on your terminal by using Yarn (yarn global add @subql/cli) or NPM (npm install -g @subql/cli) We recommend NPM.

You can then run help to see available commands and usage provided by CLI subql help

Prepare your SUBQL_ACCESS_TOKEN

  • Step 1: Go to OnFinality Indexing Service and log in.

  • Step 2: Click on your profile at the top right of the navigation menu, then click on Refresh Token.

  • Step 3: Copy the generated token.

  • Step 4: To use this token, add SUBQL_ACCESS_TOKEN in your environment variables. EXPORT SUBQL_ACCESS_TOKEN=<token> (Windows) or export SUBQL_ACCESS_TOKEN=<token> (Mac/Linux)

Usage in GitHub Actions

With the introduction of the deployment feature for the CLI, we've added a Default Action Workflow to the starter project in GitHub that will allow you to publish and deploy your changes automatically:

Please review the documentation on how to deploy a new version of your project using GitHub actions.

Create a New Project

The CLI allows you to create a brand new project in the OnFinality Indexing Service. It supports both interactive and non-interactive methods.

BASH
// Creating a project using the interactive method of the CLI
$ subql project:create-project

// OR using non-interactive method of the CLI, it will prompt you if the required fields are missing
$ subql project:create-project
    --apiVersion=apiVersion    [default: 2] Enter api version
    --description=description  Enter description
    --gitRepo=gitRepo          Enter git repository
    --logoURL=logoURL          Enter logo URL
    --org=org                  Enter organization name
    --projectName=projectName  Enter project name
    --subtitle=subtitle        Enter subtitle

Deploy a New Version of your Project

Using the CLI, you can deploy a new version of your SubQuery project to the OnFinality Indexing Service. It supports both interactive and non-interactive methods. You may want to run this command after you delete the target deployment slot (staging or primary).

We suggest using the --useDefaults command for best results.

BASH
// Deploy using the interactive method of the CLI
$ subql deployment:deploy

// OR using non-interactive method of the CLI, it will prompt you if the required fields are missing
$ subql deployment:deploy
  -d, --useDefaults                Use default values for indexerVersion, queryVersion, dictionary, endpoint
  --dict=dict                      Enter dictionary
  --endpoint=endpoint              Enter endpoint
  --indexerVersion=indexerVersion  Enter indexer-version
  --ipfsCID=ipfsCID                Enter IPFS CID
  --org=org                        Enter organization name
  --projectName=projectName        Enter project name
  --queryVersion=queryVersion      Enter query-version
  --type=(stage|primary)           [default: primary]

Promote a Staging Deployment to Production Slot

This command will promote a staging deployment to the production slot in the OnFinality Indexing Service.

BASH
// Promote using the interactive method of the CLI
subql deployment:promote

// OR using non-interactive method of the CLI, it will prompt you if the required fields are missing
subql deployment:promote
  --deploymentID=deploymentID  Enter deployment ID
  --org=org                    Enter organization name
  --project_name=project_name  Enter project name

Delete an Existing Deployment of your Project

This is a command commonly run to clear out data from an existing deployment slot (e.g. the staging slot) before you do a fresh deployment.

BASH
// Delete slot using the interactive method of the CLI
subql deployment:delete

// OR using non-interactive method of the CLI, it will prompt you if the required fields are missing
subql deployment:delete
  --deploymentID=deploymentID  Enter deployment ID
  --org=org                    Enter organization name
  --project_name=project_name  Enter project name

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.