Skip to content

Commit

Permalink
Merge pull request #421 from Turbo87/db-dumps
Browse files Browse the repository at this point in the history
crates-io: Add support for `db-dump.zip` files
  • Loading branch information
jdno authored Jun 10, 2024
2 parents 12be3fc + a0e6a04 commit 195b80c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
8 changes: 5 additions & 3 deletions terragrunt/modules/crates-io/compute-static/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ fn handle_request(config: &Config, mut request: Request) -> Result<Response, Err

// Database dump is too big to cache on Fastly
if request.get_url_str().ends_with("db-dump.tar.gz") {
redirect_db_dump_to_cloudfront(config)
redirect_to_cloudfront(config, "db-dump.tar.gz")
} else if request.get_url_str().ends_with("db-dump.zip") {
redirect_to_cloudfront(config, "db-dump.zip")
} else {
send_request_to_s3(config, &request)
}
Expand Down Expand Up @@ -192,8 +194,8 @@ fn rewrite_download_urls(request: &mut Request) {
///
/// As of early 2023, certain files are too large to be served through Fastly. One of those is the
/// database dump, which gets redirected to CloudFront.
fn redirect_db_dump_to_cloudfront(config: &Config) -> Result<Response, Error> {
let url = format!("https://{}/db-dump.tar.gz", config.cloudfront_url);
fn redirect_to_cloudfront(config: &Config, path: &str) -> Result<Response, Error> {
let url = format!("https://{}/{path}", config.cloudfront_url);
Ok(Response::temporary_redirect(url))
}

Expand Down
20 changes: 12 additions & 8 deletions terragrunt/modules/crates-io/s3-static.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ resource "aws_s3_bucket" "static" {
max_age_seconds = 3000
}

// Keep only the live db-dump.tar.gz and the previous day's version, removing
// Keep only the live db-dumps and the previous day's versions, removing
// all the other ones. This is needed because we don't want this file to be
// versioned, while all the other ones in the bucket should be versioned.
lifecycle_rule {
id = "purge-db-dump"
enabled = true
prefix = "db-dump.tar.gz"
dynamic "lifecycle_rule" {
for_each = toset(["db-dump.tar.gz", "db-dump.zip"])

content {
id = "purge-${replace(lifecycle_rule.key, ".", "-")}"
enabled = true
prefix = lifecycle_rule.key

abort_incomplete_multipart_upload_days = 1
noncurrent_version_expiration {
days = 1
abort_incomplete_multipart_upload_days = 1
noncurrent_version_expiration {
days = 1
}
}
}

Expand Down

0 comments on commit 195b80c

Please sign in to comment.