-
Notifications
You must be signed in to change notification settings - Fork 505
[WIP] feat: add xblocks at runtime without rebuilding image #1257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
mlabeeb03
wants to merge
7
commits into
overhangio:release
from
edly-io:labeeb/install-xblocks-at-runtime
Closed
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7732998
feat: add xblocks at runtime without rebuilding image
f18888a
add xblocks uninstall and list commands
725db52
auto reload after installing xblock
d04f22c
add migration run command and change mounted volume name
08ea6ad
install packages from host machine instead of from containers
mlabeeb03 44f50d4
use minio as storage for persistent packages
mlabeeb03 dd3eb35
use django storages api
mlabeeb03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
changelog.d/20250806_160115_muhammad.labeeb_install_xblocks_at_runtime.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - [Feature] Add Xblocks at runtime without rebuilding image. (by @mlabeeb03) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import click | ||
mlabeeb03 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import os | ||
| import shlex | ||
| import shutil | ||
| import subprocess | ||
| from typing import cast | ||
|
|
||
| from tutor import config as tutor_config | ||
| from tutor.commands.context import Context | ||
| from tutor.commands.config import save as config_save_command | ||
|
|
||
|
|
||
| HERE = os.path.abspath(os.path.dirname(__file__)) | ||
| DEPS_ZIP_PATH = os.path.join(HERE, "deps.zip") | ||
| DEPS_PATH = os.path.join(HERE, "deps/") | ||
|
|
||
|
|
||
| @click.group( | ||
| name="packages", | ||
| short_help="Manage packages", | ||
| ) | ||
| def packages_command() -> None: | ||
| """Custom persistent package manager for Tutor.""" | ||
|
|
||
|
|
||
| @click.command(name="list") | ||
| @click.pass_obj | ||
| def list_command(context: Context) -> None: | ||
| """ | ||
| List installed persistent packages. | ||
|
|
||
| Entries will be fetched from the `PERSISTENT_PIP_PACKAGES` config setting. | ||
| """ | ||
| config = tutor_config.load(context.root) | ||
| packages = [ | ||
| package for package in cast(list[str], config["PERSISTENT_PIP_PACKAGES"]) | ||
| ] | ||
| print(packages) | ||
|
|
||
|
|
||
| @click.command(name="build") | ||
| @click.pass_obj | ||
| def build(context: Context) -> None: | ||
| """Rebuild dependencies from scratch.""" | ||
| config = tutor_config.load(context.root) | ||
| DEPS = cast(list[str], config["PERSISTENT_PIP_PACKAGES"]) | ||
|
|
||
| build_dir = f"{context.root}/data/persistent-python-packages" | ||
|
|
||
| lib_path = os.path.join(build_dir, "lib") | ||
| bin_path = os.path.join(build_dir, "bin") | ||
|
|
||
| if os.path.exists(lib_path): | ||
| shutil.rmtree(lib_path) | ||
| if os.path.exists(bin_path): | ||
| shutil.rmtree(bin_path) | ||
|
|
||
| _pip_install(DEPS, build_dir) | ||
|
|
||
|
|
||
| @click.command(name="append") | ||
| @click.pass_obj | ||
| @click.pass_context | ||
| @click.argument("package") | ||
| def append(click_context: click.Context, context: Context, package: str) -> None: | ||
| """Append a new package to the list.""" | ||
| click_context.invoke( | ||
| config_save_command, | ||
| interactive=False, | ||
| set_vars=[], | ||
| append_vars=[("PERSISTENT_PIP_PACKAGES", package)], | ||
| remove_vars=[], | ||
| unset_vars=[], | ||
| env_only=False, | ||
| clean_env=False, | ||
| ) | ||
|
|
||
| build_dir = f"{context.root}/data/persistent-python-packages" | ||
|
|
||
| if os.path.exists(DEPS_ZIP_PATH): | ||
| shutil.unpack_archive(DEPS_ZIP_PATH, extract_dir=build_dir) | ||
|
|
||
| _pip_install([package], build_dir) | ||
|
|
||
|
|
||
| @click.command(name="remove") | ||
| @click.pass_context | ||
| @click.argument("package") | ||
| def remove(context: click.Context, package: str) -> None: | ||
| """Remove a package and rebuild archive from scratch.""" | ||
| context.invoke( | ||
| config_save_command, | ||
| interactive=False, | ||
| set_vars=[], | ||
| append_vars=[], | ||
| remove_vars=[("PERSISTENT_PIP_PACKAGES", package)], | ||
| unset_vars=[], | ||
| env_only=False, | ||
| clean_env=False, | ||
| ) | ||
|
|
||
| context.invoke(build) | ||
|
|
||
|
|
||
| def _pip_install(deps: list[str], prefix_dir: str) -> None: | ||
| for dep in deps: | ||
| # We use python3.11 because that's whats used in the Dockerfile | ||
| check_call( | ||
| "python3.11", | ||
| "-m", | ||
| "pip", | ||
| "install", | ||
| "--no-deps", | ||
| f"--prefix={prefix_dir}", | ||
| dep, | ||
| ) | ||
| check_call(f'touch "{prefix_dir}/.uwsgi_trigger"', shell=True) | ||
|
|
||
|
|
||
| def check_call(*args: str, shell: bool = False) -> None: | ||
| if shell: | ||
| command = " ".join(args) | ||
| print(command) | ||
| subprocess.check_call(command, shell=True) | ||
| else: | ||
| print(shlex.join(args)) | ||
| subprocess.check_call(args) | ||
|
|
||
|
|
||
| packages_command.add_command(list_command) | ||
| packages_command.add_command(build) | ||
| packages_command.add_command(append) | ||
| packages_command.add_command(remove) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.