Skip to content

Commit

Permalink
Better moving system
Browse files Browse the repository at this point in the history
  • Loading branch information
Auties00 committed Dec 10, 2024
1 parent 0cfa4af commit fdb1d69
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 99 deletions.
2 changes: 1 addition & 1 deletion archive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
Builds are stored on a Cloudflare R2 instance at `https://builds.rebootfn.org/versions.json`.
If you want to move them to another AWS-compatible object storage, run:
```
move.ps1
python move.py
```
and provide the required parameters.
98 changes: 0 additions & 98 deletions archive/move.ps1

This file was deleted.

66 changes: 66 additions & 0 deletions archive/move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import argparse
import os
import requests
import boto3

from concurrent.futures import ThreadPoolExecutor, as_completed
from urllib.parse import urlparse

def upload_url_to_s3(s3_client, bucket_name, url, object_key):
response = requests.get(url, stream=True, verify=False, headers={"Cookie": "_c_t_c=1"})
response.raise_for_status()
s3_client.upload_fileobj(response.raw, bucket_name, object_key)
return url, object_key

def derive_key_from_url(url, prefix=None):
parsed = urlparse(url)
filename = os.path.basename(parsed.path)
if prefix:
return f"{prefix}/{filename}"
else:
return filename

def main():
parser = argparse.ArgumentParser(description="Upload multiple URLs from versions.txt to an S3 bucket concurrently.")
parser.add_argument('--bucket', required=True, help="Name of the S3 bucket.")
parser.add_argument('--concurrency', required=True, type=int, help="Number of concurrent uploads.")
parser.add_argument('--versions-file', default='versions.txt', help="File containing one URL per line.")
parser.add_argument('--access-key', required=True, help="AWS Access Key ID.")
parser.add_argument('--secret-key', required=True, help="AWS Secret Access Key.")
parser.add_argument('--endpoint-url', required=True, help="Custom endpoint URL for S3 or S3-compatible storage.")
args = parser.parse_args()

bucket_name = args.bucket
concurrency = args.concurrency
versions_file = args.versions_file
access_key = args.access_key
secret_key = args.secret_key
endpoint_url = args.endpoint_url

with open(versions_file, 'r') as f:
urls = [line.strip() for line in f if line.strip()]

print(f"Uploading {len(urls)} files...")
s3_params = {}
if access_key and secret_key:
s3_params['aws_access_key_id'] = access_key
s3_params['aws_secret_access_key'] = secret_key
if endpoint_url:
s3_params['endpoint_url'] = endpoint_url

s3 = boto3.client('s3', **s3_params)

futures = []
with ThreadPoolExecutor(max_workers=concurrency) as executor:
for url in urls:
object_key = derive_key_from_url(url)
futures.append(executor.submit(upload_url_to_s3, s3, bucket_name, url, object_key))
for future in as_completed(futures):
try:
uploaded_url, uploaded_key = future.result()
print(f"Uploaded: {uploaded_url} -> s3://{bucket_name}/{uploaded_key}")
except Exception as e:
print(f"Error uploading: {e}")

if __name__ == "__main__":
main()

0 comments on commit fdb1d69

Please sign in to comment.