Skip to content
This repository has been archived by the owner on Jun 28, 2019. It is now read-only.

Purge Static Assets from CDN At The End of Deployment #49

Open
kingkool68 opened this issue Jul 17, 2018 · 0 comments
Open

Purge Static Assets from CDN At The End of Deployment #49

kingkool68 opened this issue Jul 17, 2018 · 0 comments

Comments

@kingkool68
Copy link
Contributor

kingkool68 commented Jul 17, 2018

Because we deploy to one production server at a time it is possible that static assets with a new version number can cache old versions of a resource. This is a race condition where a request is made from a server whose codebase was recently updated but ended up hitting a CDN endpoint where the new static asset hadn't been synced yet.

In other words /path/to/file.css?ver=1.2.3 is actually serving version 1.2.2 of the file. One way of fixing this is to make an API request to our CDN provider, bunnyCDN, to purge a list of assets.

A cURL request would look something like this:

curl --include \
     --request POST \
     --header "Content-Type: application/json" \
     --header "Accept: application/json" \
     --header "AccessKey: abc123" \
  'https://bunnycdn.com/api/purge?url=https%3A%2F%2Fexample.com'

This should happen near the end of deployment-production.sh after the static assets have been synced: https://github.com/spiritedmedia/systems/blob/3886746cc71dc953853ba8bd0df6e0a4461288b4/web-servers/spiritedmedia.com/deploy-production.sh

See https://bunnycdn.docs.apiary.io/#reference/0//api/statistics/post-purge-cache?console=1

The bunnyCDN API key can be found at https://bunnycdn.com/dashboard/account

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

No branches or pull requests

1 participant