Week 2 of the Hasura internship was dedicated to setting up your system for creating the project, and the last step of the week is to install the Hasura platform in our computers so that we can work on it locally.
The steps are provided to us by Hasura, which are simple enough, no matter what OS you are using. I will be installing it on my Zorin OS. For other OS users, there are only slight changes, which are as and when specified in the instructions.
Steps to setup Hasura Local
First, we need to make sure that our system specifications meet 64 bit architecture and at least 4 GB of RAM. If this is all good, then we proceed.
- So the first step is to install Virtualbox. It is an open source virtualization tool, available for all platforms. Install from here the one compatible for your system.
- Now Windows users have to install git-bash if they don’t have it yet. It will be used to run the further commands.
- Install Hasuractl which is a command line tool. It will simply allow us to install the Hasura project locally by linking to our account on this. Hasuractl requires a Kubernetes cluster, to be running locally, to do this job. Hence we need to install minikube, which is a tool that makes this possible, by running a single-node Kubernetes cluster inside a VM that we installed (Virtualbox in our case).
All three platforms have 3 different approaches to install hasuractl:
- In windows, as given in the instructions, you have to download hasuractl.exe and place it in your PATH. There is this video reference also provided to make things clear.
- In Linux, you need to first download it using this command:
curl -Lo hasuractlhttps://storage.googleapis.com/hasuractl/v0.1.2/linux-amd64/hasuractl
- Then make it executable using this command,
chmod +x hasuractl
- Finally, add the file to the system path,
sudo mv hasuractl /usr/local/bin/
- For Mac users, the steps are similar to the Linux ones, only a small change is there. Here is this combined single line command to install it:
curl -Lo hasuractl https://storage.googleapis.com/hasuractl/v0.1.2/darwin-amd64/hasuractl && chmod +x hasuractl && sudo mv hasuractl /usr/local/bin/
Now we proceed to install Kubectl, which is also a command-line tool, that hasuractl requires to communicate with the Kubernetes cluster.
Here is the link to download and install it. Install version 1.6.0 or above.
To make this local-development work, we need to create an account on beta.husura.io. So make sure you have one.
Now using command-line, we have to run the following commands:
hasuractl local start
This command, when executed for the first time, will download 1-1.5 GB of docker images and therefore depending on your internet connection, it may take a while (or perhaps long :/) to complete.
For me, it took around half an hour to finally complete. The normal process will end up by providing a URL to the console and also Username and password to log in to it.
However, the wait may also result in some errors, causing the process to get stuck at various levels.
If this happens, we need to clean the installation and redo it.
hasuractl local clean
This command deletes all data and configuration.
However, it does not delete the underlying VM, and all the downloaded images still exist inside the VM. Simply rerun
hasuractl local start command to start again.
But if you want to delete the underlying VM too, then run this command instead:
hasuractl local delete
All the downloaded images along with the VM are completely removed after its execution.
After successfully logging in to the console, you can see the dashboard, where you can manage database, sub domains, etc. This conforms that local-development has been setup successfully.
This can further be ensured by running this command which shows status of all the pods running.
kubectl get pods -n hasura or kubectl get po -n hasura
Exposing Locally created project to Public
The Hasura platform provides with a privilege to expose your work on the internet, that too, with execution of a simple command:
hasuractl local expose
But, before doing that, you have to configure your public URL using this link: https://beta.hasura.io/local-development
So when the command is run, console url changes from console.c100.hasura.me to the one configured by you on beta.hasura.io.
So, this means your project is up, and anyone on the internet can access your application, till you keep it alive using your laptop.
So now everything is set and we are ready to begin with our project development. The task in the next week is to prepare Data Models for the app along with testing Hasura’s Data and Auth APIs.