Skip to content
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

feat: add all default assets to aspects-superset image to avoid load it via larger file #500

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Henrrypg marked this conversation as resolved.
Show resolved Hide resolved
# For each asset, create a file in the right folder
for asset in extra_assets:
if FILE_NAME_ATTRIBUTE not in asset:
Ian2012 marked this conversation as resolved.
Show resolved Hide resolved
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