From c48c5604579b68d6543de3c895f522e701340a67 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 2 Jun 2026 18:29:48 -0700 Subject: [PATCH] refactor(cloud): keep relay infra config unprefixed Co-authored-by: codex --- .github/workflows/deploy-relay.yml | 6 ++-- .github/workflows/release.yml | 12 +++---- docs/release.md | 8 ++--- docs/t3-cloud-clerk.md | 8 ++--- infra/relay/.env.example | 6 ++-- infra/relay/README.md | 10 +++--- infra/relay/src/worker.ts | 2 +- infra/relay/src/zone.test.ts | 50 ++++++++++++++++++++++++++++++ infra/relay/src/zone.ts | 4 +-- 9 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 infra/relay/src/zone.test.ts diff --git a/.github/workflows/deploy-relay.yml b/.github/workflows/deploy-relay.yml index 1ce9b21986..eec2c100f7 100644 --- a/.github/workflows/deploy-relay.yml +++ b/.github/workflows/deploy-relay.yml @@ -29,9 +29,9 @@ jobs: PLANETSCALE_ORGANIZATION: ${{ vars.PLANETSCALE_ORGANIZATION }} AXIOM_TOKEN: ${{ secrets.AXIOM_TOKEN }} AXIOM_ORG_ID: ${{ vars.AXIOM_ORG_ID }} - T3CODE_RELAY_DOMAIN: ${{ vars.T3CODE_RELAY_DOMAIN }} - T3CODE_RELAY_ZONE_NAME: ${{ vars.T3CODE_RELAY_ZONE_NAME }} - T3CODE_CLERK_PUBLISHABLE_KEY: ${{ vars.T3CODE_CLERK_PUBLISHABLE_KEY }} + RELAY_DOMAIN: ${{ vars.RELAY_DOMAIN }} + RELAY_ZONE_NAME: ${{ vars.RELAY_ZONE_NAME }} + CLERK_PUBLISHABLE_KEY: ${{ vars.CLERK_PUBLISHABLE_KEY }} CLERK_SECRET_KEY: ${{ secrets.CLERK_SECRET_KEY }} APNS_ENVIRONMENT: ${{ vars.APNS_ENVIRONMENT }} APNS_TEAM_ID: ${{ vars.APNS_TEAM_ID }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 50700d77ae..2f3171518d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -178,8 +178,8 @@ jobs: clerk_publishable_key: ${{ steps.public_config.outputs.clerk_publishable_key }} relay_url: ${{ steps.public_config.outputs.relay_url }} env: - T3CODE_RELAY_DOMAIN: ${{ vars.T3CODE_RELAY_DOMAIN }} - T3CODE_CLERK_PUBLISHABLE_KEY: ${{ vars.T3CODE_CLERK_PUBLISHABLE_KEY }} + RELAY_DOMAIN: ${{ vars.RELAY_DOMAIN }} + CLERK_PUBLISHABLE_KEY: ${{ vars.CLERK_PUBLISHABLE_KEY }} steps: - id: public_config name: Resolve production relay public config @@ -188,8 +188,8 @@ jobs: set -euo pipefail required=( - T3CODE_RELAY_DOMAIN - T3CODE_CLERK_PUBLISHABLE_KEY + RELAY_DOMAIN + CLERK_PUBLISHABLE_KEY ) missing=() for name in "${required[@]}"; do @@ -202,8 +202,8 @@ jobs: exit 1 fi - echo "clerk_publishable_key=$T3CODE_CLERK_PUBLISHABLE_KEY" >> "$GITHUB_OUTPUT" - echo "relay_url=https://$T3CODE_RELAY_DOMAIN" >> "$GITHUB_OUTPUT" + echo "clerk_publishable_key=$CLERK_PUBLISHABLE_KEY" >> "$GITHUB_OUTPUT" + echo "relay_url=https://$RELAY_DOMAIN" >> "$GITHUB_OUTPUT" build: name: Build ${{ matrix.label }} diff --git a/docs/release.md b/docs/release.md index c07fe8b0c7..4a4674f51e 100644 --- a/docs/release.md +++ b/docs/release.md @@ -56,10 +56,10 @@ Required repository secrets shared by relay deployments: Required `production` environment variables: -- `T3CODE_RELAY_DOMAIN` -- `T3CODE_RELAY_ZONE_NAME` -- `T3CODE_CLERK_PUBLISHABLE_KEY` -- `T3CODE_CLERK_CLI_OAUTH_CLIENT_ID` +- `RELAY_DOMAIN` +- `RELAY_ZONE_NAME` +- `CLERK_PUBLISHABLE_KEY` +- `CLERK_CLI_OAUTH_CLIENT_ID` - `APNS_ENVIRONMENT` - `APNS_TEAM_ID` - `APNS_KEY_ID` diff --git a/docs/t3-cloud-clerk.md b/docs/t3-cloud-clerk.md index 7f07a1460c..518fcbf613 100644 --- a/docs/t3-cloud-clerk.md +++ b/docs/t3-cloud-clerk.md @@ -34,11 +34,11 @@ client-facing values in their EAS environment. When either public value is absent, cloud UI is omitted. For a hosted relay deployment, copy `infra/relay/.env.example` to `infra/relay/.env`. The relay -deployment reads `T3CODE_RELAY_DOMAIN`, `T3CODE_RELAY_ZONE_NAME`, and -`T3CODE_CLERK_PUBLISHABLE_KEY` through Effect `Config`. There are no checked-in deployment defaults. +deployment reads `RELAY_DOMAIN`, `RELAY_ZONE_NAME`, and `CLERK_PUBLISHABLE_KEY` through Effect +`Config`. There are no checked-in deployment defaults. `bun --cwd infra/relay run deploy` invokes Alchemy from the relay directory, so Alchemy loads `infra/relay/.env`. After a successful deployment, the wrapper updates the repository-root `.env` -with the HTTPS relay URL derived from `T3CODE_RELAY_DOMAIN`. The relay still requires +with the HTTPS relay URL derived from `RELAY_DOMAIN`. The relay still requires `CLERK_SECRET_KEY` as an Alchemy secret. Never put `CLERK_SECRET_KEY` in a client application environment or commit it to the repository. @@ -56,7 +56,7 @@ In **Clerk Dashboard > JWT templates**, create a template with: | Claims | `{ "aud": "https://relay.example.com" }` | The `aud` value must be the deployed relay public URL, with no trailing slash. It must match the -client-facing `T3CODE_RELAY_URL` and the HTTPS URL derived from the deployment's `T3CODE_RELAY_DOMAIN`. If +client-facing `T3CODE_RELAY_URL` and the HTTPS URL derived from the deployment's `RELAY_DOMAIN`. If the relay domain changes, update both values and the JWT template. ## Desktop OAuth Redirect Allowlist diff --git a/infra/relay/.env.example b/infra/relay/.env.example index 7df5c58f2e..66a73eaf9f 100644 --- a/infra/relay/.env.example +++ b/infra/relay/.env.example @@ -1,15 +1,15 @@ # Required: Relay domain # Use the DNS zone managed in your Cloudflare account. Production deploys use # relay.; personal stages use relay-.. -T3CODE_RELAY_ZONE_NAME=example.com +RELAY_ZONE_NAME=example.com # Optional: Relay domain override # Set this only when the derived relay hostname should not be used. -# T3CODE_RELAY_DOMAIN=relay.example.com +# RELAY_DOMAIN=relay.example.com # Required: Clerk # Get both values from the Clerk Dashboard under API keys. -T3CODE_CLERK_PUBLISHABLE_KEY=pk_test_... +CLERK_PUBLISHABLE_KEY=pk_test_... CLERK_SECRET_KEY=sk_test_... # Required: Apple Push Notification service diff --git a/infra/relay/README.md b/infra/relay/README.md index 8271348928..21414063f6 100644 --- a/infra/relay/README.md +++ b/infra/relay/README.md @@ -100,8 +100,8 @@ bun --cwd infra/relay run deploy -- --env-file .env.local Alchemy defaults personal deployments to the `dev_$USER` stage. Relay custom domains apply the same DNS-safe sanitization as Alchemy physical resource names, so `prod` uses -`relay.` and `dev_julius` uses `relay-dev-julius.`. -`T3CODE_RELAY_DOMAIN` remains available as an explicit override. +`relay.` and `dev_julius` uses `relay-dev-julius.`. +`RELAY_DOMAIN` remains available as an explicit override. After a successful deploy, the wrapper updates the repository-root `.env` file with the derived relay URL. That makes subsequent source builds point at the relay that was just deployed without copying @@ -130,9 +130,9 @@ The repository must define these Actions secrets shared by relay deployments: The `production` GitHub environment must define these Actions variables: -- `T3CODE_RELAY_ZONE_NAME` -- `T3CODE_RELAY_DOMAIN` if overriding the derived production relay domain -- `T3CODE_CLERK_PUBLISHABLE_KEY` +- `RELAY_ZONE_NAME` +- `RELAY_DOMAIN` if overriding the derived production relay domain +- `CLERK_PUBLISHABLE_KEY` - `APNS_ENVIRONMENT` - `APNS_TEAM_ID` - `APNS_KEY_ID` diff --git a/infra/relay/src/worker.ts b/infra/relay/src/worker.ts index f5f07964a6..712e822e68 100644 --- a/infra/relay/src/worker.ts +++ b/infra/relay/src/worker.ts @@ -129,7 +129,7 @@ export default class Api extends Cloudflare.Worker()( const axiomTracesEndpoint = yield* observability.traces.otelTracesEndpoint; const clerkSecretKey = yield* Config.redacted("CLERK_SECRET_KEY"); - const clerkPublishableKey = yield* Config.string("T3CODE_CLERK_PUBLISHABLE_KEY"); + const clerkPublishableKey = yield* Config.string("CLERK_PUBLISHABLE_KEY"); const cloudMintPrivateKey = yield* cloudMintKeyPair.privateKey; const cloudMintPublicKey = yield* cloudMintKeyPair.publicKey; diff --git a/infra/relay/src/zone.test.ts b/infra/relay/src/zone.test.ts new file mode 100644 index 0000000000..f1da429e43 --- /dev/null +++ b/infra/relay/src/zone.test.ts @@ -0,0 +1,50 @@ +import * as Alchemy from "alchemy"; +import * as ConfigProvider from "effect/ConfigProvider"; +import * as Effect from "effect/Effect"; +import * as Layer from "effect/Layer"; +import { describe, expect, it } from "vitest"; + +import { RelayDeploymentConfig } from "./zone.ts"; + +function resolveRelayDeploymentConfig(env: Record, stage = "prod") { + return Effect.runPromise( + RelayDeploymentConfig.pipe( + Effect.provide( + Layer.mergeAll( + Layer.succeed(Alchemy.Stage, stage), + ConfigProvider.layer(ConfigProvider.fromEnv({ env })), + ), + ), + ), + ); +} + +describe("RelayDeploymentConfig", () => { + it("derives the relay domain from the unprefixed zone name", async () => { + await expect(resolveRelayDeploymentConfig({ RELAY_ZONE_NAME: "example.com" })).resolves.toEqual( + { + stage: "prod", + relayPublicDomain: "relay.example.com", + relayPublicOrigin: "https://relay.example.com", + managedEndpointZoneName: "example.com", + }, + ); + }); + + it("uses the unprefixed relay domain override", async () => { + await expect( + resolveRelayDeploymentConfig( + { + RELAY_ZONE_NAME: "example.com", + RELAY_DOMAIN: "relay.custom.example", + }, + "dev_julius", + ), + ).resolves.toEqual({ + stage: "dev_julius", + relayPublicDomain: "relay.custom.example", + relayPublicOrigin: "https://relay.custom.example", + managedEndpointZoneName: "example.com", + }); + }); +}); diff --git a/infra/relay/src/zone.ts b/infra/relay/src/zone.ts index f8063622b6..9a6e7a220e 100644 --- a/infra/relay/src/zone.ts +++ b/infra/relay/src/zone.ts @@ -9,8 +9,8 @@ import { relayPublicDomainForStage } from "./deploymentConfig.ts"; export const RelayDeploymentConfig = Effect.gen(function* () { const stage = yield* Alchemy.Stage; - const managedEndpointZoneName = yield* Config.nonEmptyString("T3CODE_RELAY_ZONE_NAME"); - const relayPublicDomainOverride = yield* Config.nonEmptyString("T3CODE_RELAY_DOMAIN").pipe( + const managedEndpointZoneName = yield* Config.nonEmptyString("RELAY_ZONE_NAME"); + const relayPublicDomainOverride = yield* Config.nonEmptyString("RELAY_DOMAIN").pipe( Config.option, ); const relayPublicDomain = Option.getOrElse(relayPublicDomainOverride, () =>