|
5 | 5 | import importlib
|
6 | 6 | import json
|
7 | 7 | import logging
|
| 8 | +import urllib.request |
| 9 | +import zipfile |
8 | 10 | from concurrent.futures import as_completed,ProcessPoolExecutor
|
9 | 11 |
|
10 | 12 | from utils.common import download_file_from_s3_by_s5cmd
|
|
24 | 26 |
|
25 | 27 | logger = get_logger(__name__)
|
26 | 28 |
|
| 29 | +# Global constants |
| 30 | +S5CMD_PATH = "./s5cmd" |
| 31 | + |
27 | 32 |
|
28 | 33 | def parse_args():
|
29 | 34 | parser = argparse.ArgumentParser()
|
@@ -241,19 +246,46 @@ def get_executable_model(args):
|
241 | 246 | return execute_model
|
242 | 247 |
|
243 | 248 | def download_s5cmd():
|
244 |
| - assert os.system('curl https://github.com/peak/s5cmd/releases/download/v2.0.0/s5cmd_2.0.0_Linux-64bit.tar.gz -L -o /tmp/s5cmd.tar.gz') == 0 |
245 |
| - assert os.system("mkdir -p /tmp/s5cmd && tar -xvf /tmp/s5cmd.tar.gz -C /tmp/s5cmd") == 0 |
246 |
| - assert os.system(f"cp /tmp/s5cmd/s5cmd .") == 0 |
| 249 | + """Download s5cmd binary using S3 URL (always use us-east-1 for local deployment)""" |
| 250 | + # Check if s5cmd already exists |
| 251 | + if os.path.exists(S5CMD_PATH): |
| 252 | + return S5CMD_PATH |
| 253 | + |
| 254 | + s5cmd_url = "https://aws-gcr-solutions-us-east-1.s3.us-east-1.amazonaws.com/easy-model-deployer/pipeline/s5cmd.zip" |
| 255 | + |
| 256 | + try: |
| 257 | + # Download and extract |
| 258 | + zip_path = S5CMD_PATH + ".zip" |
| 259 | + urllib.request.urlretrieve(s5cmd_url, zip_path) |
| 260 | + |
| 261 | + with zipfile.ZipFile(zip_path, 'r') as zip_ref: |
| 262 | + zip_ref.extractall(".") |
| 263 | + |
| 264 | + os.remove(zip_path) # Clean up zip file |
| 265 | + |
| 266 | + # Make s5cmd executable |
| 267 | + if os.path.exists(S5CMD_PATH): |
| 268 | + os.chmod(S5CMD_PATH, os.stat(S5CMD_PATH).st_mode | 0o755) |
| 269 | + return S5CMD_PATH |
| 270 | + else: |
| 271 | + raise FileNotFoundError("Required component(s5cmd) installation failed") |
| 272 | + |
| 273 | + except Exception as e: |
| 274 | + raise RuntimeError("Required component(s5cmd) download failed") |
247 | 275 |
|
248 | 276 | if __name__ == "__main__":
|
249 | 277 | t0 = time.time()
|
250 | 278 | start_time = time.time()
|
251 | 279 | args = parse_args()
|
252 |
| - if not (check_cn_region(args.region) or args.region == LOCAL_REGION): |
253 |
| - download_s5cmd() |
254 |
| - |
255 |
| - s5_cmd_path = "./s5cmd" |
256 |
| - os.chmod(s5_cmd_path, os.stat(s5_cmd_path).st_mode | 0o100) |
| 280 | + |
| 281 | + # Download s5cmd |
| 282 | + download_s5cmd() |
| 283 | + |
| 284 | + if not os.path.exists(S5CMD_PATH): |
| 285 | + logger.error("Required component(s5cmd) not found") |
| 286 | + sys.exit(1) |
| 287 | + |
| 288 | + os.chmod(S5CMD_PATH, os.stat(S5CMD_PATH).st_mode | 0o100) |
257 | 289 | extra_params = args.extra_params
|
258 | 290 | for k,v in extra_params.items():
|
259 | 291 | setattr(args,k,v)
|
|
0 commit comments