Skip to content

Commit

Permalink
feat: add separate bucket for discovery
Browse files Browse the repository at this point in the history
Run init script for minio to create a bucket for discovery
after enabling discovery plugin.
  • Loading branch information
Muhammad Faraz Maqsood authored and Muhammad Faraz Maqsood committed Jul 2, 2024
1 parent bb8b3f4 commit ab5f139
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions tutorminio/patches/discovery-common-settings
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion tutorminio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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 }}",
Expand Down Expand Up @@ -93,3 +94,11 @@ 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()))
11 changes: 11 additions & 0 deletions tutorminio/templates/minio/tasks/minio/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

0 comments on commit ab5f139

Please sign in to comment.