@@ -540,55 +540,39 @@ def do_callback(service_commands: t.Iterable[tuple[str, str]]) -> None:
540
540
runner .run_task_from_str (service , command )
541
541
542
542
543
- @click .command (help = "Build all persistent pip packages and upload to MinIO" )
543
+ @click .command (
544
+ help = "Build all live dependencies, zip them and upload to storage backend"
545
+ )
544
546
@click .pass_obj
545
- def build_packages (context : Context ) -> t .Iterable [tuple [str , str ]]:
547
+ def build_live_dependencies (context : Context ) -> t .Iterable [tuple [str , str ]]:
546
548
"""
547
- Build the persistent pip packages and upload to MinIO.
548
- You need to update the `PERSISTENT_PIP_PACKAGES` variable
549
- in the config file to add/remove packages.
549
+ Build the live dependencies and upload using Django's storage API.
550
+ You need to update the `LIVE_DEPENDENCIES` variable in the config file to add/remove packages.
550
551
"""
551
552
config = tutor_config .load (context .root )
552
553
all_packages = " " .join (
553
- package for package in t .cast (list [str ], config ["PERSISTENT_PIP_PACKAGES " ])
554
+ package for package in t .cast (list [str ], config ["LIVE_DEPENDENCIES " ])
554
555
)
555
556
556
557
script = f"""
557
558
pip install \
558
- --prefix=/openedx/persistent-python-packages /deps \
559
+ --prefix=/openedx/live-dependencies /deps \
559
560
{ all_packages } \
560
561
&& python3 -c '
561
- import os, shutil, tempfile, boto3, botocore, datetime, zipfile
562
-
563
- DEPS_DIR = "/openedx/persistent-python-packages/deps"
564
- MINIO_KEY = "deps.zip"
565
- DEPS_ZIP_PATH = DEPS_DIR[:-4] + MINIO_KEY
566
- MINIO_BUCKET = "tutor-deps"
567
-
568
- s3 = boto3.client(
569
- "s3",
570
- endpoint_url="http://" + os.environ.get("MINIO_HOST"),
571
- aws_access_key_id=os.environ.get("OPENEDX_AWS_ACCESS_KEY"),
572
- aws_secret_access_key=os.environ.get("OPENEDX_AWS_SECRET_ACCESS_KEY"),
573
- )
562
+ import os, shutil, tempfile
563
+ from django.core.files.storage import storages
564
+ from django.core.files.base import File
565
+
566
+ DEPS_DIR = "/openedx/live-dependencies/deps"
567
+ DEPS_KEY = "deps.zip"
568
+
569
+ with tempfile.TemporaryDirectory(prefix="tutor-livedeps-") as zip_dir:
570
+ base = os.path.join(zip_dir, DEPS_KEY)
571
+ archive_path = shutil.make_archive(base[:-4], format="zip", root_dir=DEPS_DIR)
574
572
575
- def _upload_to_minio(local_path):
576
- try:
577
- s3.head_bucket(Bucket=MINIO_BUCKET)
578
- except botocore.exceptions.ClientError:
579
- s3.create_bucket(Bucket=MINIO_BUCKET)
580
- s3.upload_file(local_path, MINIO_BUCKET, MINIO_KEY)
581
- print(f"Uploaded {{local_path}} → MinIO:{{MINIO_BUCKET}}/{{MINIO_KEY}}")
582
- os.remove(local_path)
583
-
584
- def _make_zip_archive(src_dir):
585
- with tempfile.TemporaryDirectory(prefix="tutor-depszip-") as zip_dir:
586
- path = os.path.join(zip_dir, "deps.zip")
587
- shutil.make_archive(path[:-4], format="zip", root_dir=src_dir)
588
- shutil.move(path, DEPS_ZIP_PATH)
589
-
590
- _make_zip_archive(DEPS_DIR)
591
- _upload_to_minio(DEPS_ZIP_PATH)
573
+ with open(archive_path, "rb") as f:
574
+ # TODO User a separate storage for live dependencies
575
+ storages["default"].save(DEPS_KEY, File(f))
592
576
'
593
577
"""
594
578
@@ -619,7 +603,7 @@ def run_migrations(package: str) -> t.Iterable[tuple[str, str]]:
619
603
settheme ,
620
604
sqlshell ,
621
605
update_mysql_authentication_plugin ,
622
- build_packages ,
606
+ build_live_dependencies ,
623
607
run_migrations ,
624
608
]
625
609
)
0 commit comments