This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add icon caching to offline devfile registries
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
- Loading branch information
Showing
9 changed files
with
75 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2012-2018 Red Hat, Inc. | ||
# This program and the accompanying materials are made | ||
# available under the terms of the Eclipse Public License 2.0 | ||
# which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Arguments | ||
# $1 - devfiles directory | ||
# $2 - resources directory, where project zips will be stored. | ||
# | ||
# Only supports downloading projecst from GitHub. | ||
|
||
set -e | ||
|
||
DEVFILES_DIR="${1%/}" | ||
INDEX_JSON="${DEVFILES_DIR#./}/index.json" | ||
RESOURCES_DIR="${2%/}/images/" | ||
RESOURCES_DIR="${RESOURCES_DIR#\./}" | ||
TEMP_DIR="${RESOURCES_DIR%/}/temp_images" | ||
|
||
readarray -d '' metas < <(find "${DEVFILES_DIR#./}" -name 'meta.yaml' -print0) | ||
|
||
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 | ||
# 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}" | ||
file=$(find "${TEMP_DIR}" -type f) | ||
filename=$(basename "${file}") | ||
|
||
# Store downloaded image in resources dir, on subpath derived from URL (strip | ||
# protocol and last portion) | ||
image_dir="${image#*//}" | ||
image_dir="${RESOURCES_DIR%/}/${image_dir%/*}" | ||
mkdir -p "$image_dir" | ||
|
||
cached_image="${image_dir%/}/${filename}" | ||
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 | ||
|
||
rm -rf "$TEMP_DIR" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters