ops: add portal deployment and backup runbook

This commit is contained in:
Leon Tonhäuser committed 2026-08-10 21:47:53 +02:00
1 parent 21871bb9ff
commit f7481d4cde
7 files changed
+375

No files matched your search

@@ -0,0 +1,56 @@
import "server-only";
import { sql } from "drizzle-orm";
import { NextResponse } from "next/server";
import { db } from "@/db/client";
import { immichClient } from "@/modules/immich/client";
export type ReadinessCheckers = {
checkDb: () => Promise<boolean>;
checkImmich: () => Promise<boolean>;
};
export function createReadinessRoute(checkers?: Partial<ReadinessCheckers>) {
return async function GET() {
let dbOk = false;
let immichOk = false;
try {
dbOk = checkers?.checkDb
? await checkers.checkDb()
: await (async () => {
await db.execute(sql`SELECT 1`);
return true;
})();
} catch {
dbOk = false;
}
try {
immichOk = checkers?.checkImmich
? await checkers.checkImmich()
: await (async () => {
await immichClient.listAlbums();
return true;
})();
} catch {
immichOk = false;
}
const allReady = dbOk && immichOk;
const status = allReady ? "ok" : "not_ready";
const httpStatus = allReady ? 200 : 503;
return NextResponse.json(
{
status,
checks: {
database: dbOk ? "ok" : "failed",
immich: immichOk ? "ok" : "failed",
},
},
{ status: httpStatus },
);
};
}
+43
View File
@@ -0,0 +1,43 @@
import { describe, expect, test } from "vitest";
import { createReadinessRoute } from "./readiness-handler";
describe("GET /api/health/ready", () => {
test("returns 200 ok when database and Immich are healthy", async () => {
const route = createReadinessRoute({
checkDb: async () => true,
checkImmich: async () => true,
});
const response = await route();
expect(response.status).toBe(200);
await expect(response.json()).resolves.toEqual({
status: "ok",
checks: { database: "ok", immich: "ok" },
});
});
test("returns 503 when database is unreachable", async () => {
const route = createReadinessRoute({
checkDb: async () => false,
checkImmich: async () => true,
});
const response = await route();
expect(response.status).toBe(503);
await expect(response.json()).resolves.toEqual({
status: "not_ready",
checks: { database: "failed", immich: "ok" },
});
});
test("returns 503 when Immich is unavailable", async () => {
const route = createReadinessRoute({
checkDb: async () => true,
checkImmich: async () => false,
});
const response = await route();
expect(response.status).toBe(503);
await expect(response.json()).resolves.toEqual({
status: "not_ready",
checks: { database: "ok", immich: "failed" },
});
});
});
+3
View File
@@ -0,0 +1,3 @@
import { createReadinessRoute } from "./readiness-handler";
export const GET = createReadinessRoute();