Git Ready With Hasura & Your Team — Part 2/7

Joseph Cooper
KintoHub
Published in
6 min readJan 8, 2020

This is Part 2 to Hasura && KintoHub Idea to Scale blog series. Playing with cool new dev tools is always fun, but running things at scale with a team usually comes with a lack of documentation, process and random quirks that aren’t. This post will help you easily set up a git repository for team collaboration and a cloud environment with CI/CD on KintoHub in less than 15 minutes!

KintoHub has been using Hasura in production for some time now. KintoHub manages KintoHub with KintoHub, so we’re always running into the same issues our users do as well. In this article, we’ll cover what we’re doing which makes us happy and some of the upcoming changes that Hasura is working on which we believe will bulletproof migrations.

The Problem & Goal

When you have two or more people working on any project together, problems arise faster than you’d think. That’s why Git, Branches, Pull Requests and more were invented. Similarly with Hasura and KintoHub, working directly with the Hasura Console or deploying only single-branch repositories on KintoHub works great for individual projects, but you would not want to do this with a team sharing the same environment as you may interrupt someone hard at work!

It’s important for developers to easily obtain a local, isolated environment to make and test changes before committing to a collaborative group environment such as dev or staging.

The goal? Let’s introduce new changes to your backend database and services with zero downtime, including when you deploy changes to your customers. In order to achieve this, it’s important to create stateless services and backward compatible services which are outside the scope of this article. But what is key for your team is to follow a simple process to achieve high uptime, less merge conflicts and dodge bugs with isolated environments.

Teams have invented many ways to manage branches for collaboration. We will be following Git Flow with a simple dev and prod environment based on a dev and master branch. To introduce changes into dev via feature, bug and hotfix branches.

Git Started

We’ve created a standard template to start using Hasura locally and on KintoHub.

You can easily copy this template to your organization or account via the “Use this template” button.

There you will find the following directory structure…

Files for cloud deployment

  • /migrations — standard folder for applying all changes to your database with Hasura.
  • Dockerfile — a simple Dockerfile with “cli-migrations” tag which will automatically detect and apply all new changes to the running database

Files for local development

  • config.yaml — a standard file for Hasura which defines where
  • docker-compose.yaml — a multi-docker setup to easily spin up a local Hasura instance and Postgres database with your migrations applied to it.

Setup the Cloud Development Environment

Login or Signup to KintoHub which has a free tier that can run this entire example. Once logged in go to the Create KintoBlock page. KintoHub introduces the concept of “Blocks” which we will need one for Hasura and one for Postgres in order to complete the example.

  1. Select the Create Website Block.
  2. Connect to GitHub and grant access to all or the hasura-template repository.
  3. Select the hasura-template repository then press Continue.
  4. Enter a name for your Block and then select Dynamic Web App

5. Enter the port 8080 then press Create Website

It should look something like this!

Once created, you’ll find that a build has automatically been triggered on the master branch. This takes about 60 seconds. While you wait, you can take a peek around KintoHub and see other branches on the left side and advanced settings at the top left.

Now your build is successful! Let’s get this up and online!

While you wait…. Enable Continuous Integration (CI) so that future commits will automatically be deployed in the build settings on the page.

Once the build is successful, “Deploy Now” which will add your Hasura project to a new environment. Scroll down to find the KintoBlocks section where you will need to add a Postgres Database. Type “Postgres” inside of the “Add KintoBlocks” bar and then select it. Also, Enable the “Automatically deploy when new KintoBlock commits are available”.

Now you’re all set! Since we already have configured the “default settings” for you in the git repository, you can simply click the green “Deploy” button at the bottom right and then confirm your deployment! It takes about 60 seconds, but you’ll find your Hasura and the database instances online and ready to rock after!

The last and final step to see the fruit of all your hard work is to click the “Open” button on your block to access Hasura!

You now have set up an awesome way to start using Hasura in the cloud and directly edit a database… This works great for individuals, but now we need a more pragmatic process in place to collaborate with a team via Git!

Git + Hasura For Teams!

Let’s say that we want to make a new table of users and get it accepted and deployed into the dev environment. The first thing you’ll need to do is download Hasura CLI tools which come with a hande set of functions to make this easy. You will also need the latest Docker for Desktop.

Once installed run the following:

  1. Run git clone {your-hasura-repository...}
  2. Go to the root of the repository you have cloned
  3. Run git checkout -b feat/users — Create a new branch for the users feature.
  4. Run docker-compose up -d — Which will spin up a local hasura instance and postgres server.
  5. hasura console — This will open up a special browser connecting to your Hasura instance.
  6. Go to “Data” and create a users table with a few columns
  7. Now check the /migrations folder within your repository and you can see all your changes have been tracked!
  8. Commit your new files with git add -A && git commit -m "{Cool message here}
  9. Now push your branch and create a pull request to master !

With a new branch and pull requests, people can now pull your migration changes, run docker-compose up -d which will automatically update the latest changes into their local server. If all checks out good, they can approve the PR and merge it to master.

Since you enabled CI/CD, whenever a new commit is available, your environment will perform a “Rolling Update” where it will replace your instance and transfer the traffic with zero downtime. If any issues occur, KintoHub will automatically stop the update, log the errors and keep the existing version online!

That’s It! In Summary…

Now you have a simple workflow on how to create migrations and deploy them into a live cloud development environment. You can learn more advanced topics on KintoHub’s docs and Hasura’s Docs.

Now that we have a cloud environment and a process to safely collaborate and update your environment, the next steps will be to set up a more powerful, bulletproof production environment! You may want stronger machines and multiple instances running to reduce the chances of having any downtime. Expect another post about that in the coming weeks!

  1. From Idea to Scale with Hasura && KintoHub
  2. Git Ready with Hasura & Your Team (This Post)
  3. Setup a Hasura Production Environment on KintoHub (Coming Soon)
  4. Securing your Hasura Environment on KintoHub (Coming Soon)
  5. Advanced Hasura & KintoHub App: CRUD, Events, Microservices & introducing Actions! (Coming Soon)
  6. Load test Hasura to over 9000 with Vegeta && KintoHub (Coming Soon)
  7. Advanced Use Cases, Ongoing Improvements, Learnings and Retrospection (Coming Soon)

BONUS — HELP US!

We’re currently wondering if we should build out Bitbucket or Gitlab next. Please help us vote below!

Bitbucket: https://feedback.kintohub.com/feature-requests/p/bitbucket-support

Gitlab: https://feedback.kintohub.com/feature-requests/p/gitlab-support

--

--