diff --git a/.github/workflows/deploy-relay.yml b/.github/workflows/deploy-relay.yml new file mode 100644 index 0000000000..fdcb3e6c71 --- /dev/null +++ b/.github/workflows/deploy-relay.yml @@ -0,0 +1,61 @@ +name: Deploy T3 Cloud relay + +on: + push: + branches: + - main + workflow_dispatch: + +permissions: + contents: read + id-token: none + +concurrency: + group: relay-production + cancel-in-progress: false + +jobs: + deploy_relay: + name: Deploy production relay + runs-on: blacksmith-8vcpu-ubuntu-2404 + timeout-minutes: 15 + environment: + name: production + env: + CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + PLANETSCALE_API_TOKEN_ID: ${{ secrets.PLANETSCALE_API_TOKEN_ID }} + PLANETSCALE_API_TOKEN: ${{ secrets.PLANETSCALE_API_TOKEN }} + PLANETSCALE_ORGANIZATION: ${{ vars.PLANETSCALE_ORGANIZATION }} + AXIOM_TOKEN: ${{ secrets.AXIOM_TOKEN }} + AXIOM_ORG_ID: ${{ vars.AXIOM_ORG_ID }} + T3_RELAY_DOMAIN: ${{ vars.T3_RELAY_DOMAIN }} + T3_RELAY_ZONE_NAME: ${{ vars.T3_RELAY_ZONE_NAME }} + T3CODE_CLERK_PUBLISHABLE_KEY: ${{ vars.T3CODE_CLERK_PUBLISHABLE_KEY }} + CLERK_SECRET_KEY: ${{ secrets.CLERK_SECRET_KEY }} + CLERK_CLI_OAUTH_CLIENT_ID: ${{ vars.CLERK_CLI_OAUTH_CLIENT_ID }} + APNS_ENVIRONMENT: ${{ vars.APNS_ENVIRONMENT }} + APNS_TEAM_ID: ${{ vars.APNS_TEAM_ID }} + APNS_KEY_ID: ${{ vars.APNS_KEY_ID }} + APNS_BUNDLE_ID: ${{ vars.APNS_BUNDLE_ID }} + APNS_PRIVATE_KEY: ${{ secrets.APNS_PRIVATE_KEY }} + ALCHEMY_TELEMETRY_DISABLED: "1" + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Setup Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version-file: package.json + + - name: Setup Node + uses: actions/setup-node@v6 + with: + node-version-file: package.json + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Deploy production relay stage + run: bun --cwd infra/relay run deploy -- --stage prod --yes diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ab086ae6cd..cc901a2c58 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,10 +26,6 @@ permissions: contents: read id-token: none -env: - T3CODE_CLERK_PUBLISHABLE_KEY: ${{ vars.T3CODE_CLERK_PUBLISHABLE_KEY }} - T3_RELAY_URL: ${{ vars.T3_RELAY_URL }} - jobs: check_changes: name: Check for changes since last nightly @@ -170,12 +166,54 @@ jobs: --current-tag "${{ steps.release_meta.outputs.tag }}" \ --github-output - build: - name: Build ${{ matrix.label }} + relay_public_config: + name: Resolve T3 Cloud public config needs: preflight if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' }} + runs-on: blacksmith-8vcpu-ubuntu-2404 + timeout-minutes: 5 + environment: + name: production + outputs: + clerk_publishable_key: ${{ steps.public_config.outputs.clerk_publishable_key }} + relay_url: ${{ steps.public_config.outputs.relay_url }} + env: + T3_RELAY_DOMAIN: ${{ vars.T3_RELAY_DOMAIN }} + T3CODE_CLERK_PUBLISHABLE_KEY: ${{ vars.T3CODE_CLERK_PUBLISHABLE_KEY }} + steps: + - id: public_config + name: Resolve production relay public config + shell: bash + run: | + set -euo pipefail + + required=( + T3_RELAY_DOMAIN + T3CODE_CLERK_PUBLISHABLE_KEY + ) + missing=() + for name in "${required[@]}"; do + if [[ -z "${!name:-}" ]]; then + missing+=("$name") + fi + done + if (( ${#missing[@]} > 0 )); then + printf 'Missing required relay deployment configuration: %s\n' "${missing[*]}" >&2 + exit 1 + fi + + echo "clerk_publishable_key=$T3CODE_CLERK_PUBLISHABLE_KEY" >> "$GITHUB_OUTPUT" + echo "relay_url=https://$T3_RELAY_DOMAIN" >> "$GITHUB_OUTPUT" + + build: + name: Build ${{ matrix.label }} + needs: [preflight, relay_public_config] + if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.relay_public_config.result == 'success' }} runs-on: ${{ matrix.runner }} timeout-minutes: 30 + env: + T3CODE_CLERK_PUBLISHABLE_KEY: ${{ needs.relay_public_config.outputs.clerk_publishable_key }} + T3_RELAY_URL: ${{ needs.relay_public_config.outputs.relay_url }} strategy: fail-fast: false matrix: @@ -426,13 +464,16 @@ jobs: publish_cli: name: Publish CLI to npm - needs: [preflight, build] - if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.build.result == 'success' }} + needs: [preflight, relay_public_config, build] + if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.relay_public_config.result == 'success' && needs.build.result == 'success' }} runs-on: ubuntu-24.04 # blacksmith-8vcpu-ubuntu-2404 timeout-minutes: 10 permissions: contents: read id-token: write + env: + T3CODE_CLERK_PUBLISHABLE_KEY: ${{ needs.relay_public_config.outputs.clerk_publishable_key }} + T3_RELAY_URL: ${{ needs.relay_public_config.outputs.relay_url }} steps: - name: Checkout uses: actions/checkout@v6 @@ -581,11 +622,13 @@ jobs: deploy_web: name: Deploy hosted web app - needs: [preflight, release] - if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.release.result == 'success' }} + needs: [preflight, relay_public_config, release] + if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.relay_public_config.result == 'success' && needs.release.result == 'success' }} runs-on: blacksmith-8vcpu-ubuntu-2404 timeout-minutes: 10 env: + T3CODE_CLERK_PUBLISHABLE_KEY: ${{ needs.relay_public_config.outputs.clerk_publishable_key }} + T3_RELAY_URL: ${{ needs.relay_public_config.outputs.relay_url }} VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} @@ -749,10 +792,11 @@ jobs: if: | always() && !cancelled() && needs.preflight.result == 'success' && + needs.relay_public_config.result == 'success' && needs.release.result == 'success' && needs.deploy_web.result == 'success' && (needs.finalize.result == 'success' || needs.finalize.result == 'skipped') - needs: [preflight, release, deploy_web, finalize] + needs: [preflight, relay_public_config, release, deploy_web, finalize] runs-on: blacksmith-8vcpu-ubuntu-2404 timeout-minutes: 10 steps: diff --git a/docs/release.md b/docs/release.md index df9033218b..37051aecb1 100644 --- a/docs/release.md +++ b/docs/release.md @@ -7,9 +7,10 @@ This document covers the unified release workflow for stable and nightly desktop - Workflow: `.github/workflows/release.yml` - Triggers: - push tag matching `v*.*.*` for stable releases - - scheduled nightly at `09:00 UTC` + - scheduled nightly check every three hours - manual `workflow_dispatch` for either channel - Runs quality gates first: lint, typecheck, test. +- Reads the shared production T3 Cloud relay URL and Clerk publishable key before packaging clients. - Builds four artifacts in parallel for both channels: - macOS `arm64` DMG - macOS `x64` DMG @@ -29,6 +30,57 @@ This document covers the unified release workflow for stable and nightly desktop - nightly releases are aliased to the `nightly` hosted app channel - Signing is optional and auto-detected per platform from secrets. +## T3 Cloud relay deployment + +The relay is a shared control plane versioned separately from client releases. Stable and nightly +client builds must point at the same relay so users see the same linked environments when switching +release channels. + +`.github/workflows/deploy-relay.yml` deploys Alchemy stage `prod` on every push to `main`. It also +supports manual dispatch for retries. The release workflow reads the relay URL and Clerk +publishable key from the existing `production` GitHub Actions environment before building +desktop, CLI, or hosted web artifacts. + +Required repository variables shared by relay deployments: + +- `CLOUDFLARE_ACCOUNT_ID` +- `PLANETSCALE_ORGANIZATION` +- `AXIOM_ORG_ID` + +Required repository secrets shared by relay deployments: + +- `CLOUDFLARE_API_TOKEN` +- `PLANETSCALE_API_TOKEN_ID` +- `PLANETSCALE_API_TOKEN` +- `AXIOM_TOKEN` + +Required `production` environment variables: + +- `T3_RELAY_DOMAIN` +- `T3_RELAY_ZONE_NAME` +- `T3CODE_CLERK_PUBLISHABLE_KEY` +- `CLERK_CLI_OAUTH_CLIENT_ID` +- `APNS_ENVIRONMENT` +- `APNS_TEAM_ID` +- `APNS_KEY_ID` +- `APNS_BUNDLE_ID` + +Required `production` environment secrets: + +- `CLERK_SECRET_KEY` +- `APNS_PRIVATE_KEY` + +The account-scoped repository credentials are consumed by Alchemy while provisioning relay stages; they +are not bound into the relay Worker. The production deployment uses an Axiom personal access token, +so `AXIOM_ORG_ID` must accompany `AXIOM_TOKEN`. The `prod` stage owns the retained PlanetScale +database. Local personal stages provision isolated branches from it and are never deployed by CI. + +Developers deploy personal stages locally rather than through pull-request automation: + +```sh +bun --cwd infra/relay run deploy -- --stage "$USER" --env-file .env.local +``` + ## Hosted web app release deployment The hosted app is intentionally not deployed by Vercel's Git integration. The @@ -85,7 +137,7 @@ One-time Vercel dashboard setup: - Workflow: `.github/workflows/release.yml` - Triggers: - - scheduled every day at `09:00 UTC` + - scheduled check every three hours - manual `workflow_dispatch` with `channel=nightly` - Runs the same desktop quality gates and artifact matrix as the tagged release flow. - Publishes a GitHub prerelease only: diff --git a/infra/relay/README.md b/infra/relay/README.md index 828553020e..8d3525ed03 100644 --- a/infra/relay/README.md +++ b/infra/relay/README.md @@ -88,6 +88,63 @@ connectivity, and relay tracing resources. Copy [`infra/relay/.env.example`](./. `infra/relay/.env` and fill in the deployment-specific values before deploying. Alchemy loads that file from the relay directory. Runtime secrets include Clerk and APNs credentials. +The `prod` Alchemy stage owns the retained PlanetScale database and is the shared hosted relay for +stable and nightly clients. Every other stage references that database and provisions an isolated +PlanetScale branch and runtime role for local development, so deploy `prod` before creating +developer stages: + +```sh +bun --cwd infra/relay run deploy -- --stage prod +bun --cwd infra/relay run deploy -- --stage "$USER" --env-file .env.local +``` + +After a successful deploy, the wrapper updates the repository-root `.env` file with the relay URL +derived from `T3_RELAY_DOMAIN`. That makes subsequent source builds point at the relay that was just +deployed without copying the URL manually. + +### Deployment CI + +The relay is versioned separately from client releases. `.github/workflows/deploy-relay.yml` deploys +the shared Alchemy `prod` stage on every push to `main`, with a manual dispatch available for +retries. Stable and nightly release builds both resolve their static public config from the same +`production` GitHub environment. Pull requests do not deploy relay stages. Developers can +deploy personal non-production stages locally with any stage name other than `prod`. + +The repository must define these Actions variables shared by relay deployments: + +- `CLOUDFLARE_ACCOUNT_ID` +- `PLANETSCALE_ORGANIZATION` +- `AXIOM_ORG_ID` + +The repository must define these Actions secrets shared by relay deployments: + +- `CLOUDFLARE_API_TOKEN` +- `PLANETSCALE_API_TOKEN_ID` +- `PLANETSCALE_API_TOKEN` +- `AXIOM_TOKEN` + +The `production` GitHub environment must define these Actions variables: + +- `T3_RELAY_DOMAIN` +- `T3_RELAY_ZONE_NAME` +- `T3CODE_CLERK_PUBLISHABLE_KEY` +- `CLERK_CLI_OAUTH_CLIENT_ID` +- `APNS_ENVIRONMENT` +- `APNS_TEAM_ID` +- `APNS_KEY_ID` +- `APNS_BUNDLE_ID` + +The `production` GitHub environment must define these Actions secrets: + +- `CLERK_SECRET_KEY` +- `APNS_PRIVATE_KEY` + +The account-scoped repository credentials are consumed by Alchemy while provisioning relay stages; they +are not bound into the relay Worker. The production deployment uses an Axiom personal access token, +so `AXIOM_ORG_ID` must accompany `AXIOM_TOKEN`. The release workflow reads the production relay's +derived public URL and Clerk publishable key from the same environment for downstream desktop, CLI, +and hosted web builds. + See: - [T3 Cloud Clerk Setup](../../docs/t3-cloud-clerk.md) for Clerk keys, JWT templates, and waitlist