Deployment is managed in two parts:
- Underlying core and environment-specific infrastructure is defined in Terraform, and needs to be created manually (using
terraform
commands) - Repeated deployments are managed via Helm, and executed by the CI
The Terraform for this app is split into three segments:
core
- Core infrastructure for CI and shared resources for all environmentsenv
- Environment-specific resources
These need to be applied in the above order, because of dependencies.
You will need the following tools:
- google-cloud-sdk
- terraform
And you'll need access to the Terraform state encryption key.
These are one-time "singleton" resources. Resources include:
- Google Cloud OIDC creds (see here)
- GCS static assets bucket
- GitHub Actions secrets to auth with GCP
cd deploy/terraform/core
- Create a new file
secrets.auto.tfvars
- Generate a GitHub Personal Access Token
- Go here
- Create a new token for the Beta Spray repo
- Give it these scopes:
- Administration: R/W (for branch protection)
- Environments: R/W
- Secrets: R/W
- Variables: R/W
- Add
github_token = "<token>"
to thetfvars
file
- Auth to Google with
gcloud auth login
terraform init -backend-config encryption_key="<key>"
- MAKE SURE TO INCLUDE THE SPACE AT THE BEGINNING, so your shell doesn't store the key in command history
Then apply changes with:
terraform apply
These are per-environment resources. This will need to be executed once for each deployment environment (development, production, etc.). Resources include:
- DNS rules in Cloudflare
- TLS cert
- GCS Media bucket
- GCP Service Account to enable the API pod to access GCS
- GitHub Actions environment and secrets
Since this project needs to be deployed multiple times, we use Terraform workspaces to manage each environment. The name of the workspace will match
This setup only needs to be run once, then these creds can be used for all environments.
- Create a new file
secrets.auto.tfvars
- Generate a Cloudflare API Token
- Go here
- Use the "Edit zone DNS" template
- Add
betaspray.net
as the only accessible zone - Create the key
- Add
cloudflare_api_token = "<token>"
to thetfvars
file
- Access your Cloudflare Origin CA key
- Go here
- Click "View" for the Origin CA Key
- Add
cloudflare_origin_ca_key = "<key>"
to thetfvars
file
- Follow the steps in the Core section above to create a GitHub token (you can also re-use that token)
- Add
github_token = "<token>"
to thetfvars
file
- Add
- Create a Google OAuth client (This should be automated but Google doesn't support it :/)
- Go here
- Follow the steps in the main README from here if you get lost
- Auth to Google with
gcloud auth login
terraform init -backend-config encryption_key="<key>"
- MAKE SURE TO INCLUDE THE SPACE AT THE BEGINNING, so your shell doesn't store the key in command history
Each environment needs its own Terraform workspace. You can use terraform workspace list
to see all the current environments (excluding default
). Each workspace also has a corresponding tfvars
file, which defines environment-specific variables. The one thing you need to manually configure per environment is to add its paths to the Google OAuth client.
Each environment needs to be deployed separately, like so:
terraform workspace select <environment>
terraform apply -var-file <environment>.tfvars
Once all the infrastructure is created with Terraform, the CI will automatically handle deployment. This is all defined in .github/workflows/deploy.yml
. The deployment environment is set manually when you run it, or based on branch name for automated runs.
Generally you shouldn't need to run the deploy commands manually. If you do, you can figure it out on your own, then add instructions here :)