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

Purge Fastly cache after release #3819

Closed
wants to merge 1 commit into from
Closed
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
51 changes: 49 additions & 2 deletions ci/sync-dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@

from __future__ import print_function

import sys
import json
import os
import subprocess
import shutil
import subprocess
import sys


def usage():
print("usage: sync-dist dev-to-local [--live-run]\n"
Expand Down Expand Up @@ -127,6 +129,49 @@ def run_s3cmd(command):

subprocess.check_call(s3cmd)


# Purge cached versions of rustup on Fastly
#
# When a new version of rustup is released, we need to purge old versions that
# have been cached on Fastly. Since rustup is distributed using the same CDN as
# the Rust releases, we selectively purge rustup artifacts using surrogate keys.
# https://www.fastly.com/documentation/guides/concepts/edge-state/cache/purging/#surrogate-key-purge
#
# Objects are tagged transparently by the Fastly service. This is configured in
# the Terragrunt module `release-distribution` in rust-lang/simpleinfra:
# https://github.com/rust-lang/simpleinfra/blob/master/terragrunt/modules/release-distribution/fastly-static.tf
def purge_fastly(env):
fastly_token = get_ssm_parameter(f"/{env}/rustup/fastly-api-token")
service_id = get_ssm_parameter(f"/{env}/rustup/fastly-service-id")

cmd = [
"curl", "-i", "-X", "POST",
f"https://api.fastly.com/service/{service_id}/purge/rustup",
"-H", f"Fastly-Key: {fastly_token}",
"-H", "Accept: application/json"
]

if live_run:
subprocess.check_call(cmd)
else:
print(f"skipping: {cmd}")


def get_ssm_parameter(parameter):
if not live_run:
return "[REDACTED]"

cmd = [
"aws", "ssm", "get-parameter",
"--with-decryption",
"--name", parameter
]

ssm_parameter = json.loads(subprocess.check_output(cmd))

return ssm_parameter["Parameter"]["Value"]


run_s3cmd(s3cmd)

# Next deal with the rustup-init.sh script and website
Expand Down Expand Up @@ -163,9 +208,11 @@ def run_s3cmd(command):
if command == "update-dev-release" and live_run:
run_s3cmd("aws cloudfront create-invalidation --distribution-id " +
"E30AO2GXMDY230 --paths /rustup/*".format(s3_bucket))
purge_fastly("dev")
# Invalidate dev.rustup.rs
run_s3cmd("aws cloudfront create-invalidation --distribution-id " +
"E3OQOQ34607Z0A --paths /*")
if command == "update-prod-release" and live_run:
run_s3cmd("aws cloudfront create-invalidation --distribution-id " +
"E3NZU1LCBHH4A4 --paths /rustup/*".format(s3_bucket))
purge_fastly("prod")
Loading