dehaze

Using the Gateway Directly

This guide shows you how to use the Gateway component of Space Cloud directly.

Why would I need to use the gateway directly?link

Space Cloud is an opensource serverless platform based on Kubernetes, which lets you develop, scale and secure cloud-native apps.

You can see it as a Firebase + Heroku. On one side, it provides instant GraphQL APIs for any database which can be consumed directly from your frontend. On the other, it provides serverless capabilities on top of kubernetes. It also has an easy to use authorization system, end to end traffic encryption and a lot more.

To cover this entire spectrum of development (auto-generated GraphQL/REST APIs) to operations (auto-scaling, end to end traffic encryption), Space Cloud has two components:

  • Gateway (Reduces development time): Responsible for ingress traffic and providing auto-generated GraphQL/REST APIs that can be consumed by frontend directly.
  • Runner (Automates operations): Responsible for providing serverless capabilities, end-to-end traffic encryption, policy enforcement and other such features.

There might be various use cases why one would want to run the Gateway component directly, such as:

  • You are just interested in the GraphQL/REST APIs that Space Cloud provides and don’t need the serverless capabilities.
  • You already have a deployment platform in place like Nomad or DCOS, and so you don’t want the Runner component.

Keeping such use cases in mind, we purposely split Space Cloud into two components.

Both these components require Redis as a dependency.

Using gateway directlylink

There are two ways of using the gateway directly:

Using the docker imagelink

You can directly use the docker image of gateway published on DockerHub by us.

The following command runs the gateway on docker in development mode and exposes its HTTP and HTTPS ports:

docker run --name sc-gateway -d -p 4122:4122 -p 4126:4126 -e CLUSTER_ID=my-cluster -e DEV=true -e REDIS_CONN=redis:6379 spaceuptech/gateway:latest

Check out the list of environment variables below that you can pass to the gateway container.

Using the binarylink

To use the binary of gateway directly, you first need to build it from its source.

You need to have Go 1.13.0 or above to build gateway from its source.

Clone the repository of Space Cloud first:

git clone https://github.com/spacecloud-io/space-cloud.git

Checkout into the gateway folder:

cd space-cloud/gateway

Now that we have the source code for the gateway, let’s build it:

go build

Building the gateway might take a few minutes depending on the internet as it downloads all the dependencies of gateway before building it.

Once the build is successful, you should be able to see a new binary with the name of gateway in case of Linux/Mac or gateway.exe in case of Windows. This is the desired binary that we need to use.

Now that we have the gateway binary, here’s how to run it:

./gateway run --dev --cluster my-cluster
gateway.exe run --dev --cluster my-cluster

That’s it. We have successfully run the gateway directly from its source code. You can pat yourself on the back now since you deserve it!😛

Check out the list of environment variables/flags below that you can pass to the gateway binary.

Environment variables / flagslink

You can pass environment variables or flags while running the gateway to tweak certain things. Below is a list of the most important environment variables /flags:

While using docker container you can only set environment variables whereas with the binary you can use both the environment variables and/or flags

Environment variable Flag Default value Description
CLUSTER_ID --cluster na Set gateway’s cluster id.
DEV --dev false Run gateway in development mode.
ADMIN_USER --admin-user admin Set the admin user name.
ADMIN_PASS --admin-pass 123 Set the admin password.
ADMIN_SECRET --admin-secret some-secret Set the admin JWT secret.
PORT --port 4122 The HTTP port of Space Cloud. HTTPS port is auto calculated as (HTTP port + 4).
REDIS_CONN n/a localhost:6379 Set redis connection string.

The admin credentials are required to login into the Mission Control (Admin UI of Space Cloud).

Have a technical question?

Improve the docs!