Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MaroonRides infrastructure: one Contabo VPS (`prod-server`) running NixOS and a
single-node k3s cluster (`prod`) reconciled by Flux.

- `tofu/`: Contabo instance + NixOS install, `maroonrides.app` DNS records,
the `web.maroonrides.app` Pages project and its GitHub deploy secrets,
the `web.maroonrides.app` Pages project, `tiles.maroonrides.app` R2 bucket and their GitHub deploy secrets,
Cloudflare tokens, R2 backup bucket, Tailscale policy, Flux webhooks
- `nixos/`: host configuration
- `kubernetes/`: Flux tree. `apps/base` is the platform, `apps/prod` the apps
Expand Down
11 changes: 6 additions & 5 deletions tofu/config/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ module "flux_webhooks" {
module "pages_web" {
source = "../modules/pages-web"

account_id = local.account_id
zone_id = local.zone_id
domain = local.domain
project_name = "maroonrides-web"
repository = "MaroonRides"
account_id = local.account_id
zone_id = local.zone_id
domain = local.domain
project_name = "maroonrides-web"
tiles_bucket_name = "maroonrides-map-tiles"
repository = "MaroonRides"
}
55 changes: 54 additions & 1 deletion tofu/modules/pages-web/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
locals {
hostname = "web.${var.domain}"
hostname = "web.${var.domain}"
tiles_hostname = "tiles.${var.domain}"
}

// Deployments are direct uploads from GitHub Actions, so the project has no git source.
Expand All @@ -24,6 +25,37 @@ resource "cloudflare_dns_record" "web" {
ttl = 1
}

// Pages ignores Range headers, which PMTiles needs, so the web build reads the basemap from R2.
resource "cloudflare_r2_bucket" "tiles" {
account_id = var.account_id
name = var.tiles_bucket_name
}

resource "cloudflare_r2_custom_domain" "tiles" {
account_id = var.account_id
bucket_name = cloudflare_r2_bucket.tiles.name
zone_id = var.zone_id
domain = local.tiles_hostname
enabled = true
}

resource "cloudflare_r2_bucket_cors" "tiles" {
account_id = var.account_id
bucket_name = cloudflare_r2_bucket.tiles.name

rules = [
{
allowed = {
methods = ["GET", "HEAD"]
origins = ["*"]
headers = ["Range", "If-Match"]
}
expose_headers = ["ETag", "Content-Range", "Content-Length"]
max_age_seconds = 86400
}
]
}

resource "cloudflare_account_token" "pages_deploy" {
account_id = var.account_id
name = "maroonrides pages deploy"
Expand All @@ -37,6 +69,15 @@ resource "cloudflare_account_token" "pages_deploy" {
resources = jsonencode({
"com.cloudflare.api.account.${var.account_id}" = "*"
})
},
{
effect = "allow"
permission_groups = [
{ id = "2efd5506f9c8494dacb1fa10a3e7d5b6" }, # Workers R2 Storage Bucket Item Write
]
resources = jsonencode({
"com.cloudflare.edge.r2.bucket.${var.account_id}_default_${cloudflare_r2_bucket.tiles.name}" = "*"
})
}
]
}
Expand All @@ -58,3 +99,15 @@ resource "github_actions_variable" "pages_project" {
variable_name = "CLOUDFLARE_PAGES_PROJECT"
value = cloudflare_pages_project.web.name
}

resource "github_actions_variable" "tiles_bucket" {
repository = var.repository
variable_name = "MAP_TILES_BUCKET"
value = cloudflare_r2_bucket.tiles.name
}

resource "github_actions_variable" "tiles_url" {
repository = var.repository
variable_name = "MAP_TILES_URL"
value = "https://${local.tiles_hostname}"
}
4 changes: 4 additions & 0 deletions tofu/modules/pages-web/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ variable "project_name" {
variable "repository" {
type = string
}

variable "tiles_bucket_name" {
type = string
}