chore(repo): sync wireframe structure and references

This commit is contained in:
david committed 2026-08-08 03:09:06 +02:00
1 parent 05d2d5777f
commit d953a79e95
453 files changed
+36639 -621

No files matched your search

@@ -0,0 +1,84 @@
#!/usr/bin/env bash
#
# Disable Cloudflare compression for /videos/* so <video> stays byte-range
# serveable (Safari needs HTTP 206; a gzip/brotli stream can't be ranged, so
# Safari stalls). Idempotent: safe to run repeatedly — it only adds/updates
# our one rule and leaves any other compression rules untouched.
#
# Usage (token never lives in the repo — pass it at call time):
# CF_API_TOKEN=xxxxx CF_ZONE_ID=yyyyy ./scripts/cf-disable-video-compression.sh
#
# The token needs the "Zone > Config Rules / Rulesets: Edit" and
# "Zone > Cache Purge" permissions. Same secrets the deploy pipeline uses
# (CF_API_TOKEN / CF_ZONE_ID).
#
set -euo pipefail
: "${CF_API_TOKEN:?set CF_API_TOKEN (Cloudflare API token)}"
: "${CF_ZONE_ID:?set CF_ZONE_ID (Cloudflare zone id for hivegrid.de)}"
PATH_MATCH="${PATH_MATCH:-/videos/}"
PURGE_URL="${PURGE_URL:-https://hivegrid.de/videos/hero-test.mp4}"
DESC="hivegrid: no compression for ${PATH_MATCH} (Safari range playback)"
API="https://api.cloudflare.com/client/v4"
PHASE="http_response_compression"
auth=(-H "Authorization: Bearer ${CF_API_TOKEN}" -H "Content-Type: application/json")
say() { printf '\n\033[1m%s\033[0m\n' "$*"; }
die() { printf '\n\033[31mERROR:\033[0m %s\n' "$*" >&2; exit 1; }
# --- 1. read the current compression-phase ruleset (may not exist yet) --------
say "1/4 · Fetching current '${PHASE}' ruleset…"
resp="$(curl -s "${auth[@]}" \
"${API}/zones/${CF_ZONE_ID}/rulesets/phases/${PHASE}/entrypoint")"
if [ "$(jq -r '.success' <<<"$resp")" != "true" ]; then
# No entrypoint ruleset yet is fine — we'll create one. Any other error is fatal.
if jq -e '.errors[]? | select(.code==10007 or (.message|test("could not find";"i")))' <<<"$resp" >/dev/null 2>&1; then
existing_rules='[]'
else
die "Cloudflare API rejected the read: $(jq -c '.errors' <<<"$resp")"
fi
else
existing_rules="$(jq -c '.result.rules // []' <<<"$resp")"
fi
# --- 2. build the new rules array (drop any previous copy of ours, prepend) ---
say "2/4 · Building rules (keeping $(jq 'length' <<<"$existing_rules") existing, adding ours)…"
new_rule="$(jq -n --arg expr "starts_with(http.request.uri.path, \"${PATH_MATCH}\")" \
--arg desc "$DESC" '{
action: "compress_response",
expression: $expr,
description: $desc,
enabled: true,
action_parameters: { algorithms: [ { name: "none" } ] }
}')"
# Prepend ours; keep the others but strip CF's read-only fields (id/version/
# last_updated/ref) — Cloudflare rejects a PUT that echoes them back.
rules="$(jq -c --argjson r "$new_rule" --arg desc "$DESC" \
'[ $r ] + [ .[] | select(.description != $desc) | del(.id, .version, .last_updated, .ref) ]' \
<<<"$existing_rules")"
# --- 3. write it back ---------------------------------------------------------
say "3/4 · Updating ruleset…"
put="$(curl -s -X PUT "${auth[@]}" \
"${API}/zones/${CF_ZONE_ID}/rulesets/phases/${PHASE}/entrypoint" \
--data "$(jq -n --argjson rules "$rules" '{rules: $rules}')")"
[ "$(jq -r '.success' <<<"$put")" = "true" ] \
|| die "Ruleset update failed: $(jq -c '.errors' <<<"$put")"
echo " ✓ compression disabled for ${PATH_MATCH}"
# --- 4. purge the cached (gzipped) copy so the next hit re-fetches clean -------
say "4/4 · Purging cached copy of ${PURGE_URL}…"
purge="$(curl -s -X POST "${auth[@]}" \
"${API}/zones/${CF_ZONE_ID}/purge_cache" \
--data "$(jq -n --arg u "$PURGE_URL" '{files: [$u]}')")"
[ "$(jq -r '.success' <<<"$purge")" = "true" ] \
|| die "Cache purge failed: $(jq -c '.errors' <<<"$purge")"
echo " ✓ purged"
say "Done. Verify (expect 206, accept-ranges, NO content-encoding):"
echo " curl -sI -H 'Range: bytes=0-1023' ${PURGE_URL} | grep -iE 'HTTP|accept-ranges|content-encoding'"
@@ -0,0 +1,228 @@
#!/usr/bin/env node
const [, , command, ...args] = process.argv;
const apiUrl = (
process.env.SELECTED_COOLIFY_API_URL ||
process.env.COOLIFY_STAGING_API_URL ||
process.env.COOLIFY_API_URL ||
""
).replace(/\/+$/, "");
const token =
process.env.SELECTED_COOLIFY_TOKEN ||
process.env.COOLIFY_STAGING_TOKEN ||
process.env.COOLIFY_TOKEN ||
"";
const delayMs = Number(process.env.COOLIFY_DEPLOYMENT_POLL_MS || "5000");
const attempts = Number(process.env.COOLIFY_DEPLOYMENT_WAIT_ATTEMPTS || "90");
const apiTimeoutMs = Number(process.env.COOLIFY_API_TIMEOUT_MS || "20000");
const COOLIFY_CUID_PATTERN = /^[a-z][a-z0-9]{23}$/;
const OCI_DIGEST_PATTERN = /^sha256:[0-9a-f]{64}$/;
function fail(message) {
process.stderr.write(`${message}\n`);
process.exit(1);
}
async function coolify(path, options = {}) {
if (!apiUrl || !token) {
fail("Coolify API URL and token are required");
}
let response;
try {
response = await fetch(`${apiUrl}${path}`, {
...options,
headers: {
Authorization: `Bearer ${token}`,
Accept: "application/json",
...(options.body ? { "Content-Type": "application/json" } : {}),
...options.headers,
},
signal: AbortSignal.timeout(apiTimeoutMs),
});
} catch {
fail("Coolify API request failed or timed out");
}
const text = await response.text();
let payload = {};
if (text.trim()) {
try {
payload = JSON.parse(text);
} catch {
payload = { message: text.trim() };
}
}
if (!response.ok) {
fail(`Coolify API request failed with HTTP ${response.status}`);
}
return payload;
}
function deploymentStatus(payload) {
return String(
payload.status ||
payload.deployment?.status ||
payload.data?.status ||
"unknown"
).toLowerCase();
}
function deploymentUuid(payload) {
const value =
payload.deployments?.[0]?.deployment_uuid ||
payload.deployment_uuid ||
payload.uuid ||
payload.deployment?.uuid ||
payload.data?.deployment_uuid ||
payload.data?.uuid ||
"";
return typeof value === "string" ? value : "";
}
function requireCoolifyCuid(value, label) {
if (!COOLIFY_CUID_PATTERN.test(value)) {
fail(`${label} must be a 24-character Coolify identifier`);
}
}
function digestTag(digest) {
if (!OCI_DIGEST_PATTERN.test(digest)) {
fail("Image digest must be a lowercase sha256 OCI digest");
}
return digest.replace(":", "-");
}
function normalized(value) {
return typeof value === "string" ? value.trim() : "";
}
async function trigger(resourceUuid) {
requireCoolifyCuid(resourceUuid, "Coolify resource UUID");
const payload = await coolify(
`/deploy?uuid=${encodeURIComponent(resourceUuid)}&force=true`,
{ method: "POST" }
);
const queuedDeployments = Array.isArray(payload.deployments)
? payload.deployments
: [];
const matchingDeployment = queuedDeployments.find(
(deployment) => deployment?.resource_uuid === resourceUuid
);
const uuid = matchingDeployment?.deployment_uuid || deploymentUuid(payload);
if (!uuid) {
fail("Coolify deployment UUID was not returned by the deploy request");
}
requireCoolifyCuid(uuid, "Coolify deployment UUID");
process.stdout.write(uuid);
}
async function waitForDeployment(uuid, label) {
requireCoolifyCuid(uuid, "Coolify deployment UUID");
for (let attempt = 1; attempt <= attempts; attempt += 1) {
const payload = await coolify(`/deployments/${encodeURIComponent(uuid)}`);
const status = deploymentStatus(payload);
process.stdout.write(`${label} deployment status: ${status}\n`);
if (["finished", "success", "succeeded", "completed", "done"].includes(status)) {
return;
}
if (["failed", "error", "cancelled", "canceled"].includes(status)) {
fail(`${label} deployment failed`);
}
await new Promise((resolve) => setTimeout(resolve, delayMs));
}
fail(`${label} deployment did not finish in time`);
}
async function setRelease(resourceUuid, expectedImage, digest) {
requireCoolifyCuid(resourceUuid, "Coolify resource UUID");
if (!expectedImage) {
fail("Expected registry image is required");
}
const expectedTag = digestTag(digest);
const path = `/applications/${encodeURIComponent(resourceUuid)}`;
const before = await coolify(path);
if (
normalized(before?.uuid) !== resourceUuid ||
normalized(before?.docker_registry_image_name) !== expectedImage
) {
fail("Coolify website resource identity does not match the expected registry image");
}
await coolify(path, {
method: "PATCH",
body: JSON.stringify({
docker_registry_image_tag: expectedTag,
pre_deployment_command: "",
post_deployment_command: "",
}),
});
const after = await coolify(path);
if (
normalized(after?.uuid) !== resourceUuid ||
normalized(after?.docker_registry_image_name) !== expectedImage ||
normalized(after?.docker_registry_image_tag) !== expectedTag
) {
fail("Coolify website resource did not persist the expected registry digest");
}
}
async function assertRelease(resourceUuid, expectedImage, digest) {
requireCoolifyCuid(resourceUuid, "Coolify resource UUID");
const expectedTag = digestTag(digest);
const app = await coolify(`/applications/${encodeURIComponent(resourceUuid)}`);
if (
normalized(app?.uuid) !== resourceUuid ||
normalized(app?.docker_registry_image_name) !== expectedImage
) {
fail("Coolify website release proof resolved the wrong resource");
}
if (normalized(app?.docker_registry_image_tag) !== expectedTag) {
fail("Coolify website is not pinned to the expected registry digest");
}
if (normalized(app?.status).toLowerCase() !== "running:healthy") {
fail("Coolify website is not running healthy at the expected registry digest");
}
}
async function currentRelease(resourceUuid, expectedImage) {
requireCoolifyCuid(resourceUuid, "Coolify resource UUID");
if (!expectedImage) {
fail("Expected registry image is required");
}
const app = await coolify(`/applications/${encodeURIComponent(resourceUuid)}`);
if (
normalized(app?.uuid) !== resourceUuid ||
normalized(app?.docker_registry_image_name) !== expectedImage
) {
fail("Coolify website release proof resolved the wrong resource");
}
const tag = normalized(app?.docker_registry_image_tag);
if (!/^sha256-[0-9a-f]{64}$/.test(tag)) {
fail("Coolify website is not pinned to an immutable rollback digest");
}
process.stdout.write(tag.replace("-", ":"));
}
if (command === "trigger") {
await trigger(args[0] || "");
} else if (command === "wait") {
await waitForDeployment(args[0] || "", args[1] || "Coolify");
} else if (command === "set-release") {
await setRelease(args[0] || "", args[1] || "", args[2] || "");
} else if (command === "assert-release") {
await assertRelease(args[0] || "", args[1] || "", args[2] || "");
} else if (command === "current-release") {
await currentRelease(args[0] || "", args[1] || "");
} else {
fail(
"Usage: coolify-deploy.mjs trigger <resource-uuid> | wait <deployment-uuid> <label> | set-release <resource-uuid> <image> <digest> | assert-release <resource-uuid> <image> <digest> | current-release <resource-uuid> <image>"
);
}
@@ -0,0 +1,80 @@
import assert from "node:assert/strict";
import fs from "node:fs";
import test from "node:test";
const stageWorkflow = fs.readFileSync(
new URL("../.gitea/workflows/deploy.yml", import.meta.url),
"utf8"
);
const promoteWorkflow = fs.readFileSync(
new URL("../.gitea/workflows/promote.yml", import.meta.url),
"utf8"
);
const helper = fs.readFileSync(
new URL("./coolify-deploy.mjs", import.meta.url),
"utf8"
);
test("main builds once and deploys the exact digest to staging", () => {
assert.match(stageWorkflow, /name: Deploy staging/);
assert.match(stageWorkflow, /IMAGE_DIGEST=.*Manifest\.Digest/);
assert.equal(
(stageWorkflow.match(/coolify-deploy\.mjs set-release/g) || []).length,
1
);
assert.equal(
(stageWorkflow.match(/coolify-deploy\.mjs assert-release/g) || []).length,
1
);
assert.match(
stageWorkflow,
/imagetools create --prefer-index=false --tag "\$IMAGE:staging"/
);
assert.doesNotMatch(stageWorkflow, /Promote staging image to production/);
});
test("production promotion is input-free and resolves the live staging release", () => {
assert.match(promoteWorkflow, /name: Promote to production/);
assert.match(promoteWorkflow, /workflow_dispatch:\s*\n/);
assert.doesNotMatch(promoteWorkflow, /inputs:/);
assert.match(promoteWorkflow, /\/healthz\?__promotecheck=/);
assert.match(promoteWorkflow, /git rev-list origin\/main/);
assert.match(promoteWorkflow, /"\$IMAGE:\$STAGED_SHA"/);
assert.match(promoteWorkflow, /"\$IMAGE:staging"/);
assert.match(promoteWorkflow, /"\$IMAGE_DIGEST" != "\$STAGING_DIGEST"/);
assert.match(promoteWorkflow, /coolify-deploy\.mjs current-release/);
assert.match(promoteWorkflow, /PREVIOUS_PRODUCTION_DIGEST/);
});
test("promotion deploys the staged digest and purges Cloudflare", () => {
assert.equal(
(promoteWorkflow.match(/coolify-deploy\.mjs set-release/g) || []).length,
1
);
assert.equal(
(promoteWorkflow.match(/coolify-deploy\.mjs assert-release/g) || []).length,
2
);
assert.match(
promoteWorkflow,
/imagetools create --prefer-index=false --tag "\$IMAGE:main"/
);
assert.match(promoteWorkflow, /\/purge_cache/);
assert.match(promoteWorkflow, /payload\.success !== true/);
});
test("Coolify deploys use force deploy and immutable digest pins", () => {
assert.match(
helper,
/\/deploy\?uuid=\$\{encodeURIComponent\(resourceUuid\)\}&force=true/
);
assert.doesNotMatch(
helper,
/\/applications\/\$\{encodeURIComponent\(resourceUuid\)\}\/start/
);
assert.match(helper, /AbortSignal\.timeout\(apiTimeoutMs\)/);
assert.match(helper, /const OCI_DIGEST_PATTERN = \/\^sha256:/);
assert.match(helper, /docker_registry_image_tag: expectedTag/);
assert.match(helper, /async function currentRelease/);
assert.match(helper, /not pinned to an immutable rollback digest/);
});