Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Fix caching of images when multiple images specified #150

Merged
merged 3 commits into from
Dec 3, 2019
Merged
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
8 changes: 5 additions & 3 deletions build/scripts/cache_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ images=$(yq -S -r '.icon' "${metas[@]}" | sort | uniq)
mkdir -p "$RESOURCES_DIR" "$TEMP_DIR"

echo "Caching images referenced in devfiles"
for image in "${images[@]}"; do
while read -r image; do
# Workaround for getting filenames through content-disposition: copy to temp
# dir and read filename before moving to /resources.
wget -P "${TEMP_DIR}" -nv --content-disposition "${image}"
Expand All @@ -40,13 +40,15 @@ for image in "${images[@]}"; do
image_dir="${RESOURCES_DIR%/}/${image_dir%/*}"
mkdir -p "$image_dir"

cached_image="${image_dir%/}/${filename}"
# Strip query and fragment components from image URL
cached_image="${image_dir%/}/${filename%%\?*}"
cached_image="${cached_image%%\#*}"
mv "$file" "$cached_image"
echo " Downloaded image $image to $cached_image"

cached_url="{{ DEVFILE_REGISTRY_URL }}/${cached_image#/}"
sed -i "s|${image}|${cached_url}|g" "${metas[@]}" "$INDEX_JSON"
echo " Updated devfiles to point at cached image"
done
done <<< "$images"

rm -rf "$TEMP_DIR"