Skip to content

Cache NAR files for upto a year #727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions terraform/cache.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ resource "fastly_service_vcl" "cache" {
name = local.cache_domain
default_ttl = 86400

# https://registry.terraform.io/providers/fastly/fastly/latest/docs/resources/service_vcl#activation-and-staging
# activate should not be set to true when stage is also set to true. While this combination will not cause any harm to the service,
# there is no logical reason to both stage and activate every set of applied changes.
activate = false # set to true to deploy
stage = true # set to false to remove staging environment

backend {
address = "s3.amazonaws.com"
auto_loadbalance = false
Expand Down Expand Up @@ -174,6 +180,13 @@ resource "fastly_service_vcl" "cache" {
type = "REQUEST"
}

condition {
name = "is-nar"
priority = 10
statement = "req.url ~ \"^/nar/\""
type = "CACHE"
}

domain {
name = "cache.nixos.org"
}
Expand Down Expand Up @@ -239,6 +252,18 @@ resource "fastly_service_vcl" "cache" {
status = 404
}

cache_setting {
name = "cache-404"
cache_condition = "is-404"
ttl = 86400 # 1 day
}

cache_setting {
name = "cache-nar"
cache_condition = "is-nar"
ttl = 31557600 # the maximum. 1 year
}

# Authenticate Fastly<->S3 requests. See Fastly documentation:
# https://docs.fastly.com/en/guides/amazon-s3#using-an-amazon-s3-private-bucket
snippet {
Expand Down