Skip to content

How to deploy the openstatus probe to Cloudflare Containers

In this guide we will show you how to deploy the OpenStatus probe to Cloudflare Containers.

Cloudflare Containers is a platform that allows you to run serverless containers in the Cloudflare network.

Cloudflare containers automatically scales down after a given time. We will push a cron worker that will keep our container alive and running on Cloudflare Containers platform.

The code showcased in this guide is available on GitHub

  1. Go to the OpenStatus dashboard.
  2. Click on the Private locations in the sidebar.
  3. Click on the Create Private Location button.
  4. Give it a human readable name.
  5. Save token.
  6. Click submit to save the newly created private location.
  1. Create a new cloudflare workers container template using the following command:
Terminal window
pnpm create cloudflare@latest --template=cloudflare/templates/containers-template
  1. Fetch openstatus private location image from Docker Hub, we need to specify the platform to linux/amd64 because Cloudflare Containers currently only supports amd64 architecture.:
Terminal window
docker docker pull --platform linux/amd64 ghcr.io/openstatushq/private-location:latest
  1. Tag the image, be aware we cannot use the latest tag on Cloudflare Containers:
Terminal window
docker tag ghcr.io/openstatushq/private-location:latest openstatus-private-location:v1
  1. Push the image to Cloudflare Container Registry:
Terminal window
pnpm wrangler containers push openstatus-private-location:v1
  1. Update the wrangler.toml file to use the pushed image:
[containers]
image = "registry.cloudflare.com/GENERATED_ID/openstatus-private-location:cf-1"
  1. Update the worker to use a cron trigger to keep the container alive, add the following to your wrangler.toml file:
triggers = { cron = ["*/2 * * * *"] }
  1. Update the index.ts file to run a simple command to keep the container alive:
sleepAfter = "150s";

and

async scheduled(_controller: any, env: Env) {
try {
const container = getContainer(env.MY_CONTAINER);
await container.start({
envVars: {
OPENSTATUS_KEY: env.OPENSTATUS_KEY,
},
});
} catch (e) {
console.error("Error in scheduled task:", e);
}
return new Response("ok");
},
  1. Add you OpenStatus API secret
Terminal window
pnpm wrangler secret put OPENSTATUS_KEY
  1. Deploy the container to Cloudflare Containers:
Terminal window
pnpm wrangler deploy

You have successfully deployed the openstatus private location probe to Cloudflare Containers. Thus you can monitor your endpoint from Cloudflare’s global network.

OpenStatus Private Location on Cloudflare Containers OpenStatus Private Location on Cloudflare Containers