Skip to content

Commit ca6be2a

Browse files
authored
Migrate update-s3-html job to test-infra (#4879)
1 parent 8acbaa9 commit ca6be2a

File tree

5 files changed

+631
-0
lines changed

5 files changed

+631
-0
lines changed

.github/workflows/update-s3-html.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Update S3 HTML indices for download.pytorch.org
2+
3+
on:
4+
schedule:
5+
# Update the indices every 30 minutes
6+
- cron: "*/30 * * * *"
7+
workflow_dispatch:
8+
9+
permissions:
10+
id-token: write
11+
contents: read
12+
13+
jobs:
14+
update:
15+
runs-on: ubuntu-22.04
16+
environment: pytorchbot-env
17+
strategy:
18+
matrix:
19+
prefix: ["whl", "whl/test", "whl/nightly", "whl/lts/1.8"]
20+
fail-fast: False
21+
container:
22+
image: continuumio/miniconda3:4.12.0
23+
steps:
24+
- name: configure aws credentials
25+
id: aws_creds
26+
uses: aws-actions/configure-aws-credentials@v3
27+
with:
28+
role-to-assume: arn:aws:iam::308535385114:role/gha_workflow_s3_update
29+
aws-region: us-east-1
30+
- name: Checkout repository test-infra
31+
uses: actions/checkout@v3
32+
with:
33+
repository: pytorch/test-infra
34+
ref: ${{ github.ref }}
35+
- name: Update s3 html index
36+
run: |
37+
set -ex
38+
39+
# Create Conda Environment
40+
conda create --quiet -y --prefix run_env python="3.8"
41+
conda activate ./run_env
42+
43+
# Install requirements
44+
pip install -r s3_management/requirements.txt
45+
python s3_management/manage.py --generate-pep503 ${{ matrix.prefix }}

s3_management/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# s3_management
2+
3+
This directory houses scripts to maintain the s3 HTML indices for https://download.pytorch.org/whl

s3_management/backup_conda.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python3
2+
# Downloads domain pytorch and library packages from channel
3+
# And backs them up to S3
4+
# Do not use unless you know what you are doing
5+
# Usage: python backup_conda.py --version 1.6.0
6+
7+
import boto3
8+
from typing import List, Optional
9+
import conda.api
10+
import urllib
11+
import os
12+
import hashlib
13+
import argparse
14+
15+
S3 = boto3.resource('s3')
16+
BUCKET = S3.Bucket('pytorch-backup')
17+
_known_subdirs = ["linux-64", "osx-64", "osx-arm64", "win-64"]
18+
19+
20+
def compute_md5(path:str) -> str:
21+
with open(path, "rb") as f:
22+
return hashlib.md5(f.read()).hexdigest()
23+
24+
25+
def download_conda_package(package:str, version:Optional[str] = None,
26+
depends:Optional[str] = None, channel:Optional[str] = None) -> List[str]:
27+
packages = conda.api.SubdirData.query_all(package,
28+
channels = [channel] if channel is not None else None,
29+
subdirs = _known_subdirs)
30+
rc = []
31+
32+
for pkg in packages:
33+
if version is not None and pkg.version != version:
34+
continue
35+
if depends is not None and depends not in pkg.depends:
36+
continue
37+
38+
print(f"Downloading {pkg.url}...")
39+
os.makedirs(pkg.subdir, exist_ok = True)
40+
fname = f"{pkg.subdir}/{pkg.fn}"
41+
if not os.path.exists(fname):
42+
with open(fname, "wb") as f, urllib.request.urlopen(pkg.url) as url:
43+
f.write(url.read())
44+
if compute_md5(fname) != pkg.md5:
45+
print(f"md5 of {fname} is {compute_md5(fname)} does not match {pkg.md5}")
46+
continue
47+
rc.append(fname)
48+
49+
return rc
50+
51+
def upload_to_s3(prefix: str, fnames: List[str]) -> None:
52+
for fname in fnames:
53+
BUCKET.upload_file(fname, f"{prefix}/{fname}")
54+
print(fname)
55+
56+
57+
58+
if __name__ == "__main__":
59+
parser = argparse.ArgumentParser()
60+
parser.add_argument(
61+
"--version",
62+
help="PyTorch Version to backup",
63+
type=str,
64+
required = True
65+
)
66+
options = parser.parse_args()
67+
rc = download_conda_package("pytorch", channel = "pytorch", version = options.version)
68+
upload_to_s3(f"v{options.version}/conda", rc)
69+
70+
for libname in ["torchvision", "torchaudio", "torchtext"]:
71+
print(f"processing {libname}")
72+
rc = download_conda_package(libname, channel = "pytorch", depends = f"pytorch {options.version}")
73+
upload_to_s3(f"v{options.version}/conda", rc)

0 commit comments

Comments
 (0)