Compare commits

..
9 Commits
Author SHA1 Message Date
michael ceba2d26e6 Merge pull request 'Deploy: install requests for the D1 scripts' (#2) from fix-deploy-python-deps into main
Check / check (push) Successful in 50s
Deploy to Cloudflare / build-and-deploy (push) Failing after 58s
Reviewed-on: #2
2026-11-25 04:11:23 +00:00
Michael Kinder dd8b610ea5 Deploy: install requests for the D1 scripts (the Gitea runner image lacks it)
Check / check (pull_request) Successful in 52s
2026-11-24 23:04:02 -05:00
michael 13ea6a0fe3 Merge pull request 'Move CI to Gitea Actions' (#1) from gitea-actions into main
Check / check (push) Successful in 1m35s
Deploy to Cloudflare / build-and-deploy (push) Failing after 1m51s
Reviewed-on: #1
2026-11-25 03:57:32 +00:00
Michael Kinder 303016681a CI: use the npm cache again (the runners' cache server is reachable now)
Check / check (pull_request) Successful in 1m42s
2026-11-24 22:49:36 -05:00
Michael Kinder 2fe7fb386b CI: don't use the npm cache (restoring it stalls on the runner)
Check / check (pull_request) Successful in 1m4s
2026-11-24 22:40:34 -05:00
Michael Kinder 1d11d58b86 Move CI to Gitea Actions
Check / check (pull_request) Canceled after 4m3s
Workflows live in .gitea/workflows. The upstream sync pushes with an access
token, so it no longer needs the GitHub-only deploy trigger or PAT input.
2026-11-24 22:14:33 -05:00
michael 7c3eb7debd Send down and back-up alerts to Mattermost (#6)
Deploy to Cloudflare / build-and-deploy (push) Skipped
Check / check (push) Successful in 10m48s
The webhook address is private: uptime.config.ts names it as secret:MATTERMOST_WEBHOOK and the
worker reads the Worker secret of that name (bound in deploy.tf from the GitHub Actions secret).
The address is kept out of the logs. Alerts wait 3 minutes before saying something is down.
2026-11-23 10:11:52 -05:00
michael cf977e65da Read the apps check address from a Worker secret (#5)
A monitor's target can be secret:NAME: the worker reads the address
from the Worker secret NAME at check time, bound in deploy.tf from the
GitHub Actions secret of the same name. The address never appears in
this repository, and any error text that mentions it is scrubbed before
it's stored or shown. Apps in US East now checks a real app this way.
2026-11-23 03:35:25 -05:00
michael 035d23d1e3 Check apps in US East through the status canary (#4) 2026-11-22 23:50:58 -05:00
8 changed files with 116 additions and 31 deletions

No files matched your search

File renamed without changes.
@@ -5,8 +5,8 @@ on:
branches: ['main']
workflow_dispatch:
# Cottage: deploys only once the repository variable CLOUDFLARE_DEPLOY is "true" (set at launch,
# with the CLOUDFLARE_API_TOKEN secret). Until then a push to main does nothing.
# Cottage (Gitea Actions): deploys only once the repository variable CLOUDFLARE_DEPLOY is "true" (set
# at launch, with the CLOUDFLARE_API_TOKEN secret). Until then a push to main does nothing.
env:
WRANGLER_SEND_METRICS: 'false'
@@ -63,6 +63,9 @@ jobs:
run: |
npx @cloudflare/next-on-pages
- name: Install Python dependencies (the Gitea runner image lacks them)
run: pip install --quiet requests
- name: Create D1 database and tables
run: |
python3 deploy/init_d1.py # This sets D1_ID in GITHUB_ENV
@@ -104,6 +107,8 @@ jobs:
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
TF_VAR_CLOUDFLARE_ACCOUNT_ID: ${{ steps.fetch_account_id.outputs.account_id }}
TF_VAR_APPS_US_EAST_TARGET: ${{ secrets.APPS_US_EAST_TARGET }}
TF_VAR_MATTERMOST_WEBHOOK: ${{ secrets.MATTERMOST_WEBHOOK }}
D1_ID: ${{ env.D1_ID }}
# Currently Terraform Cloudflare provider doesn't support direct upload, use wrangler to upload instead.
@@ -1,9 +1,8 @@
name: Upstream Sync
permissions:
contents: write
actions: write
# Pulls the latest UptimeFlare code from github.com/lyc8503/UptimeFlare while keeping our
# uptime.config.ts. The push uses SYNC_TOKEN (an access token with write access to this
# repository) so that it starts the Deploy workflow like any other push to main.
on:
workflow_dispatch:
inputs:
@@ -12,9 +11,6 @@ on:
type: boolean
required: true
default: false
override-token:
description: '[Optional] Paste a PAT here. If left blank, PAT_TOKEN secret will be used (if set). Used to solve `refusing to allow a GitHub App to create or update workflow... `, more info at https://github.com/lyc8503/UptimeFlare/wiki/Synchronize-updates-from-upstream#upgrade-methods'
required: false
jobs:
sync_latest_from_upstream:
@@ -23,9 +19,9 @@ jobs:
steps:
- name: Checkout target repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
token: ${{ inputs.override-token || secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
token: ${{ secrets.SYNC_TOKEN }}
- name: Current config
run: |
@@ -33,10 +29,9 @@ jobs:
cp uptime.config.ts /tmp/origin.config.ts
- name: Sync upstream changes
id: sync
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "Cottage status sync"
git config user.email "[email protected]"
# Fetch latest code
git clone https://github.com/lyc8503/UptimeFlare /tmp/latest
@@ -49,9 +44,3 @@ jobs:
git add .
git commit -m "Sync latest code from upstream"
git push
- name: Trigger deployment
if: ${{ inputs.override-token == '' }}
uses: benc-uk/workflow-dispatch@v1
with:
workflow: deploy.yml
+1 -1
View File
@@ -23,7 +23,7 @@ export default function Footer() {
<span>
Built on{' '}
<a href="https://github.com/lyc8503/UptimeFlare">UptimeFlare</a>, open source (
<a href="https://github.com/cottage-host/status">our copy</a>)
<a href="https://git.cottage.host/cottage/status">our copy</a>)
</span>
</div>
</div>
+21
View File
@@ -16,6 +16,19 @@ variable "CLOUDFLARE_ACCOUNT_ID" {
type = string
}
# Cottage: private monitor addresses (see `secret:` targets in uptime.config.ts).
variable "APPS_US_EAST_TARGET" {
# read from $TF_VAR_APPS_US_EAST_TARGET (the GitHub Actions secret of the same name)
type = string
sensitive = true
}
variable "MATTERMOST_WEBHOOK" {
# read from $TF_VAR_MATTERMOST_WEBHOOK (the GitHub Actions secret of the same name)
type = string
sensitive = true
}
variable "enable_do_migration" {
type = bool
default = false
@@ -59,6 +72,14 @@ resource "cloudflare_workers_script" "uptimeflare_worker" {
name = "UPTIMEFLARE_D1"
type = "d1"
id = cloudflare_d1_database.uptimeflare_d1.id
}, {
name = "APPS_US_EAST_TARGET"
type = "secret_text"
text = var.APPS_US_EAST_TARGET
}, {
name = "MATTERMOST_WEBHOOK"
type = "secret_text"
text = var.MATTERMOST_WEBHOOK
}]
}
+18 -5
View File
@@ -43,20 +43,33 @@ const workerConfig: WorkerConfig = {
headers: { 'User-Agent': 'cottage-status (+https://status.cottage.host)' },
},
{
// A small app Cottage runs for itself on the region's servers (ntfy, "Status canary" on
// Cottage's own internal account), so this checks the whole path a customer's app takes:
// Cloudflare, the node's proxy, Harbor and a running container.
// A real app running on the region's servers (on Cottage's own internal account), so this
// checks the whole path a customer's app takes: Cloudflare, the node's proxy, Harbor and a
// running container. Its address is private: the worker reads it from the Worker secret
// APPS_US_EAST_TARGET (GitHub Actions secret of the same name, bound in deploy.tf).
id: 'apps-us-east',
name: 'Apps in US East',
tooltip: 'Customer apps hosted in Virginia',
method: 'GET',
target: 'https://status-canary-m7ec.cottagehost.com/v1/health',
target: 'secret:APPS_US_EAST_TARGET',
expectedCodes: [200],
timeout: 10000,
headers: { 'User-Agent': 'cottage-status (+https://status.cottage.host)' },
},
],
// Alerts come from Grafana Cloud (hearth infra/monitoring). A webhook here could page too.
// Down and back-up messages go to the founder's Mattermost (channel "alerts"). The webhook address
// is private: the worker reads it from the Worker secret MATTERMOST_WEBHOOK (GitHub Actions secret of
// the same name, bound in deploy.tf). Grafana Cloud (hearth infra/monitoring) alerts there too.
notification: {
webhook: {
url: 'secret:MATTERMOST_WEBHOOK',
payloadType: 'json',
payload: { text: '$MSG', username: 'Status' },
},
timeZone: 'Etc/UTC',
// Wait a few minutes before saying something is down, so a single failed check doesn't page.
gracePeriod: 3,
},
}
// Notices shown on the page: incident updates and planned maintenance. Newest last.
+35 -2
View File
@@ -2,7 +2,7 @@ import { DurableObject } from 'cloudflare:workers'
import { MonitorTarget } from '../../types/config'
import { workerConfig } from '../../uptime.config'
import { doMonitor, getStatus } from './monitor'
import { formatAndNotify, getWorkerLocation } from './util'
import { formatAndNotify, getWorkerLocation, setWebhookSecrets } from './util'
import { CompactedMonitorStateWrapper, getFromStore, setToStore } from './store'
import pLimit from 'p-limit'
@@ -11,8 +11,41 @@ export interface Env {
UPTIMEFLARE_D1: D1Database
}
// Cottage: a monitor's target may be `secret:NAME`, read at check time from the Worker secret
// NAME (bound in deploy.tf from a GitHub Actions secret), so a private address never appears in
// this public repo. Error text is scrubbed of the address before it's stored or shown.
type CheckStatus = { ping: number; up: boolean; err: string }
function secretTarget(monitor: MonitorTarget, env: Env): { monitor: MonitorTarget; secret?: string } | { missing: string } {
if (!monitor.target.startsWith('secret:')) return { monitor }
const name = monitor.target.slice('secret:'.length)
const value = (env as unknown as Record<string, unknown>)[name]
if (typeof value !== 'string' || value === '') return { missing: name }
return { monitor: { ...monitor, target: value }, secret: value }
}
function scrub(status: CheckStatus, secret: string): CheckStatus {
let err = status.err
const parts = [secret]
try {
parts.push(new URL(secret).host, new URL(secret).hostname)
} catch {}
for (const p of parts) if (p) err = err.split(p).join('the app')
return { ...status, err }
}
async function checkMonitor(monitor: MonitorTarget, location: string, env: Env) {
const r = secretTarget(monitor, env)
if ('missing' in r) {
return { id: monitor.id, location, status: { ping: 0, up: false, err: `Check address not configured (${r.missing})` } }
}
const result = await doMonitor(r.monitor, location, env)
return r.secret ? { ...result, status: scrub(result.status, r.secret) } : result
}
const Worker = {
async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> {
setWebhookSecrets(env)
const workerLocation = (await getWorkerLocation()) || 'ERROR'
console.log(`Running scheduled event on ${workerLocation}...`)
@@ -31,7 +64,7 @@ const Worker = {
let checkResult: Record<string, CheckResult> = {};
const limit = pLimit(5);
for (const monitor of workerConfig.monitors) {
checkQueue.push(limit(() => doMonitor(monitor, workerLocation, env)))
checkQueue.push(limit(() => checkMonitor(monitor, workerLocation, env)))
}
for (const result of await Promise.all(checkQueue)) {
checkResult[result.id] = result
+27 -3
View File
@@ -79,6 +79,24 @@ function templateWebhookPlayload(payload: any, message: string) {
}
}
// Cottage: a webhook url may be `secret:NAME`, read at send time from the Worker secret NAME (bound in
// deploy.tf from a GitHub Actions secret), so the address never appears in this public repo or the logs.
let webhookSecrets: Record<string, unknown> = {}
function setWebhookSecrets(env: object) {
webhookSecrets = env as Record<string, unknown>
}
function resolveWebhookUrl(url: string): string | undefined {
if (!url.startsWith('secret:')) return url
const value = webhookSecrets[url.slice('secret:'.length)]
return typeof value === 'string' && value !== '' ? value : undefined
}
function hideUrl(text: string, url: string, real: string): string {
return real === url ? text : text.split(real).join(url)
}
async function webhookNotify(webhook: WebhookConfig, message: string) {
if (Array.isArray(webhook)) {
for (const w of webhook) {
@@ -90,8 +108,13 @@ async function webhookNotify(webhook: WebhookConfig, message: string) {
console.log(
'Sending webhook notification: ' + JSON.stringify(message) + ' to webhook ' + webhook.url
)
const realUrl = resolveWebhookUrl(webhook.url)
if (realUrl === undefined) {
console.log(`Webhook address not configured (${webhook.url}), skipping notification`)
return
}
try {
let url = webhook.url
let url = realUrl
let method = webhook.method
let headers = new Headers(webhook.headers as any)
let payloadTemplated: { [key: string]: string | number } = JSON.parse(
@@ -128,7 +151,7 @@ async function webhookNotify(webhook: WebhookConfig, message: string) {
}
console.log(
`Webhook finalized parameters: ${method} ${url}, headers ${JSON.stringify(
`Webhook finalized parameters: ${method} ${hideUrl(url, webhook.url, realUrl)}, headers ${JSON.stringify(
Object.fromEntries(headers.entries())
)}, body ${JSON.stringify(body)}`
)
@@ -142,7 +165,7 @@ async function webhookNotify(webhook: WebhookConfig, message: string) {
console.log('Webhook notification sent successfully, code: ' + resp.status)
}
} catch (e) {
console.log('Error calling webhook server: ' + e)
console.log('Error calling webhook server: ' + hideUrl(String(e), webhook.url, realUrl))
}
}
@@ -198,4 +221,5 @@ export {
webhookNotify,
formatStatusChangeNotification,
formatAndNotify,
setWebhookSecrets,
}