Deploy on Google Cloud
In this guide we'll walk you through deploying an Interval app on Google Cloud Run.
The full code for this example for Node is also available on GitHub.
Before you begin
There are two important requirements for running Interval on Google Cloud Run.
The first is that your instance must use always allocated CPUs with a single allocated instance. Interval requires an always-online listener, and we won't be able to connect to your app if Google allows the server to sleep or shut down due to inactivity.
The second is that your entrypoint must listen for connections on port 8080. This is how Google detects that your app is online:
- TypeScript
- JavaScript
import path from "path";
import http from "http";
import { Interval } from "@interval/sdk";
// Google Cloud Run requires a process listening on port 8080
const server = http.createServer(() => {});
server.listen(8080);
const interval = new Interval({
endpoint: "wss://<YOUR INTERVAL SERVER URL>/websocket",
apiKey: "<YOUR API KEY>", // get an API key from the Keys page in your Interval dashboard
routesDirectory: path.resolve(__dirname, "routes"),
});
interval.listen();
const path = require("path");
const http = require("http");
const { Interval } = require("@interval/sdk");
// Google Cloud Run requires a process listening on port 8080
const server = http.createServer(() => {});
server.listen(8080);
const interval = new Interval({
endpoint: "wss://<YOUR INTERVAL SERVER URL>/websocket",
apiKey: "<YOUR API KEY>", // get an API key from the Keys page in your Interval dashboard
routesDirectory: path.resolve(__dirname, "routes"),
});
interval.listen();
Installation
Use the following instructions to set up a new instance on Google Cloud Run to run Interval.
This guide assumes you'll be setting up continuous deployment from a GitHub repo using a Dockerfile. For examples of how to set up your project, check out a sample Dockerfile and index.ts.
- Go to the Cloud Run dashboard and click Create Service
- Choose Continuously deploy new revisions from a source repository, then click the Set Up With Cloud Build button
- Pick your repo from GitHub and click Next
- Under Build Type, select the Dockerfile option
- Under CPU allocation, pick "CPU is always allocated"
- Set minimum and maximum number of instances to 1
- Under Authentication, choose "Allow unauthenticated invocations"
- Click Container, Variables & Secrets, Connections, Security
- Under Variables & Secrets > Environment Variables, add your Live mode API key as
INTERVAL_API_KEY
. You can get an API key from the dashboard. - Click Create
That's it! Cloud Build will build and deploy your app to Cloud Run. Check the Cloud Build logs for progress and look for your actions to appear in the Actions tab in Interval shortly.
Having issues with any of these steps? Let us know and we'd be happy to help you out.