Here's an example project with Interval running on Google Cloud Run.
There are two requirements for running Interval on Google Cloud Run:
- Your instance must use always allocated CPUs with a single allocated instance
- Your entrypoint must listen for connections on port 8080 (this is how Google knows that your app is online):
// src/index.ts
import "dotenv/config";
import Interval, { io } from "@interval/sdk";
// Google Cloud Run requires a process listening on port 8080
const http = require("http");
const server = http.createServer(() => {});
server.listen(8080);
const interval = new Interval({
apiKey: process.env.INTERVAL_API_KEY,
actions: {
hello_world: async () => {
const name = await io.input.text("Your name");
return `Hello, ${name}`;
},
},
});
interval.listen();
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 the sample Dockerfile and index.ts.
- In Google Cloud Platform, go to the Cloud Run dashboard
- 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 API key as
INTERVAL_API_KEY
. You can get your API key from the dashboard. - Click Create
That's it! Cloud Build will build and deploy your app to Cloud Run.