Appearance
Cloudflare & GitHub Actions Setup Guide
This guide walks you through setting up Cloudflare and GitHub Actions for the deployment pipeline (Cloudflare Pages + Workers), using split workflows and separate staging/production resources.
Overview
This repo uses separate workflows per deployable:
- Relay (Cloudflare Worker):
examples/relay-cloudflare-worker - Docs site (Cloudflare Pages):
examples/tatchi-docs - Wallet iframe (Cloudflare Pages):
examples/vite - Optional: publish signed SDK runtime bundles to Cloudflare R2 (artifact storage)
What Gets Deployed
Cloudflare Pages/Workers mappings
w3a-wallet-iframe-prod→wallet.web3authn.orgw3a-wallet-iframe-staging→wallet-staging.web3authn.orgw3a-tatchi-docs-prod→tatchi.xyzw3a-tatchi-docs-staging→staging.tatchi.xyzw3a-relay-prod→relay.tatchi.xyzw3a-relay-staging→relay-staging.tatchi.xyz
GitHub Environments
We use two GitHub Environments, each with its own secrets + vars:
staging(deploys fromdev)production(deploys frommain)
GitHub Actions workflows
.github/workflows/deploy-relay-staging.yml(pushdev) → deployw3a-relay-staging+ configure Email Routing.github/workflows/deploy-relay-prod.yml(pushmain) → deployw3a-relay-prod+ configure Email Routing.github/workflows/deploy-docs-staging.yml(pushdev) → deploy Pagesw3a-tatchi-docs-staging.github/workflows/deploy-docs-prod.yml(pushmain) → deploy Pagesw3a-tatchi-docs-prod.github/workflows/deploy-wallet-iframe-staging.yml(pushdev) → deploy Pagesw3a-wallet-iframe-staging.github/workflows/deploy-wallet-iframe-prod.yml(pushmain) → deploy Pagesw3a-wallet-iframe-prod.github/workflows/publish-sdk-r2.yml(optional) → publishsdk/distto R2 aftercisucceeds (or via manual dispatch)
R2 Storage
- Path:
sdk/dist/**+manifest.json+manifest.sig - Structure:
releases/<git-sha>/...(commit-specific)releases/<tag>/...(tagged releases)
One-Time Cloudflare Setup
1. Account Setup
Create Cloudflare Account
- Go to Cloudflare Sign Up and create an account
- Complete account verification
Get Account ID
- Go to Workers & Pages section in Cloudflare dashboard
- Copy your Account ID from the right sidebar
- Reference: Cloudflare Account ID Documentation
2. API Token Setup
Create an API Token with the following permissions:
- Go to: My Profile → API Tokens → Create Token
- Use: "Custom token" template
- Permissions:
- Workers Scripts: Edit
- Pages: Edit
- R2: Edit (only if you use
publish-sdk-r2.yml) - Email Routing: Edit (only if you want the relay deploy workflow to manage Email Routing rules)
- Account Resources: Include - All accounts
- Zone Resources: Include - All zones
- Copy the token (you'll need this for
CLOUDFLARE_API_TOKEN) - Reference: Cloudflare API Tokens Documentation
3. R2 Storage Setup
Create R2 Bucket
- Go to R2 Object Storage in Cloudflare dashboard
- Click Create bucket
- Name it (e.g.,
w3a-sdk) - Choose location (recommend US East for global access)
- Reference: R2 Getting Started Guide
Generate S3 Access Keys
- Go to Manage R2 API tokens
- Click Create API token
- Permissions: Object Read & Write
- Bucket: Your bucket name
- Copy the credentials:
- Access Key ID
- Secret Access Key
- Reference: R2 API Tokens Documentation
Get R2 Endpoint
- Your endpoint will be:
https://<account_id>.r2.cloudflarestorage.com - Replace
<account_id>with your actual Account ID - Reference: R2 S3 API Documentation
- Your endpoint will be:
GitHub Secrets Configuration
Add these secrets to your GitHub Environments (staging and production). The workflows read secrets/vars from the environment they run in.
Go to: Repository → Settings → Environments → pick staging / production.
Worker/Pages Secrets
CLOUDFLARE_API_TOKEN=<your_api_token>
CLOUDFLARE_ACCOUNT_ID=<your_account_id>
CLOUDFLARE_ZONE_ID=<your_zone_id> # required if using Email Routing automation in relay deploy workflowsR2 Storage Secrets
R2_ENDPOINT=https://<account_id>.r2.cloudflarestorage.com
R2_BUCKET=<your_bucket_name>
R2_ACCESS_KEY_ID=<your_access_key_id>
R2_SECRET_ACCESS_KEY=<your_secret_access_key>Optional GitHub Secrets
THRESHOLD_ED25519_MASTER_SECRET_B64U(only if using threshold signing; the relay deploy workflows can push it into the Worker as a Wrangler secret)
Cloudflare Pages Project Setup
1. Create Pages Projects (One-time)
You can either:
- Auto-create: Let the first deployment create them automatically
- Manual create: Create them beforehand for more control
Manual Creation:
bash
# Install Wrangler CLI
npm install -g wrangler
# Login to Cloudflare
wrangler login
# Create Pages projects
wrangler pages project create w3a-tatchi-docs-staging
wrangler pages project create w3a-tatchi-docs-prod
wrangler pages project create w3a-wallet-iframe-staging
wrangler pages project create w3a-wallet-iframe-prodReference: Wrangler CLI Documentation
2. Set the Production branch (important)
Cloudflare Pages treats deployments on the “Production branch” as Production (custom domains attach here).
For this repo’s setup:
- For the
*-stagingPages projects, set Production branch todev. - For the
*-prodPages projects, set Production branch tomain.
This avoids “Preview” deployments for staging when you push to dev.
GitHub Environment variables (build-time Vite vars)
Set these as Environment variables (not secrets) in staging / production:
VITE_WALLET_ORIGIN- staging:
https://wallet-staging.web3authn.org - production:
https://wallet.web3authn.org
- staging:
VITE_RELAYER_URL- staging:
https://relay-staging.tatchi.xyz - production:
https://relay.tatchi.xyz
- staging:
VITE_RELAYER_ACCOUNT_IDVITE_NEAR_NETWORK,VITE_NEAR_RPC_URL,VITE_NEAR_EXPLORERVITE_WEBAUTHN_CONTRACT_IDVITE_RP_ID_BASE- Optional (SDK defaults):
VITE_WALLET_SERVICE_PATH(defaults to/wallet-service),VITE_SDK_BASE_PATH(defaults to/sdk) RECOVER_EMAIL_RECIPIENT(required by relay deploy workflows for Email Routing)
Worker secrets and vars (Cloudflare-side)
The relay Worker requires runtime secrets that are stored in Cloudflare (not GitHub):
- Secrets (Wrangler):
RELAYER_PRIVATE_KEY,SHAMIR_P_B64U,SHAMIR_E_S_B64U,SHAMIR_D_S_B64U - Optional secrets:
THRESHOLD_ED25519_MASTER_SECRET_B64U - Vars (
wrangler.tomlorwrangler deploy --var ...):EXPECTED_ORIGIN,EXPECTED_WALLET_ORIGIN,WEBAUTHN_CONTRACT_ID,NEAR_RPC_URL, etc.
Set secrets for each environment:
bash
cd examples/relay-cloudflare-worker
pnpm install
wrangler login
# Production
wrangler secret put RELAYER_PRIVATE_KEY --env production
wrangler secret put SHAMIR_P_B64U --env production
wrangler secret put SHAMIR_E_S_B64U --env production
wrangler secret put SHAMIR_D_S_B64U --env production
# Staging
wrangler secret put RELAYER_PRIVATE_KEY --env staging
wrangler secret put SHAMIR_P_B64U --env staging
wrangler secret put SHAMIR_E_S_B64U --env staging
wrangler secret put SHAMIR_D_S_B64U --env stagingDeploying
Once Cloudflare + GitHub Environments are set up:
- Push to
devto deploy staging (w3a-*-staging) - Push to
mainto deploy production (w3a-*-prod)
You can also run any workflow manually via workflow_dispatch.
Notes on R2
Cloudflare Pages is already CDN-backed. The deploy workflows copy the SDK runtime assets into the Pages output under /sdk/*, so staging/prod sites work without R2.
R2 publishing (publish-sdk-r2.yml) is still useful if you want a signed, immutable artifact store (for external distribution or future “load SDK assets from R2” setups).