Skip to content

Commit 4badd82

Browse files
authored
[doc build] use rayci.anyscale.dev to fetch doc build cache (#57877)
so that we are not tied to using public s3 buckets Signed-off-by: Lonnie Liu <lonnie@anyscale.com>
1 parent 65bb37d commit 4badd82

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

doc/load_doc_cache.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import boto3
2-
import botocore
31
import subprocess
42
import tarfile
53
import os
6-
import click
7-
from botocore import UNSIGNED
8-
from botocore.client import Config
94
import time
5+
6+
import click
107
import requests
118

12-
S3_BUCKET = "ray-ci-results"
13-
DOC_BUILD_DIR_S3 = "doc_build"
149
LAST_BUILD_CUTOFF = 3 # how many days ago to consider a build outdated
1510
PENDING_FILES_PATH = "pending_files.txt"
1611
ENVIRONMENT_PICKLE = "_build/doctrees/environment.pickle"
17-
DOC_BUILD_S3_URL = "https://ray-ci-results.s3.us-west-2.amazonaws.com/doc_build"
12+
DOC_BUILD_CACHE_URL = "https://rayci.anyscale.dev/ray/doc/build-cache"
13+
14+
15+
def _build_cache_url(commit: str):
16+
return f"{DOC_BUILD_CACHE_URL}/{commit}.tgz"
1817

1918

2019
def find_latest_master_commit():
@@ -34,33 +33,32 @@ def find_latest_master_commit():
3433
.split("\n")
3534
)
3635
for commit in latest_commits:
37-
result = requests.head(f"{DOC_BUILD_S3_URL}/{commit}.tgz")
38-
if result.status_code == 200:
39-
return commit
36+
with requests.head(_build_cache_url(commit), allow_redirects=True) as response:
37+
if response.status_code == 200:
38+
return commit
4039
raise Exception(
41-
"No cache found for latest master commit."
40+
"No cache found for latest master commit. "
4241
"Please merge with upstream master or use 'make develop'."
4342
)
4443

4544

46-
def fetch_cache_from_s3(commit, target_file_path):
45+
def fetch_cache(commit, target_file_path):
4746
"""
48-
Fetch doc cache archive from ray-ci-results S3 bucket
47+
Fetch doc cache archive from rayci.anyscale.dev
4948
5049
Args:
5150
commit: The commit hash of the doc cache to fetch
5251
target_file_path: The file path to save the doc cache archive
5352
"""
54-
# Create an S3 client
55-
s3 = boto3.client("s3", config=Config(signature_version=UNSIGNED))
56-
s3_file_path = f"{DOC_BUILD_DIR_S3}/{commit}.tgz"
57-
try:
58-
print(f"Fetching doc cache from commit {commit}...")
59-
s3.download_file(S3_BUCKET, s3_file_path, target_file_path)
60-
print(f"Successfully downloaded {s3_file_path} to {target_file_path}")
61-
except botocore.exceptions.ClientError as e:
62-
print(f"Failed to download {s3_file_path} from S3: {str(e)}")
63-
raise e
53+
54+
with requests.get(
55+
_build_cache_url(commit), allow_redirects=True, stream=True
56+
) as response:
57+
response.raise_for_status()
58+
with open(target_file_path, "wb") as f:
59+
for chunk in response.iter_content(chunk_size=8192):
60+
f.write(chunk)
61+
print(f"Successfully downloaded {target_file_path}")
6462

6563

6664
def extract_cache(cache_path: str, doc_dir: str):
@@ -149,8 +147,9 @@ def main(ray_dir: str) -> None:
149147
f.write("\n".join(filenames))
150148

151149
cache_path = f"{ray_dir}/doc.tgz"
152-
# Fetch cache of that commit from S3 to cache_path
153-
fetch_cache_from_s3(latest_master_commit, cache_path)
150+
# Fetch cache of that commit from build cache archive to cache_path
151+
print(f"Use build cache for commit {latest_master_commit}")
152+
fetch_cache(latest_master_commit, cache_path)
154153
# Extract cache to override ray/doc directory
155154
extract_cache(cache_path, f"{ray_dir}/doc")
156155
os.remove(cache_path)

0 commit comments

Comments
 (0)