Openstatus www.openstatus.dev

๐Ÿ“„ Cf guide (#1499)

* blog post

* guide cloudflare

authored by

Thibault Le Ouay and committed by
GitHub
0fb7a0c5 ba0e4098

+133
+4
apps/docs/astro.config.mjs
··· 130 130 label: "How to use React Status Widget", 131 131 slug: "guides/how-to-use-react-widget", 132 132 }, 133 + { 134 + label: "How to deploy probes on Cloudflare Containers ", 135 + slug: "guides/how-to-deploy-probes-cloudflare-containers", 136 + }, 133 137 ], 134 138 }, 135 139 {
apps/docs/src/assets/guides/how-to-deploy-probes-cf-containters/cloudflare-log.png

This is a binary file and will not be displayed.

apps/docs/src/assets/guides/how-to-deploy-probes-cf-containters/private-location.jpg

This is a binary file and will not be displayed.

+1
apps/docs/src/content/docs/guides/getting-started.mdx
··· 14 14 - [Export Metrics to your OTLP endpoint](/guides/how-to-export-metrics-to-otlp-endpoint) 15 15 - [How to Add an SVG Status Badge to your GitHub README](/guides/how-to-add-svg-status-badge) 16 16 - [How to use React Status Widget](/guides/how-to-use-react-widget) 17 + - [How to deploy private location on Cloudflare Containers](/guides/how-to-deploy-probes-cloudflare-containers)
+128
apps/docs/src/content/docs/guides/how-to-deploy-probes-cloudflare-containers.mdx
··· 1 + --- 2 + title: How to deploy the openstatus probe to Cloudflare Containers 3 + description: Learn how to use OpenStatus monitoring data and deploy your own Status Page to cloudflare pages. 4 + sidebar: 5 + label: Deploy private probes on Cloudflare Containers 6 + --- 7 + import { Image } from 'astro:assets'; 8 + import log from '../../../assets/guides/how-to-deploy-probes-cf-containters/cloudflare-log.png'; 9 + import os from '../../../assets/guides/how-to-deploy-probes-cf-containters/private-location.jpg'; 10 + 11 + 12 + In this guide we will show you how to deploy the OpenStatus probe to Cloudflare Containers. 13 + 14 + Cloudflare Containers is a platform that allows you to run serverless containers in the Cloudflare network. 15 + 16 + 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. 17 + 18 + The code showcased in this guide is available on [GitHub](https://github.com/openstatusHQ/private-location-cloudflare-container) 19 + 20 + ### Requirements 21 + - A Cloudflare Account. 22 + - An [openstatus](https://www.openstatus.dev) Account. 23 + 24 + 25 + 26 + ### Create a private location on OpenStatus 27 + 28 + 1. Go to the OpenStatus dashboard. 29 + 2. Click on the `Private locations` in the sidebar. 30 + 3. Click on the `Create Private Location` button. 31 + 4. Give it a human readable name. 32 + 5. Save token. 33 + 6. Click submit to save the newly created private location. 34 + 35 + ### Create a Cloudflare Container 36 + 37 + 1. Create a new cloudflare workers container template using the following command: 38 + 39 + ```bash 40 + pnpm create cloudflare@latest --template=cloudflare/templates/containers-template 41 + ``` 42 + 43 + 2. 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.: 44 + 45 + ```bash 46 + docker docker pull --platform linux/amd64 ghcr.io/openstatushq/private-location:latest 47 + ``` 48 + 49 + 3. Tag the image, be aware we cannot use the `latest` tag on Cloudflare Containers: 50 + 51 + ```bash 52 + docker tag ghcr.io/openstatushq/private-location:latest openstatus-private-location:v1 53 + ``` 54 + 55 + 4. Push the image to Cloudflare Container Registry: 56 + 57 + ```bash 58 + pnpm wrangler containers push openstatus-private-location:v1 59 + ``` 60 + 61 + 5. Update the `wrangler.toml` file to use the pushed image: 62 + 63 + ```toml 64 + [containers] 65 + image = "registry.cloudflare.com/GENERATED_ID/openstatus-private-location:cf-1" 66 + ``` 67 + 68 + 6. Update the worker to use a cron trigger to keep the container alive, add the following to your `wrangler.toml` file: 69 + 70 + ```toml 71 + triggers = { cron = ["*/2 * * * *"] } 72 + ``` 73 + 74 + 7. Update the `index.ts` file to run a simple command to keep the container alive: 75 + 76 + ```ts 77 + sleepAfter = "150s"; 78 + ``` 79 + and 80 + 81 + ```ts 82 + async scheduled(_controller: any, env: Env) { 83 + try { 84 + const container = getContainer(env.MY_CONTAINER); 85 + await container.start({ 86 + envVars: { 87 + OPENSTATUS_KEY: env.OPENSTATUS_KEY, 88 + }, 89 + }); 90 + } catch (e) { 91 + console.error("Error in scheduled task:", e); 92 + } 93 + 94 + return new Response("ok"); 95 + }, 96 + ``` 97 + 98 + 9. Add you OpenStatus API secret 99 + 100 + ```bash 101 + pnpm wrangler secret put OPENSTATUS_KEY 102 + ``` 103 + 104 + 105 + 10. Deploy the container to Cloudflare Containers: 106 + 107 + ```bash 108 + pnpm wrangler deploy 109 + ``` 110 + 111 + 112 + 113 + 114 + ## Conclusion 115 + 116 + You have successfully deployed the openstatus private location probe to Cloudflare Containers. Thus you can monitor your endpoint from Cloudflare's global network. 117 + 118 + 119 + <Image 120 + src={log} 121 + alt="OpenStatus Private Location on Cloudflare Containers" 122 + caption="Cloudflare Workers Logs showing OpenStatus Private Location running" 123 + /> 124 + 125 + <Image 126 + src={os} 127 + alt="OpenStatus Private Location on Cloudflare Containers" 128 + />