Skip to content

Commit

Permalink
more s3 script cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Divide-By-0 committed Sep 28, 2023
1 parent 368cec3 commit f395260
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/twitter-verifier-circuits/scripts/upload_to_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@

parser = argparse.ArgumentParser(description='Upload files to S3 bucket')
parser.add_argument('--bucket_name', type=str, default='zkemail-zkey-chunks', help='Name of the S3 bucket')
parser.add_argument('--dirs', type=str, default='./chunked_build/email, ./chunked_build/email/email_js', help="Comma seperated directories to upload files from")
# parser.add_argument('--build_dir', type=str, default='chunked_build', help='Name of the build directory directory with the circuitname/ folder')
# parser.add_argument('--circuit_name', type=str, default='email', help='Name of the circuit (i.e. the foldername in build_dir/)')
parser.add_argument('--prefix_to_tar', type=str, default='email.zkey', help='Prefix to match for files in order to compress to a .tar.gz and upload')
parser.add_argument('--build-dir', type=str, default='build', help='Name of the build directory directory with the circuitname/ folder')
parser.add_argument('--circuit-name', type=str, default='wallet', help='Name of the circuit (i.e. the foldername in build_dir/)')
parser.add_argument('--prefix', type=str, default='vkey.json,email.wasm', help='Comma-seperated prefixes to upload without compression')
args = parser.parse_args()
bucket_name = args.bucket_name
# build_dir = args.build_dir
# circuit_name = args.circuit_name
prefix_to_tar = args.prefix_to_tar
build_dir = args.build_dir
circuit_name = args.circuit_name
prefix_to_tar = args.circuit_name + ".zkey"
prefixes = args.prefix.split(',')
dirs = args.dirs.split(',')
dirs = [os.path.join(build_dir, circuit_name, ""), os.path.join(build_dir, circuit_name, circuit_name + '_js')]

# Get the latest commit hash
commit_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('utf-8').strip()
Expand All @@ -32,17 +30,17 @@
# source = '.'
# zkey_dir = source + '/{build_dir}/{circuit_name}/'
# wasm_dir = source + '/{build_dir}/{circuit_name}/{circuit_name}_js/'

def upload_to_s3(filename, dir=""):
with open(dir + filename, 'rb') as file:
print("Starting upload...")
s3.upload_fileobj(file, bucket_name, commit_hash + '/' + filename, ExtraArgs={
'ACL': 'public-read', 'ContentType': 'binary/octet-stream'})
print("Done uploading ", filename, "!")
print(f"Done uploading {filename} to: https://{bucket_name}.s3.amazonaws.com/{commit_hash}/{filename}")


# Loop through the files in the remote directory
for dir in dirs:
print("Searching for files in: ", dir)
for file in os.listdir(dir):
# Check if the file matches the pattern
if file.startswith(prefix_to_tar):
Expand Down

0 comments on commit f395260

Please sign in to comment.