Skip to content

Commit

Permalink
Merge pull request #500 from eduNEXT/hpg/assets-bug-resolution
Browse files Browse the repository at this point in the history
feat: add all default assets to aspects-superset image to avoid load it via larger file
  • Loading branch information
bmtcril authored Nov 1, 2023
2 parents 5314d22 + 1d017c2 commit cb48cf8
Show file tree
Hide file tree
Showing 58 changed files with 39 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ To contribute assets to Aspects:
#. The script will also warn about missing `_roles` in dashboards. Superset does not export
these, so you will need to manually add this key with the roles that are necessary to
view the dashboard. See the existing dashboards for how this is done.
#. Re-build your ``aspects-superset`` image with `tutor images build aspects-superset --no-cache`
#. Run the command `tutor aspects check_superset_assets` to confirm there are no
duplicate assets, which can happen when you rename an asset, and will cause import
to fail. The command will automatically delete the older file if it finds a duplicate.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
{% for file in "openedx-assets/assets/"|walk_templates %}
- {% filter indent(width=2) %}{% include file %}{% endfilter %}
{% endfor %}


{{ patch("superset-extra-assets") }}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

TRANSLATIONS_FILE_PATH = "/app/localization/locale.yaml"
ASSETS_FILE_PATH = "/app/pythonpath/assets.yaml"
ASSETS_PATH = "/app/openedx-assets"

merged_data = {}
with open(TRANSLATIONS_FILE_PATH, "r") as file:
Expand All @@ -61,26 +62,46 @@ def main():
def create_assets():
"""Create assets from a yaml file."""
roles = {}

for root, dirs, files in os.walk(ASSETS_PATH):
for file in files:
if not file.endswith(".yaml"):
continue

path = os.path.join(root, file)
with open(path, "r") as file:
asset = yaml.safe_load(file)
if not asset:
continue

# Process the asset directly
if FILE_NAME_ATTRIBUTE not in asset:
raise Exception(f"Asset {asset} has no {FILE_NAME_ATTRIBUTE}")
file_name = asset.pop(FILE_NAME_ATTRIBUTE)

# Find the right folder to create the asset in
for asset_name, folder in ASSET_FOLDER_MAPPING.items():
if asset_name in asset:
write_asset_to_file(asset, asset_name, folder, file_name, roles)
break

with open(ASSETS_FILE_PATH, "r") as file:
extra_assets = yaml.safe_load(file)

if not extra_assets:
print("No extra assets to create")
return
if extra_assets:
# For each asset, create a file in the right folder
for asset in extra_assets:
if FILE_NAME_ATTRIBUTE not in asset:
raise Exception(f"Asset {asset} has no {FILE_NAME_ATTRIBUTE}")
file_name = asset.pop(FILE_NAME_ATTRIBUTE)

# For each asset, create a file in the right folder
for asset in extra_assets:
if FILE_NAME_ATTRIBUTE not in asset:
raise Exception(f"Asset {asset} has no {FILE_NAME_ATTRIBUTE}")
file_name = asset.pop(FILE_NAME_ATTRIBUTE)

# Find the right folder to create the asset in
for asset_name, folder in ASSET_FOLDER_MAPPING.items():
if not asset_name in asset:
continue
# Find the right folder to create the asset in
for asset_name, folder in ASSET_FOLDER_MAPPING.items():
if not asset_name in asset:
continue

write_asset_to_file(asset, asset_name, folder, file_name, roles)
break
write_asset_to_file(asset, asset_name, folder, file_name, roles)
break

import_assets()
update_dashboard_roles(roles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ RUN apt-get update -q \
&& ln -s /opt/firefox/firefox /usr/local/bin/firefox \
&& apt-get autoremove -yqq --purge wget && rm -rf /var/lib/apt/lists/* /var/[log,tmp]/* /tmp/* && apt-get clean

COPY ./openedx-assets /app/openedx-assets

USER superset

0 comments on commit cb48cf8

Please sign in to comment.