Hasura GraphQL API Engine #
In this tutorial, you will deploy your own Hasura GraphQL Engine. We will explain all the necessary SetOps commands that we need to deploy the application. You can find a summary of all commands at the end.
Prepare your SetOps Environment #
💡 At first, you need to choose a name forproject
,stage
, andapp
. You can edit them in the form in the top right corner.
-
Let’s start by creating a Project.
setops project:create <PROJECT>
-
Create a Stage for your project.
setops -p <PROJECT> stage:create <STAGE>
project
andstage
must only contain lowercase lettersa-z
and numbers0-9
and start with a lowercase letter. The length ofproject
has to be between 3 and 20 characters and the length ofstage
between 3 and 12. It also has to start with a lowercase letter. A valid example isparkscheibe
&staging
. -
Create the App web.
setops -p <PROJECT> -s <STAGE> app:create <APPNAME>
The name for apps must only contain lowercase letters
a-z
and numbers0-9
and dashes-
. The name must be between 3 and 16 characters long and start with a lowercase letter.We want it to be publicly reachable, so we set the network’s public option to true.
setops -p <PROJECT> -s <STAGE> --app <APPNAME> network:set public true
The default exposed port of the Server is
8080
, so let’s change it:setops -p <PROJECT> -s <STAGE> --app <APPNAME> network:set port 8080
The Health Check path deviates from the default path (
/
), so you need to adjust the network Health Check as well.setops -p <PROJECT> -s <STAGE> --app <APPNAME> network:set health-check-path '/healthz'
Last you need to set some environment variables to run the GraphQL Engine:
setops -p <PROJECT> -s <STAGE> --app <APPNAME> env:set HASURA_GRAPHQL_ENABLE_CONSOLE=true setops -p <PROJECT> -s <STAGE> --app <APPNAME> env:set HASURA_GRAPHQL_DEV_MODE=true setops -p <PROJECT> -s <STAGE> --app <APPNAME> env:set HASURA_GRAPHQL_ENABLED_LOG_TYPES="startup, http-log, webhook-log, websocket-log, query-log" setops -p <PROJECT> -s <STAGE> --app <APPNAME> env:set HASURA_GRAPHQL_ADMIN_SECRET=setopsftw
-
Create the Services the App needs.
We need to create a PostgreSQL Service and link it to the App
<APPNAME>
.setops -p <PROJECT> -s <STAGE> service:create database --type postgresql11 --plan shared setops -p <PROJECT> -s <STAGE> --app <APPNAME> link:create database --env-key HASURA_GRAPHQL_DATABASE_URL
Next we need to install the PostgreSQL Extension
pgcrypto
:setops -p <PROJECT> -s <STAGE> --service database option:set extensions pgcrypto
-
Commit your Changeset.
setops -p <PROJECT> -s <STAGE> changeset:commit
Deploy your Image #
You need to pull the application image in order to deploy it with SetOps. We use the Docker Image from dockerhub. You can use our Dockerfile
for your own apps, too.
-
Pull and deploy your Image
setops -p <PROJECT> -s <STAGE> --app <APPNAME> release:deploy hasura/graphql-engine:latest
release:deploy
executes all required steps to deploy a new image to SetOps. You can find more information about the distinct steps and how to run them isolated here. -
Verify your app status is
RUNNING
.setops -p <PROJECT> -s <STAGE> app:info <APPNAME>
-
Open the application in your browser.
Copy the domain in format
web.staging.project.$YOURDOMAIN
.setops -p <PROJECT> -s <STAGE> --app <APPNAME> domain
You can log in with the secret defined in the environment variable:
setopsftw
.
Enjoy!
Commands Summary #
If you don’t want explanations for all the commands, you can use these snippets for a fast start. Choose a name for project
, stage
, and app
first. You can edit them in the form in the top right corner.
OpenVSCode Server Blueprint
Configure App
setops project:create <PROJECT>
setops -p <PROJECT> stage:create <STAGE>
setops -p <PROJECT> -s <STAGE> app:create <APPNAME>
setops -p <PROJECT> -s <STAGE> --app <APPNAME> network:set port 8080
setops -p <PROJECT> -s <STAGE> --app <APPNAME> network:set public true
setops -p <PROJECT> -s <STAGE> --app <APPNAME> network:set health-check-path '/healthz'
setops -p <PROJECT> -s <STAGE> --app <APPNAME> env:set HASURA_GRAPHQL_ENABLE_CONSOLE=true
setops -p <PROJECT> -s <STAGE> --app <APPNAME> env:set HASURA_GRAPHQL_DEV_MODE=true
setops -p <PROJECT> -s <STAGE> --app <APPNAME> env:set HASURA_GRAPHQL_ENABLED_LOG_TYPES="startup, http-log, webhook-log, websocket-log, query-log"
setops -p <PROJECT> -s <STAGE> --app <APPNAME> env:set HASURA_GRAPHQL_ADMIN_SECRET=setopsftw
setops -p <PROJECT> -s <STAGE> service:create database --type postgresql11 --plan shared
setops -p <PROJECT> -s <STAGE> --app <APPNAME> link:create database --env-key HASURA_GRAPHQL_DATABASE_URL
setops -p <PROJECT> -s <STAGE> --service database option:set extensions pgcrypto
setops -p <PROJECT> -s <STAGE> changeset:commit
Pull and deploy App to SetOps Registry
setops -p <PROJECT> -s <STAGE> --app <APPNAME> release:deploy hasura/graphql-engine:latest
Destroy Stage & Project
setops -p <PROJECT> stage:destroy <STAGE> --force
setops project:destroy <PROJECT> --force