@@ -540,55 +540,37 @@ def do_callback(service_commands: t.Iterable[tuple[str, str]]) -> None:
540540 runner .run_task_from_str (service , command )
541541
542542
543- @click .command (help = "Build all persistent pip packages and upload to MinIO " )
543+ @click .command (help = "Build all live dependencies, zip them and upload to storage backend " )
544544@click .pass_obj
545- def build_packages (context : Context ) -> t .Iterable [tuple [str , str ]]:
545+ def build_live_dependencies (context : Context ) -> t .Iterable [tuple [str , str ]]:
546546 """
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.
547+ Build the live dependencies and upload using Django's storage API.
548+ You need to update the `LIVE_DEPENDENCIES` variable in the config file to add/remove packages.
550549 """
551550 config = tutor_config .load (context .root )
552551 all_packages = " " .join (
553- package for package in t .cast (list [str ], config ["PERSISTENT_PIP_PACKAGES " ])
552+ package for package in t .cast (list [str ], config ["LIVE_DEPENDENCIES " ])
554553 )
555554
556555 script = f"""
557556 pip install \
558- --prefix=/openedx/persistent-python-packages /deps \
557+ --prefix=/openedx/live-dependencies /deps \
559558 { all_packages } \
560559 && 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- )
560+ import os, shutil, tempfile
561+ from django.core.files.storage import storages
562+ from django.core.files.base import File
563+
564+ DEPS_DIR = "/openedx/live-dependencies/deps"
565+ DEPS_KEY = "deps.zip"
566+
567+ with tempfile.TemporaryDirectory(prefix="tutor-livedeps-") as zip_dir:
568+ base = os.path.join(zip_dir, DEPS_KEY)
569+ archive_path = shutil.make_archive(base[:-4], format="zip", root_dir=DEPS_DIR)
574570
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)
571+ with open(archive_path, "rb") as f:
572+ # TODO User a separate storage for live dependencies
573+ storages["default"].save(DEPS_KEY, File(f))
592574'
593575 """
594576
@@ -619,7 +601,7 @@ def run_migrations(package: str) -> t.Iterable[tuple[str, str]]:
619601 settheme ,
620602 sqlshell ,
621603 update_mysql_authentication_plugin ,
622- build_packages ,
604+ build_live_dependencies ,
623605 run_migrations ,
624606 ]
625607)
0 commit comments