Adding a microservice from a template¶
Note
If you’re starting with a new project head to hasura.io/hub and get started with a new Hasura project that already has the boilerplate for your stack.
Use this guide if you are adding a microservice to your existing Hasura project.
Step 1: Choosing a microservice template from Hub¶
You can clone microservices from any of the projects on hasura.io/hub and use them as a template for your microservice.
Go to hasura.io/hub and find a boilerplate project you want to clone from. Most projects should have an Included microservices
section which describes the microservices available in the project. See Popular hub microservices:
Step 2: Cloning the microservice to your project¶
To add the microservice to your project, you can use the hasura microservice clone
command from the project directory.
$ hasura microservice clone [[microservice-1] [microservice-2]...] --from [hub-user/hub-project-name] [flags]
Examples:
# Clone microservice 'app' from 'hasura/hello-python-flask':
$ hasura microservice clone app --from hasura/hello-python-flask
# Clone all microservices from 'hasura/hello-react'
$ hasura microservice clone --from hasura/hello-react
# Clone microservices 'api' and 'ui' from 'hasura/hello-react'
$ hasura microservice clone api ui --from hasura/hello-react
Step 3: Tell the Hasura CLI that you want to git-push to deploy this microservice¶
Add configuration to your conf/ci.yaml
file so that git push hasura master
will
automatically deploy your source code, build the docker image, and rollout the update!
$ hasura conf generate-remote <new-app> >> conf/ci.yaml
Behind The Scenes
Checkout ci.yaml to learn more about this file
Step 4: (Optional) Expose this microservice to the world¶
Let’s expose this microservice to the external world on the subdomain <new-app>
.
The configuration for routes for all the microservices on your Hasura project
are configured in conf/routes.yaml
.
The hasura
CLI provides a handy command to generate the
default routes configuration for your custom microservice:
$ hasura conf generate-route <new-app> >> conf/routes.yaml
This command above will add the default route configuration for your microservice to the conf/routes.yaml
file.
Behind The Scenes
Check out routes.yaml to learn more about this file
Step 5: Git push and deploy!¶
$ git add . && git commit -m 'Added <new-app>'
$ git push hasura master
That’s it! And you’ll have a shiny new microservice deployed to your cluster.
Check out the running microservices:
$ hasura microservices list
Open the microservice in your browser:
$ hasura microservices open <new-app>
Popular hub microservices:¶
Here are a few popular microservices you can choose from:
app
from hasura/hello-python-flaskui
from hasura/hello-reactapi
from hasura/hello-nodejs-expressapi
from hasura/hello-php-apacheapp
from hasura/hello-python-djangowww
from hasura/hello-java-springbootwww
from hasura/hello-nginxapp
from hasura/hello-golang-rawapp
from hasura/docker-basewww
from hasura/hello-angularjsapi
from hasura/hello-golang-iriswww
from hasura/hello-r-shinyapi
from hasura/hello-java-sparkapp
from hasura/hello-ruby-railsapp
from hasura/hello-ruby-sinatrawww
from hasura/hello-csharp-aspnetapi
from hasura/hello-swift-vaporapi
from hasura/hello-swift-perfect