Skip to content
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

Introduce staging binary cache to reduce our binary cache size #492

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 terraform-iam/.envrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use flake .#terraform
use flake .#terraform-iam

export AWS_CONFIG_FILE=$PWD/aws-config
export AWS_PROFILE=nixos-prod
Expand Down
132 changes: 132 additions & 0 deletions terraform/cache-bucket/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
variable "bucket_name" {
type = string
}

resource "aws_s3_bucket" "cache" {
provider = aws
bucket = var.bucket_name

lifecycle_rule {
enabled = true

transition {
days = 365
storage_class = "STANDARD_IA"
}
}

cors_rule {
allowed_headers = ["Authorization"]
allowed_methods = ["GET"]
allowed_origins = ["*"]
max_age_seconds = 3000
}
}

resource "aws_s3_bucket_public_access_block" "cache" {
bucket = aws_s3_bucket.cache.bucket

block_public_acls = false
block_public_policy = false
}

resource "aws_s3_bucket_object" "cache-nix-cache-info" {
provider = aws
depends_on = [aws_s3_bucket_public_access_block.cache]

bucket = aws_s3_bucket.cache.bucket
content_type = "text/x-nix-cache-info"
etag = filemd5("${path.module}/../cache-staging/nix-cache-info")
key = "nix-cache-info"
source = "${path.module}/../cache-staging/nix-cache-info"
}

resource "aws_s3_bucket_object" "cache-index-html" {
provider = aws
depends_on = [aws_s3_bucket_public_access_block.cache]

bucket = aws_s3_bucket.cache.bucket
content_type = "text/html"
etag = filemd5("${path.module}/../cache-staging/index.html")
key = "index.html"
source = "${path.module}/../cache-staging/index.html"
}

resource "aws_s3_bucket_policy" "cache" {
provider = aws
bucket = aws_s3_bucket.cache.id
depends_on = [aws_s3_bucket_public_access_block.cache]

# imported from existing
policy = <<EOF
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::${var.bucket_name}/*"
},
{
"Sid": "AllowUploadDebuginfoWrite",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::080433136561:user/s3-upload-releases"
},
"Action": [
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::${var.bucket_name}/debuginfo/*"
},
{
"Sid": "AllowUploadDebuginfoRead",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::080433136561:user/s3-upload-releases"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::${var.bucket_name}/*"
},
{
"Sid": "AllowUploadDebuginfoRead2",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::080433136561:user/s3-upload-releases"
},
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": "arn:aws:s3:::${var.bucket_name}"
}
]
}
EOF
}

resource "aws_s3_bucket_request_payment_configuration" "cache" {
provider = aws
bucket = aws_s3_bucket.cache.id
payer = "Requester"
}

output "bucket" {
value = aws_s3_bucket.cache.bucket
}

output "bucket_domain_name" {
value = aws_s3_bucket.cache.bucket_domain_name
}

output "bucket_regional_domain_name" {
value = aws_s3_bucket.cache.bucket_regional_domain_name
}

output "region" {
value = aws_s3_bucket.cache.region
}
7 changes: 7 additions & 0 deletions terraform/cache-bucket/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
aws = {
source = "registry.terraform.io/hashicorp/aws"
}
}
}
Loading
Loading