feat: add Cloudflare DNS provisioning and health checks
All checks were successful
Build & Release / build (push) Successful in 12s

This commit is contained in:
Ryan Moon
2026-04-03 20:42:43 -05:00
parent 16446a6257
commit 5d296fbb2b
5 changed files with 88 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ import { addCustomerChart, removeCustomerChart } from "../services/git";
import { setupCustomerDatabase, teardownCustomerDatabase } from "../services/db";
import { createNamespace, deleteNamespace, createSecret, createDockerRegistrySecret, patchSecret, getSecret, k8sFetch } from "../lib/k8s";
import { deleteSpacesObjects, getSpacesUsage } from "../services/spaces";
import { createCustomerDnsRecord, deleteCustomerDnsRecord, getCustomerDnsRecord, checkCustomerHealth } from "../services/cloudflare";
import { db } from "../db/manager";
import { config } from "../lib/config";
import { getCachedStatus, setCachedStatus } from "../lib/cache";
@@ -75,6 +76,7 @@ export async function customerRoutes(app: FastifyInstance) {
namespace: "pending",
secrets: "pending",
storage: "pending",
dns: "pending",
chart: "pending",
};
@@ -135,6 +137,9 @@ export async function customerRoutes(app: FastifyInstance) {
});
await setStep("storage", "done");
await createCustomerDnsRecord(slug);
await setStep("dns", "done");
addCustomerChart(slug, body.appVersion);
await setStep("chart", "done");
@@ -166,6 +171,10 @@ export async function customerRoutes(app: FastifyInstance) {
await deleteSpacesObjects(config.spacesKey, config.spacesSecret, config.spacesBucket, config.spacesRegion, `${slug}/`);
} catch {}
try {
await deleteCustomerDnsRecord(slug);
} catch {}
await Promise.all([
deleteDatabase(slug),
deleteDatabaseUser(slug),
@@ -220,7 +229,7 @@ export async function customerRoutes(app: FastifyInstance) {
}
// ── Infrastructure checks ─────────────────────────────────────────────────
const [dbCheck, sizeHistory, secrets] = await Promise.allSettled([
const [dbCheck, sizeHistory, secrets, dnsCheck, healthCheck] = await Promise.allSettled([
// Try connecting to the customer DB
(async () => {
const sql = postgres(config.doadminDbUrl.replace(/\/([^/?]+)(\?|$)/, `/${slug}$2`), { max: 1, connect_timeout: 5 });
@@ -239,10 +248,14 @@ export async function customerRoutes(app: FastifyInstance) {
LIMIT 30
`,
getSecret(namespace, "lunarfront-secrets").catch(() => null),
getCustomerDnsRecord(slug),
checkCustomerHealth(slug),
]);
const dbExists = dbCheck.status === "fulfilled" ? dbCheck.value : false;
const secretData = secrets.status === "fulfilled" ? secrets.value : null;
const dns = dnsCheck.status === "fulfilled" ? dnsCheck.value : { exists: false, proxied: false, ip: null };
const health = healthCheck.status === "fulfilled" ? healthCheck.value : { reachable: false, status: null };
const infra = {
database: { exists: dbExists },
spaces: {
@@ -250,6 +263,8 @@ export async function customerRoutes(app: FastifyInstance) {
bucket: secretData?.["spaces-bucket"] ?? null,
prefix: secretData?.["spaces-prefix"] ?? null,
},
dns,
health,
};
return reply.send({