diff --git a/docs/adr/0001-decouple-ci-quality-gates-and-delegate-cd-to-cloudflare-pages.md b/docs/adr/0001-decouple-ci-quality-gates-and-delegate-cd-to-cloudflare-pages.md new file mode 100644 index 0000000..b9ca05f --- /dev/null +++ b/docs/adr/0001-decouple-ci-quality-gates-and-delegate-cd-to-cloudflare-pages.md @@ -0,0 +1,50 @@ +# ADR-0001: Decouple CI Quality Gates (Gitea Actions) and Delegate CD to Cloudflare Pages (GitHub Webhook) + +- Status: Accepted +- Date: 2026-11-02 +- Deciders: Fabian Andres Cortes (@kiskaadee) +- Consulted: Antigravity Assistant + +## Context and Problem Statement +The `corazoncp` ecosystem hosts its sovereign repositories on a self-hosted Gitea forge (`gitea.roadtotech.me`), automatically push-mirrored to GitHub (`github.com/corazoncp`). The first deliverable, `corazoncp-landing`, is a high-performance static web application built with Vite and Tailwind CSS v4, targeted for global edge hosting on Cloudflare Pages (`elcorazoncomoportal.com`). + +Initial pipeline configuration in `corazoncp-landing` combined both validation and continuous deployment in `.gitea/workflows/deploy.yaml` using `cloudflare/wrangler-action`. However, this setup encountered concrete operational and architectural frictions: +1. **Secrets Exposure & Principle of Least Privilege**: Deploying via Wrangler in CI requires storing a high-privilege `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` in repository secrets. +2. **Homelab Runner Bottleneck**: Running Wrangler inside local container runners (`homelab-runner` via `act`) repeatedly installed Node/pnpm/Wrangler dependencies from scratch, adding 9+ minutes of overhead and network egress per run. +3. **No Automatic Pull Request Previews**: Wrangler CLI deployments require custom scripts to manage preview aliases for pull requests. +4. **Client Handover Friction**: Azu will eventually take full ownership of the production site and domain. Coupling Cloudflare deployment tokens to the developer's personal Gitea secrets creates account entanglements during future client migration. + +How should Continuous Integration (CI) and Continuous Delivery (CD) be structured to preserve developer sovereignty, minimize secret exposure, and facilitate effortless client handover? + +## Decision Outcome +Chosen option: **Decouple CI and CD boundaries**: +- **Continuous Integration (Quality Gate) on Gitea Actions**: + - The self-hosted Gitea runner (`homelab-runner`) executes `.gitea/workflows/ci.yaml` on every branch push and pull request. + - Scope is strictly quality enforcement: Biome check (linter & formatter), unit/seam test suites (`node:test`), and static build verification (`pnpm build`). +- **Continuous Delivery (Edge Deployment) on Cloudflare Pages via GitHub**: + - Cloudflare Pages is connected directly via native OAuth webhook to the mirrored `corazoncp/corazoncp-landing` repository on GitHub. + - Cloudflare's global build fleet detects pushes to `main`, runs `pnpm build`, and serves `dist/` globally with automatic cache invalidation and zero runner overhead on the homelab. + - Pull requests mirrored to GitHub automatically receive isolated preview URLs (`.elcorazoncomoportal.pages.dev`). +- **Zero Deployment Credentials in Git / CI**: + - No `CLOUDFLARE_API_TOKEN`, `CLOUDFLARE_ACCOUNT_ID`, or registrar (Spaceship) API keys may ever be committed or stored in Gitea repository secrets. +- **Portable Edge Configuration in Version Control**: + - Security headers (CSP, HSTS, X-Frame-Options) and routing rules are tracked in [`public/_headers`](file:///home/kiskaadee/Projects/active/corazoncp/corazoncp-landing/public/_headers) and [`public/robots.txt`](file:///home/kiskaadee/Projects/active/corazoncp/corazoncp-landing/public/robots.txt), which Cloudflare Pages natively evaluates, ensuring zero dashboard lock-in. + +## Consequences +- **Positive**: + - **Zero credential leakage risk**: No long-lived Cloudflare or registrar tokens exist in CI/CD runner environments. + - **Homelab resource preservation**: The local homelab runner only runs fast lint and test jobs (10–15 seconds); it does not build or upload multi-megabyte image assets to Cloudflare. + - **Instant PR Previews**: Branch previews are generated natively by Cloudflare Pages out of the box. + - **Effortless Client Handover**: When transferring ownership to Azu, she only needs an invite to the `corazoncp` GitHub organization and Cloudflare Pages project. No Gitea secrets need rotation or re-keying. +- **Negative**: + - **Multi-Hop Deployment Latency**: Production deployments depend on Gitea's push mirror reaching GitHub before Cloudflare triggers (~30–60 seconds sync latency). + - **Vendor Dependency for Delivery**: CD requires GitHub and Cloudflare availability, while CI remains 100% sovereign. + +## Alternatives Considered +- **All-in-One Gitea Pipeline with Wrangler**: Rejected due to token security risk, homelab runner load, and lack of automatic branch preview links. +- **Pure GitHub Actions**: Rejected because Gitea is the primary development forge and source of truth for issues, pull requests, and quality validation. + +## Related Documents +- Infrastructure & Handover Guide: [`corazoncp/docs/infra/dns-and-handover.md`](../infra/dns-and-handover.md) +- Landing Page Brief: [`corazoncp-landing/docs/specs/landing-page-brief.md`](../../corazoncp-landing/docs/specs/landing-page-brief.md) +- Tracking Issue: `corazoncp-landing#10` diff --git a/docs/infra/dns-and-handover.md b/docs/infra/dns-and-handover.md new file mode 100644 index 0000000..96c69aa --- /dev/null +++ b/docs/infra/dns-and-handover.md @@ -0,0 +1,64 @@ +# Infrastructure Specification: DNS, Edge Routing & Client Handover Protocol + +- Domain: `elcorazoncomoportal.com` +- Registrar: Spaceship +- Edge CDN & Hosting: Cloudflare Pages (`elcorazoncomoportal.pages.dev`) +- Upstream Organization: `corazoncp` (Gitea `gitea.roadtotech.me` push-mirrored to GitHub `github.com/corazoncp`) + +--- + +## 1. DNS Zone Inventory + +To prevent DNS record loss or misconfiguration during future account migrations, all authoritative DNS records for `elcorazoncomoportal.com` are documented below: + +| Type | Name / Host | Target / Value | Proxy Status | Purpose | +| :--- | :--- | :--- | :--- | :--- | +| **CNAME** | `@` (apex) | `elcorazoncomoportal.pages.dev` | Proxied (Orange Cloud) | Production landing page root | +| **CNAME** | `www` | `elcorazoncomoportal.pages.dev` | Proxied (Orange Cloud) | Canonical www redirect / alias | +| **TXT** | `_headers` | *(evaluated natively by Cloudflare Pages via `public/_headers`)* | N/A | CSP, HSTS, frame options | + +> **Note on Mail / Communication Services**: When Azu provisions corporate email (e.g. Google Workspace, Zoho Mail, or Proton Mail), MX, SPF, DKIM, and DMARC TXT records must be recorded in this table before activation. + +--- + +## 2. Cloudflare Pages Build Contract + +Cloudflare Pages connects to the GitHub repository `corazoncp/corazoncp-landing` with the following canonical settings: + +- **Framework preset**: `Vite` (or None) +- **Build command**: `pnpm build` +- **Build output directory**: `dist` +- **Root directory**: `/` +- **Environment variables**: + - `NODE_VERSION`: `22` + - `PNPM_VERSION`: `10` + +--- + +## 3. Client Handover Protocol (Transferring Ownership to Azu) + +When Azu is ready to take sovereign ownership of the platform, follow this zero-downtime handover protocol: + +### Phase 1: Identity & Organization Invitation +1. Azu creates a personal or corporate account on GitHub. +2. Invite Azu's GitHub account as an **Owner** of the GitHub organization `corazoncp` (`https://github.com/orgs/corazoncp/people`). +3. Azu creates her own account on [Cloudflare](https://dash.cloudflare.com/sign-up). + +### Phase 2: Dual-Option Cutover + +#### Option A: Super Administrator Delegation (Zero Nameserver Cutover) +1. In the current Cloudflare account, navigate to **Manage Account $\rightarrow$ Members**. +2. Invite Azu as a **Super Administrator**. +3. Azu enters her billing details under Account $\rightarrow$ Billing. +4. Remove developer credentials from the account. +*Downtime: 0 seconds. DNS changes: 0.* + +#### Option B: Full Account & Nameserver Migration +1. In Azu's Cloudflare account, click **Add a Domain** $\rightarrow$ `elcorazoncomoportal.com`. +2. Cloudflare will assign two unique nameservers (e.g., `carol.ns.cloudflare.com` and `dave.ns.cloudflare.com`). +3. Import the DNS Zone records documented in Section 1 into Azu's Cloudflare Zone. +4. In Azu's Cloudflare account, navigate to **Workers & Pages** $\rightarrow$ **Create Application** $\rightarrow$ **Pages** $\rightarrow$ **Connect to Git**. +5. Select GitHub Organization `corazoncp` and repository `corazoncp-landing`. Configure the build contract from Section 2. +6. Under **Custom Domains**, attach `elcorazoncomoportal.com` and `www.elcorazoncomoportal.com`. +7. At domain registrar (Spaceship), update the domain nameservers from the old Cloudflare nameservers to Azu's new Cloudflare nameservers. +*Because Cloudflare pre-provisions SSL certificates before nameserver validation, visitors experience zero interruption during DNS propagation.*