Step 4: GitHub
Create the staging and production environments and give them the secrets and variables the Deploy and Infrastructure workflows pass to OpenTofu.
Goal: GitHub environments staging and production that hold everything the workflows need, with production behind a required reviewer.
4.1 Create the environments
Repository → Settings → Environments → New environment:
staging: allow themainbranch.production: add Required reviewers (one or more people) and allow onlymain.
Also protect main (Settings → Rules or Branches): pull requests and passing CI required.
4.2 Secrets (per environment)
Settings → Environments → (environment) → Add environment secret.
| Secret | Value | Required |
|---|---|---|
DIGITALOCEAN_ACCESS_TOKEN | Step 2.1 | Yes |
SPACES_ACCESS_KEY_ID | Step 2.2 | Yes |
SPACES_SECRET_ACCESS_KEY | Step 2.2 | Yes |
CLOUDFLARE_API_TOKEN | Step 2.5 | Yes |
TOFU_STATE_PASSPHRASE | This environment's passphrase (2.4) | Yes |
TOFU_ZONE_STATE_PASSPHRASE | The zone passphrase (same value in both environments) | Yes |
PUSH_CREDENTIALS_JSON | Product push credentials; leave unset until a product enables push | No |
MONITORING_REMOTE_WRITE_USERNAME | Remote-write user (step 10) | No |
MONITORING_REMOTE_WRITE_PASSWORD | Remote-write password | No |
The zone stack runs in the production environment, so production must hold TOFU_ZONE_STATE_PASSPHRASE too.
4.3 Variables (per environment)
Settings → Environments → (environment) → Add environment variable. List values are JSON.
| Variable | Example | Required |
|---|---|---|
TOFU_STATE_BUCKET | lynkoria-tofu-state-x1y2 | Yes |
DOCR_REGISTRY | your-registry | Yes |
CLOUDFLARE_ACCOUNT_ID | Account ID from the dashboard | Yes |
CLOUDFLARE_ZONE_ID | Zone ID of lynkoria.com | Yes |
CF_ACCESS_TEAM_DOMAIN | your-team.cloudflareaccess.com | With Access on |
ACCESS_ALLOWED_EMAILS | ["ana@example.com","ben@example.com"] | With Access on |
ENABLE_ACCESS | false only to run without Cloudflare Access (no MFA in front of the console; see manual deployment 1.6) | No (default true) |
OWNER_EMAIL | ana@example.com (gets the console owner role) | Yes |
SSH_KEY_FINGERPRINTS | ["3b:16:…"] | Yes |
ADMIN_IPS | ["203.0.113.10/32"] | Yes |
ALERT_EMAILS | ["oncall@example.com"] (DigitalOcean team members) | No |
API_DNS_PROXIED | false only for the first deploy (step 6) | No |
MONITORING_REMOTE_WRITE_URL | Prometheus remote-write URL | No |
The workflows map these to OpenTofu variables (TF_VAR_*); the mapping is visible in .github/workflows/deploy.yml.
4.4 What the workflows do with them
| Workflow | Trigger | Runs |
|---|---|---|
ci.yml | Every push and pull request | Tests, builds, tofu validate, mocked tofu test. No secrets |
infra.yml | Pull requests touching infra/opentofu/; manual | tofu plan (staging on PRs); manual plan for any stack; apply for the zone stack |
deploy.yml | CI green on main (staging); manual (either) | Build and scan images → tofu apply → smoke test → Pages publish |
Every run that touches state is serialized per stack with a concurrency group, so two applies never overlap.
Verify
Both environments list all required secrets and variables. A manual Actions → Infrastructure → Run workflow → stack: staging, action: plan reports that staging has not been deployed yet (that is expected before step 6) instead of a credentials error.
Next: Step 5: Zone stack.
Step 3: Configure
Review the per-environment OpenTofu settings — hostnames, product origins, LiveKit key references and sizes — and change them through a pull request.
Step 5: Zone stack
Apply the shared Cloudflare zone stack — TLS settings, per-environment origin-lock secrets and rules, API cache bypass, www redirect, DMARC and CAA.