From 5da6a25ad8fec5d15cb03b4d6fe8f1fef7f52521 Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Tue, 13 Aug 2024 10:16:46 +0200 Subject: [PATCH 1/4] chore: Add samples related images into csv Signed-off-by: Anatolii Bazko --- .../build/scripts/sync-che-olm.sh | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/devspaces-operator-bundle/build/scripts/sync-che-olm.sh b/devspaces-operator-bundle/build/scripts/sync-che-olm.sh index 44cd509775..a11750ab7d 100755 --- a/devspaces-operator-bundle/build/scripts/sync-che-olm.sh +++ b/devspaces-operator-bundle/build/scripts/sync-che-olm.sh @@ -355,7 +355,7 @@ for CSVFILE in ${TARGETDIR}/manifests/devspaces.csv.yaml; do done echo "Converted (yq #2) ${CSVFILE}" - # Update editors definitions environment variables in csv + # Update editors definitions environment variables images in csv # by removing upstream values and inserting downstream ones # https://github.com/eclipse-che/che/issues/22932 yq -riY "del(.spec.install.spec.deployments[].spec.template.spec.containers[0].env[] | select(.name | test(\"^RELATED_IMAGE_editor_definition_\")))" "${CSVFILE}" @@ -371,6 +371,51 @@ for CSVFILE in ${TARGETDIR}/manifests/devspaces.csv.yaml; do done echo "Converted (yq #3) ${CSVFILE}" + # Update samples environment variables images in csv + # 1. Downloads samples index.json from devspaces-images repo + # 2. For each sample, downloads devfile.yaml from the sample repo + # 3. For each component in devfile.yaml, extracts image and updates csv + yq -riY "del(.spec.install.spec.deployments[].spec.template.spec.containers[0].env[] | select(.name | test(\"^RELATED_IMAGE_sample_\")))" "${CSVFILE}" + curl -sSL https://raw.githubusercontent.com/redhat-developer/devspaces-images/${MIDSTM_BRANCH}/devspaces-dashboard/samples/index.json --output /tmp/samples.json + if [[ $(cat /tmp/samples.json) == *"404"* ]] || [[ $(cat /tmp/samples.json) == *"Not Found"* ]]; then + echo "[ERROR] Could not load https://raw.githubusercontent.com/redhat-developer/devspaces-images/${MIDSTM_BRANCH}/devspaces-dashboard/samples/index.json" + exit 1 + fi + SAMPLE_URLS=( + $(yq -r '.[] | .url' /tmp/samples.json) + ) + for SAMPLE_URL in "${SAMPLE_URLS[@]}"; do + SAMPLE_ORG="$(echo "${SAMPLE_URL}" | cut -d '/' -f 4)" + SAMPLE_REPOSITORY="$(echo "${SAMPLE_URL}" | cut -d '/' -f 5)" + SAMPLE_REF="$(echo "${SAMPLE_URL}" | cut -d '/' -f 7)" + curl -sSL \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.raw+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/${SAMPLE_ORG}/${SAMPLE_REPOSITORY}/contents/devfile.yaml?ref=${SAMPLE_REF}" \ + -o "/tmp/devfile.yaml" + if [[ $(cat /tmp/devfile.yaml) == *"404"* ]] || [[ $(cat /tmp/devfile.yaml) == *"401"* ]] || [[ $(cat /tmp/devfile.yaml) == *"Not Found"* ]]; then + echo "[ERROR] Could not load devfile.yaml from ${SAMPLE_URL}" + exit 1 + fi + + SAMPLE_NAME=$(yq -r '.metadata.name' /tmp/devfile.yaml | sed 's|-|_|g') + CONTAINER_INDEX=0 + while [ "${CONTAINER_INDEX}" -lt "$(yq -r '.components | length' "/tmp/devfile.yaml")" ]; do + COMPONENT_NAME=$(yq -r '.components['${CONTAINER_INDEX}'].name' /tmp/devfile.yaml) + CONTAINER_IMAGE=$(yq -r '.components['${CONTAINER_INDEX}'].container.image' /tmp/devfile.yaml) + if [[ ! ${CONTAINER_IMAGE} == "null" ]]; then + ENV_NAME="RELATED_IMAGE_sample_${SAMPLE_NAME}_${COMPONENT_NAME}" + ENV_VALUE="${CONTAINER_IMAGE}" + ENV="{name: \"${ENV_NAME}\", value: \"${ENV_VALUE}\"}" + yq -riY "(.spec.install.spec.deployments[].spec.template.spec.containers[0].env ) += [${ENV}]" "${CSVFILE}" + fi + + CONTAINER_INDEX=$((CONTAINER_INDEX+1)) + done + done + echo "Converted (yq #4) ${CSVFILE}" + # insert replaces: field declare -A spec_insertions=( [".spec.replaces"]="devspacesoperator.v${CSV_VERSION_PREV}" @@ -384,7 +429,7 @@ for CSVFILE in ${TARGETDIR}/manifests/devspaces.csv.yaml; do updateVal="${spec_insertions[$updateName]}" replaceField "${CSVFILE}" "${updateName}" "${updateVal}" "${COPYRIGHT}" done - echo "Converted (yq #4) ${CSVFILE}" + echo "Converted (yq #5) ${CSVFILE}" # add more RELATED_IMAGE_ fields for the images referenced by the registries bash -e "${SCRIPTS_DIR}/insert-related-images-to-csv.sh" -v "${CSV_VERSION}" -t "${TARGETDIR}" --ds-branch "${MIDSTM_BRANCH}" From dcfca98a061bcaf139522fe948332669fb082dfd Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Tue, 13 Aug 2024 10:31:29 +0200 Subject: [PATCH 2/4] chore: Add samples related images into csv Signed-off-by: Anatolii Bazko --- .../build/scripts/sync-che-olm.sh | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/devspaces-operator-bundle/build/scripts/sync-che-olm.sh b/devspaces-operator-bundle/build/scripts/sync-che-olm.sh index a11750ab7d..051a3c2b9f 100755 --- a/devspaces-operator-bundle/build/scripts/sync-che-olm.sh +++ b/devspaces-operator-bundle/build/scripts/sync-che-olm.sh @@ -388,14 +388,9 @@ for CSVFILE in ${TARGETDIR}/manifests/devspaces.csv.yaml; do SAMPLE_ORG="$(echo "${SAMPLE_URL}" | cut -d '/' -f 4)" SAMPLE_REPOSITORY="$(echo "${SAMPLE_URL}" | cut -d '/' -f 5)" SAMPLE_REF="$(echo "${SAMPLE_URL}" | cut -d '/' -f 7)" - curl -sSL \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.raw+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "https://api.github.com/repos/${SAMPLE_ORG}/${SAMPLE_REPOSITORY}/contents/devfile.yaml?ref=${SAMPLE_REF}" \ - -o "/tmp/devfile.yaml" - if [[ $(cat /tmp/devfile.yaml) == *"404"* ]] || [[ $(cat /tmp/devfile.yaml) == *"401"* ]] || [[ $(cat /tmp/devfile.yaml) == *"Not Found"* ]]; then - echo "[ERROR] Could not load devfile.yaml from ${SAMPLE_URL}" + curl -sSL https://raw.githubusercontent.com/${SAMPLE_ORG}/${SAMPLE_REPOSITORY}/${SAMPLE_REF}/devfile.yaml --output /tmp/devfile.yaml + if [[ $(cat /tmp/devfile.yaml) == *"404"* ]] || [[ $(cat /tmp/devfile.yaml) == *"Not Found"* ]]; then + echo "[ERROR] Could not load https://raw.githubusercontent.com/${SAMPLE_ORG}/${SAMPLE_REPOSITORY}/${SAMPLE_REF}/devfile.yaml" exit 1 fi @@ -405,9 +400,7 @@ for CSVFILE in ${TARGETDIR}/manifests/devspaces.csv.yaml; do COMPONENT_NAME=$(yq -r '.components['${CONTAINER_INDEX}'].name' /tmp/devfile.yaml) CONTAINER_IMAGE=$(yq -r '.components['${CONTAINER_INDEX}'].container.image' /tmp/devfile.yaml) if [[ ! ${CONTAINER_IMAGE} == "null" ]]; then - ENV_NAME="RELATED_IMAGE_sample_${SAMPLE_NAME}_${COMPONENT_NAME}" - ENV_VALUE="${CONTAINER_IMAGE}" - ENV="{name: \"${ENV_NAME}\", value: \"${ENV_VALUE}\"}" + ENV="{name: \"RELATED_IMAGE_sample_${SAMPLE_NAME}_${COMPONENT_NAME}\", value: \"${CONTAINER_IMAGE}\"}" yq -riY "(.spec.install.spec.deployments[].spec.template.spec.containers[0].env ) += [${ENV}]" "${CSVFILE}" fi From 6249b5b89860ad84831f9fed78ef06462daf5f0b Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Tue, 13 Aug 2024 12:15:25 +0200 Subject: [PATCH 3/4] chore: Add samples related images into csv Signed-off-by: Anatolii Bazko --- .../build/scripts/sync-che-olm.sh | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/devspaces-operator-bundle/build/scripts/sync-che-olm.sh b/devspaces-operator-bundle/build/scripts/sync-che-olm.sh index 051a3c2b9f..9ba977f5a7 100755 --- a/devspaces-operator-bundle/build/scripts/sync-che-olm.sh +++ b/devspaces-operator-bundle/build/scripts/sync-che-olm.sh @@ -384,6 +384,7 @@ for CSVFILE in ${TARGETDIR}/manifests/devspaces.csv.yaml; do SAMPLE_URLS=( $(yq -r '.[] | .url' /tmp/samples.json) ) + RELATED_IMAGES_ENV="" for SAMPLE_URL in "${SAMPLE_URLS[@]}"; do SAMPLE_ORG="$(echo "${SAMPLE_URL}" | cut -d '/' -f 4)" SAMPLE_REPOSITORY="$(echo "${SAMPLE_URL}" | cut -d '/' -f 5)" @@ -394,19 +395,34 @@ for CSVFILE in ${TARGETDIR}/manifests/devspaces.csv.yaml; do exit 1 fi - SAMPLE_NAME=$(yq -r '.metadata.name' /tmp/devfile.yaml | sed 's|-|_|g') CONTAINER_INDEX=0 while [ "${CONTAINER_INDEX}" -lt "$(yq -r '.components | length' "/tmp/devfile.yaml")" ]; do - COMPONENT_NAME=$(yq -r '.components['${CONTAINER_INDEX}'].name' /tmp/devfile.yaml) + CONTAINER_IMAGE_ENV_NAME="" CONTAINER_IMAGE=$(yq -r '.components['${CONTAINER_INDEX}'].container.image' /tmp/devfile.yaml) - if [[ ! ${CONTAINER_IMAGE} == "null" ]]; then - ENV="{name: \"RELATED_IMAGE_sample_${SAMPLE_NAME}_${COMPONENT_NAME}\", value: \"${CONTAINER_IMAGE}\"}" - yq -riY "(.spec.install.spec.deployments[].spec.template.spec.containers[0].env ) += [${ENV}]" "${CSVFILE}" + if [[ ${CONTAINER_IMAGE} == *"@"* ]]; then + # We don't need to encode the image name if it contains a digest + SAMPLE_NAME=$(yq -r '.metadata.name' /tmp/devfile.yaml | sed 's|-|_|g') + COMPONENT_NAME=$(yq -r '.components['${CONTAINER_INDEX}'].name' /tmp/devfile.yaml) + CONTAINER_IMAGE_ENV_NAME="RELATED_IMAGE_sample_${SAMPLE_NAME}_${COMPONENT_NAME}" + elif [[ ${CONTAINER_IMAGE} == *":"* ]]; then + # Encode the image name if it contains a tag + # It is used in dashboard to replace the image in the devfile.yaml at startup + CONTAINER_IMAGE_ENV_NAME="RELATED_IMAGE_sample_$(echo "${CONTAINER_IMAGE}" | base64 -w 0 | sed 's|=|____|g')" + fi + + if [[ -n ${CONTAINER_IMAGE_ENV_NAME} ]]; then + ENV="{name: \"${CONTAINER_IMAGE_ENV_NAME}\", value: \"${CONTAINER_IMAGE}\"}" + if [[ -z ${RELATED_IMAGES_ENV} ]]; then + RELATED_IMAGES_ENV="${ENV}" + elif [[ ! ${RELATED_IMAGES_ENV} =~ ${CONTAINER_IMAGE_ENV_NAME} ]]; then + RELATED_IMAGES_ENV="${RELATED_IMAGES_ENV}, ${ENV}" + fiz fi CONTAINER_INDEX=$((CONTAINER_INDEX+1)) done done + yq -riY "(.spec.install.spec.deployments[].spec.template.spec.containers[0].env ) += [${RELATED_IMAGES_ENV}]" "${CSVFILE}" echo "Converted (yq #4) ${CSVFILE}" # insert replaces: field From 9bca1e3d67e32f51c852c8ea210187d82e93515e Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Tue, 13 Aug 2024 15:09:02 +0200 Subject: [PATCH 4/4] chore: Add samples related images into csv Signed-off-by: Anatolii Bazko --- devspaces-operator-bundle/build/scripts/sync-che-olm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devspaces-operator-bundle/build/scripts/sync-che-olm.sh b/devspaces-operator-bundle/build/scripts/sync-che-olm.sh index 9ba977f5a7..5c4b8bcfc6 100755 --- a/devspaces-operator-bundle/build/scripts/sync-che-olm.sh +++ b/devspaces-operator-bundle/build/scripts/sync-che-olm.sh @@ -407,7 +407,7 @@ for CSVFILE in ${TARGETDIR}/manifests/devspaces.csv.yaml; do elif [[ ${CONTAINER_IMAGE} == *":"* ]]; then # Encode the image name if it contains a tag # It is used in dashboard to replace the image in the devfile.yaml at startup - CONTAINER_IMAGE_ENV_NAME="RELATED_IMAGE_sample_$(echo "${CONTAINER_IMAGE}" | base64 -w 0 | sed 's|=|____|g')" + CONTAINER_IMAGE_ENV_NAME="RELATED_IMAGE_sample_encoded_$(echo "${CONTAINER_IMAGE}" | base64 -w 0 | sed 's|=|____|g')" fi if [[ -n ${CONTAINER_IMAGE_ENV_NAME} ]]; then