diff --git a/tutorminio/patches/discovery-common-settings b/tutorminio/patches/discovery-common-settings new file mode 100644 index 0000000..24bb114 --- /dev/null +++ b/tutorminio/patches/discovery-common-settings @@ -0,0 +1,10 @@ +# MinIO object storage +DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" +AWS_ACCESS_KEY_ID = "{{ OPENEDX_AWS_ACCESS_KEY }}" +AWS_SECRET_ACCESS_KEY = "{{ OPENEDX_AWS_SECRET_ACCESS_KEY }}" +AWS_S3_SIGNATURE_VERSION = "s3v4" +AWS_S3_ENDPOINT_URL = "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ MINIO_HOST }}" +AWS_STORAGE_BUCKET_NAME = "discoveryuploads" +AWS_S3_CUSTOM_DOMAIN = "{{ MINIO_HOST }}/discoveryuploads" +AWS_S3_URL_PROTOCOL = "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}:" +AWS_QUERYSTRING_EXPIRE = 7 * 24 * 60 * 60 # 1 week: this is necessary to generate valid download urls diff --git a/tutorminio/plugin.py b/tutorminio/plugin.py index 710e145..3a7ab57 100644 --- a/tutorminio/plugin.py +++ b/tutorminio/plugin.py @@ -5,7 +5,7 @@ from glob import glob import importlib_resources -from tutor import hooks as tutor_hooks +from tutor import hooks as tutor_hooks, plugins from tutor.__about__ import __version_suffix__ from .__about__ import __version__ @@ -34,6 +34,7 @@ "DOCKER_IMAGE": "docker.io/minio/minio:RELEASE.2022-03-26T06-49-28Z.hotfix.26ec6a857", "MC_DOCKER_IMAGE": "docker.io/minio/mc:RELEASE.2022-03-31T04-55-30Z", "GATEWAY": None, + "DISCOVERY_BUCKET_NAME": "discoveryuploads", }, "unique": { "AWS_SECRET_ACCESS_KEY": "{{ 24|random_string }}", @@ -93,3 +94,15 @@ def add_minio_hosts( tutor_hooks.Filters.ENV_PATCHES.add_item( (os.path.basename(path), patch_file.read()) ) + + +def is_discovery_enabled() -> bool: + for plugin, plugin_info in plugins.iter_info(): + if plugin == "discovery": + return True + return False + + +tutor_hooks.Filters.ENV_TEMPLATE_VARIABLES.add_item( + ("is_discovery_enabled", is_discovery_enabled()) +) diff --git a/tutorminio/templates/minio/tasks/minio/init.sh b/tutorminio/templates/minio/tasks/minio/init.sh index 628b480..652d4ee 100644 --- a/tutorminio/templates/minio/tasks/minio/init.sh +++ b/tutorminio/templates/minio/tasks/minio/init.sh @@ -7,3 +7,14 @@ mc policy set public minio/{{ MINIO_BUCKET_NAME }} {% else %} echo "⚠️ It is your responsibility to grant public read access rights to the '{{ MINIO_BUCKET_NAME }}' bucket on Azure." {% endif %} + +# discovery bucket +{% if is_discovery_enabled %} +mc mb --ignore-existing minio/{{ MINIO_DISCOVERY_BUCKET_NAME }} +{% if MINIO_GATEWAY != "azure" %} +# Make discovery media upload bucket public +mc policy set public minio/{{ MINIO_DISCOVERY_BUCKET_NAME }} +{% else %} +echo "⚠️ It is your responsibility to grant public read access rights to the '{{ MINIO_DISCOVERY_BUCKET_NAME }}' bucket on Azure." +{% endif %} +{% endif %}