Skip to content

Upload all content to s3 as public and immutable #1871

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

Merged
merged 1 commit into from
Nov 22, 2019

Conversation

jtescher
Copy link
Contributor

Adds cache control header with value public,max-age=31536000,immutable to all future crate and README uploads.

Fixes #1826

@rust-highfive
Copy link

r? @sgrif

(rust_highfive has picked a reviewer for you, use r? to override)

Copy link
Contributor

@smarnach smarnach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtescher Thanks for taking this on!

The uploaders is currently used for three purposes:

  • Upload rendered readme files.
  • Upload crates.
  • Upload database dumps.

The former two use the crate name and version in the path, so the content is indeed immutable. The latter, however, uses the same path every day, so marking it as immutable would be wrong.

I think the right solution for the database dumps would be to use the "Expires" header rather than "Cache-Control", and let it expire at approximately the time the next database dump is expected to be uploaded.

I believe that in the absence of any caching-related headers, CloudFront caches files for 24 hours by default. For the database dumps this can already be too long, so this is actually an existing issue unrelated to the ticket you are working on, so feel free to consider it out of scope. In any case, we need to excempt the database dumps from being marked as immutable and cached for a full year.

@jtescher
Copy link
Contributor Author

Ah thanks for the context @smarnach! I'll update this to set the appropriate headers for both scenarios.

@jtescher jtescher force-pushed the imutable-s3-uploads branch from faf1ff7 to dc3a221 Compare October 17, 2019 04:31
@jtescher
Copy link
Contributor Author

@smarnach I reworked the PR to be more conservative, currently only marking crate data immutable. It seems like rendered readme file data may also be altered at a later point via render-readmes.rs (or are the cloudfront caches purged currently when this occurs? If so I can add the header there too)

If you know the frequency at which the database dump job is run I'm happy to add the expires header as well.

Copy link
Contributor

@smarnach smarnach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! You are right that we may want to regenerate the readmes if we update the rendering code, so we shouldn't mark them as immutable. We could probably cache them for more than 24 hours, but let's go one step at a time.

The code in this PR looks good to me now, but I'd like to manually test it in a production-like setup first before merging. I'm not sure when I will have time to do so – it will probably have to wait a week or two.

@smarnach
Copy link
Contributor

I tested this on a setup similar to production, and everything is working as expected. There are two things currently blocking me from merging this:

  • We are currently making some changes to our infrastructure that are probably orthogonal to this change, but I would like to avoid making this change at the same time.
  • I need to figure out whether there are legal implications. We sometimes get requests to take down crates for legal reasons. With this change applied, these crates may still be cached for another year. We probably need to invalidate the file on the CloudFront edge caches in these cases, but I need to discuss this with the team.

Copy link
Contributor

@smarnach smarnach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are done with the CloudFront migration, and everything is working fine, so we can go ahead with this PR now.

@bors r+

@smarnach
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 22, 2019

📌 Commit dc3a221 has been approved by smarnach

@bors
Copy link
Contributor

bors commented Nov 22, 2019

⌛ Testing commit dc3a221 with merge 307930e...

bors added a commit that referenced this pull request Nov 22, 2019
Upload all content to s3 as public and immutable

Adds cache control header with value `public,max-age=31536000,immutable` to all future crate and README uploads.

Fixes #1826
@bors
Copy link
Contributor

bors commented Nov 22, 2019

☀️ Test successful - checks-travis
Approved by: smarnach
Pushing 307930e to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

static.crates.io cache control
5 participants